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 3 of 3
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,092
    Thanks
    15
    Thanked 1 Time in 1 Post

    set the width of a div to be the same as it's closest sibling

    Is it possible to set the width of a div to be the same as it's closest sibling when the width on that div is width: auto;?

    In my jsFiddle you will see that I have a red, green and blue div. I want the blue div to adjust to the size of the green div (which is dynamic). So if the green div works out to be 200px then I want the blue div to be 200px.

    Originally I thought I would be able to put the blue div inside the green one and set display: inline-block on the child, but this does not work.

    So, if the content of the blue div increases then it won't push the width of the green div out (or the container div). How can this be achieved?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,486
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Well, just don’t make it display as inline-block? A div is a block-level element by default, and as such, has an intrinsic width of 100%. Or am I not getting something here?
    Last edited by VIPStephan; 09-26-2012 at 07:38 PM.

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,092
    Thanks
    15
    Thanked 1 Time in 1 Post
    Quote Originally Posted by VIPStephan View Post
    Well, just donít make it display as inline-block? A div is a block-level element by default, and as such, has an intrinsic width of 100%. Or am I not getting something here?
    Changing it to
    Code:
    display: block
    doesn't appear to have any effect i'm afraid.


  •  

    Tags for this Thread

    Posting Permissions

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