February 11, 201214 yr Hi, I have tried a few solutions but can not seem to find one that works, to vertical align multiple content in a div? Can anyone help please? Here is my html <div class="wrap-intro"> <div class="left"> <h1>"Hello" Welcome to my site</h1> <p>Here is a short paragraph</p> </div> <div class="right"><h2>Call or contact us online</h2> <ul> <li>Telephone:...</li> </ul> <a href="#" class="button blue">enquire online</a> </div> </div> Here is my CSS #header .wrap-intro{ height:202px; } #header .wrap-intro h1 { padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 20px; margin-left: 0px; font-size: 3.2em; font-family: 'Asap', sans-serif; } #header .wrap-intro h2 { padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; font-size: 2em; font-family: 'Asap', sans-serif; font-weight: bold; } #header .wrap-intro p{ font-size: 1.6em; font-family: 'Asap', sans-serif; ; } #header .wrap-intro ul li { font-size: 1.8em; padding: 0px; color: #10B0E6; font-style: italic; font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; } #header .left { float: left; width: 660px; } #header .right { height: 202px; width: 240px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 60px; float: right; } #header .right p { line-height: 1em; }
February 12, 201214 yr First of all, your styles start with #header so you need to add that into the html markup:- <body> <div id="header"> <div class="wrap-intro"> <div class="left"> <h1>"Hello" Welcome to my site</h1> <p>Here is a short paragraph</p> </div> <div class="right"><h2>Call or contact us online</h2> <ul> <li>Telephone:...</li> </ul> <a href="#" class="button blue">enquire online</a> </div> </div> </div><!--end of #header--> </body> That will place the left and right divs side by side because of their floats. Note that your styles have a space between #header and .wrap-intro which means they are separate divs. If you had #header.wrap-intro then your markup would be <div id="header class="wrap-intro"> I added a width to #header to stop the right div falling below left at small with windows. 960px is 240 + 660 + 60px padding-left in .right #header .wrap-intro{ height:202px; width: 960px; Second, what do you mean by vertically align? Do you mean vertically align: middle inside another div? If so, the #header div needs to enclose all the others like item 5a here:- http://www.wickham43.net/centeringdivs.php "Centering vertically within a div" but I don't think you mean that. Edited February 12, 201214 yr by Wickham
February 12, 201214 yr Author Thanks for that really appreciate it What I am aiming to do is vertical align the content in the left and right div, which is inside the wrap-intro div. <div class="wrap-intro"> <div class="left"> <h1>Welcome to my website</h1> <p>Here is a short paragraph</p> </div> <div class="right"> <h2>Call or contact us online</h2> <ul> <li>123456789</li> </ul> <a href="#" class="large button blue">Enquire Online</a> </div> </div> Hope you understand what I mean, I have tried the link you posted and this does not seem to work for some reason, not sure if it will with multiple content? Thanks Edited February 12, 201214 yr by daydreamer
February 12, 201214 yr Author Thought I solved it, but not quite right #header { margin-right: auto; margin-left: auto; height: 280px; margin-top: 0px; margin-bottom: 0px; } #header .wrap { height: 78px; } #header .wrap-intro{ height:20.2em; position: relative; top: 50%; } #header .wrap-intro h1 { padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; font-size: 3.2em; font-family: 'Asap', sans-serif; color: #5E5E5E; } #header .wrap-intro h2 { padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; font-size: 2.4em; font-family: 'Asap', sans-serif; color: #5E5E5E; } #header .wrap-intro p{ font-size: 1.6em; font-family: 'Asap', sans-serif; ; } #header .wrap-intro ul li { font-size: 1.8em; padding: 0px; color: #5E5E5E; font-style: italic; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; } #header .left { float: left; width: 640px; padding-right: 40px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; height: 20.2em; margin-top: -10.1em; position: relative; } #header .right { width: 280px; float: right; height: 20.2em; margin-top: -10.1em; position: relative; } #header .right p { line-height: 1em; } Edited February 12, 201214 yr by daydreamer
February 12, 201214 yr You've now introduced a style .wrap but where is that in your markup? Have you tested in a small width window? You need a containing div with at least width: 960px; somewhere to stop the right div dropping below the left if the window width is too small.
Create an account or sign in to comment