The way div is centered vertically

Source: Internet
Author: User

  After an improvement today, finally found the solution to the vertical div.  
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "
<title>css layout tip: Unknown height div Vertical center problem </title>
<style type=" Text/css "
Html,body
{
height:100%;
padding:0;
margin:0;
}
Body
{
min-height:200px
Text-align:center
min-width:402px
}
. Firstdiv
{
Margin-top: -100px/* seconddiv height half */
Float:left;
width:100%;
height:50%;
}
. Seconddiv
{
Clear:both
border:silver 1px solid;
Background: #666;
Margin-left:auto;
Overflow: Auto
width:400px;
Margin-right:auto;
height:200px;
Text-align:left
}
</style>

<body>
<div class= "Firstdiv" >< /div>
<div class= "Seconddiv"
<p> Look, this is not centered. Oh. And noYes, I have a problem. </p>
<p>body{background-color: #FFF5F0}<br>
div{position:absolute; top:50%; left:50%; margin:-100px 0 0-200px;
width:400px height:200px; border:1px #CCCC00 solid; font-family:arial,
Helvetica, sans-serif; color: #666666} & Lt;/p>
</div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.