float center css code example
Example 1: css align center
<div class="parent">
<span>Hello World</span>
</div>
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 2: css align items vertical center
.parent {
display: flex;
justify-content: center;
align-items: center;
}
Example 3: html css center text on page
<style>
body { background: white }
section {
background: black;
color: white;
border-radius: 1em;
padding: 1em;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
</style>
<section>
<h1>Nicely centered</h1>
<p>This text block is vertically centered.
<p>Horizontally, too, if the window is wide enough.
</section>
Example 4: how to horizontal center a div in css
#inner {
width: 50%;
margin: 0 auto;
}
Example 5: make web page float to center of page
.center {
text-align-last: center;
border: 2px solid black;
}
Example 6: centering horizontally
div.center{display:block;margin:auto;width:50%;}
p.center{text-align:center;}