html - Centering Div while being able to expand div -
i found solution centering div vertically , horizontally. if fill in content section past length defined div run outside of it. hoping make expand depending on content inside div. how make can happen?
html:
<body> <div id="wrapper"> <div id="headerwrapper"> <div id="header" class="center">header</div> </div> <div id="titlewrapper"> <div id="title" class="center">title</div> </div> <div id="contentwrapper"> <div id="content" class="center">content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br>content<br></div> </div> <div id="footerwrapper"> <div id="locationwrapper"> <div id="location" class="center">location</div> </div> <div id="copyrightwrapper"> <div id="copyright" class="center">copyright</div> </div> </div> </div> </body> css:
html body { margin: 0; padding: 0; height: 100%; width: 100%; } .center { position: relative; top: 50%; transform: translatey(-50%); margin-right: auto; margin-left: auto; width: 100%; height: 100% max-width: 5em; } #wrapper { background-color: pink; height: 100%; width: 100%; } #headerwrapper { background-color: green; width: 100%; height: 8em; } #header { color: white; background-color: black; } #titlewrapper { background-color: red; width: 100%; height: 8em; } #title { color: white; background-color: black; } #contentwrapper { background-color: blue; width: 100%; height: 8em; } #content { color: white; background-color: black; } #locationwrapper { background-color: yellow; width: 100%; height: 8em; } #location { color: white; background-color: black; } #footerwrapper { background-color: brown; width: 100%; height: 100%; } #copyrightwrapper { background-color: green; width: 100%; height: 8em; } #copyright { color: white; background-color: black; }
if want "content" sections dynamically adjust height, take off fixed height.
change:
#contentwrapper { background-color: blue; width: 100%; height: 8em; } to:
#contentwrapper { background-color: blue; width: 100%; } working fiddle requirement: http://jsfiddle.net/k5yuu/6/
Comments
Post a Comment