I want my page to always be centered in the browser without affecting the content( like align-text: center; does). I want to center my wrapper-div.. How do I do this?
Simplifed existing page:
<div id="wrapper">
<div id="header">
Music Heaven
</div>
<div id="topmeny">
</div>
<div id="menu">
</div>
<div id="content">
</div>
<div id="bottom">
SiteAdmin
</div>
</div>
Entire fiddle: http://jsfiddle.net/EndQb/
You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.
Simply add text-align center to parent div and set the child div display to inline-block. This will force our div to behave like inline element and therefore subjected text-align center.
To Horizontally centered the <div> element: We can use the property of margin set to auto i.e margin: auto;. The <div> element takes up its specified width and divides equally the remaining space by the left and right margins.
Like last time, you must know the width and height of the element you want to center. Set the position property of the parent element to relative . Then set the child's position property to absolute , top to 50% , and left to 50% . This just centers the top left corner of the child element vertically and horizontally.
#wrapper {
width: ...
margin: 0 auto;
}
no need to set text-align
Set your style something like for the wrapper div.
#wrapper {
width: 841px;
margin: 0 auto;
}
In this way the wrapper div will always be centered according to your screen width. I hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With