Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    78
    Thanks
    17
    Thanked 1 Time in 1 Post

    How can I achieve this in CSS? Pic attached.



    I have this laid out on a 12 column grid. Basically, I want to stretch the length of the left div (.grid_4) to the same height as the div to the right without giving it a height attribute since the height of the right div (.grid_8) will always grow or shrink with content. Also, I want to vertically center the h2 element inside that first div.

    HTML

    <div class="containerdiv">
    <div class="grid_4">
    <h2>"Lorem Ipsum Lorem Ipsum"</h2>
    </div>
    <div class="grid_8">
    Lorem Ipsum Lorem IpsumLorem Ipsum Lorem IpsumLorem Ipsum Lorem IpsumLorem Ipsum Lorem Ipsum
    </div>
    </div>


    CSS

    .containerdiv {
    border-bottom:1px solid #EFEFEF;
    margin-bottom:30px;
    overflow:hidden;
    }

    .grid_4 {
    display:inline;
    float:left;
    margin-left:10px;
    margin-right:10px;
    position:relative;
    width:300px;
    }

    .grid_8 {
    display:inline;
    float:left;
    margin-left:10px;
    margin-right:10px;
    position:relative;
    width:620px;
    }

    Please help if you can. Thanks.
    Last edited by cpkid2; 11-10-2009 at 09:33 PM.

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    look up 'faux columns'

    basically, if the two divs will alwways be the same width then you could assign a background to the container div which looks like the two divs are the same height.

    You could, instead, use a bit of JS. I would run with the faux columns plan first.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    78
    Thanks
    17
    Thanked 1 Time in 1 Post
    I understand using faux columns but how would I get the h2 element to always center vertically in the left div?

  • #4
    New Coder
    Join Date
    Sep 2009
    Posts
    78
    Thanks
    17
    Thanked 1 Time in 1 Post
    I think I can get it working by inserting 2 columned tables in the divs but would using tables in a situation like this be accepted or is that bad coding practice?

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by cpkid2 View Post
    I understand using faux columns but how would I get the h2 element to always center vertically in the left div?
    Have a look at some centering techniques that may work for you at http://nopeople.com/CSS/vertical%20center%20with%20CSS/ (view the source to see how they are coded)
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #6
    New Coder
    Join Date
    Sep 2009
    Posts
    78
    Thanks
    17
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Excavator View Post
    Have a look at some centering techniques that may work for you at http://nopeople.com/CSS/vertical%20center%20with%20CSS/ (view the source to see how they are coded)
    Thanks for the help but I need it to be cross browser compatible; plus, the divs will grow and shrink so I can't set a height attribute like in the examples.

  • #7
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    I don't have one but I imagine you could find a js script that would do that for you.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •