I have a container with two items. One of those items is a select
element, so I need to set the size
attribute via HTML. I want the other item in the container to stretch its height to fit the container. I can't figure it out. I don't want to explicitly set the height of the container because I don't know the size of that select box.
.container { padding: 5px; border: 1px solid black; } .container .column { display: inline-block; width: 40%; background-color: #AAA; padding: 5px; margin: 5px; vertical-align: top; height: 100%; } select { width: 100%; }
<div class="container"> <div class="column">Stretch to fill?</div> <div class="column"> <select size="15"> <option>Option 1</option> <option>Option 2</option> </select> </div> <div>
Inline element properties:The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS. Inline elements flow left to right, meaning inline elements appear on the same line unless the line wraps or there's an explicit line break ( <br/> )
If you have a border or padding set for your divs, then you've created additional pixels that will prevent your divs from adding up to a 100% width. To fix this, make sure you've added box-sizing: border-box to the div's styles.
You can set a block-level element to display like an inline element by setting the display property to inline. You can also cause inline elements to behave like block-level elements using the display property.
You can't set the width or height. inline-block It's formatted just like the inline element, where it doesn't start on a new line. BUT, you can set width and height values. block The element will start on a new line and occupy the full width available.
If table-cell
is an option, here's a way to do it:
.container { display: table; width: 100%; padding: 5px; border: 1px solid black; } .container .column { display: table-cell; width: 40%; background-color: #AAA; padding: 5px; border: 5px solid white; vertical-align: top; height: 100%; } select { width: 100%; }
<div class="container"> <div class="column">Stretch to fill?</div> <div class="column"> <select size="15"> <option>Option 1</option> <option>Option 2</option> </select> </div> <div>
If I understand what you are saying, you are facing the 100% height columns problem. I'm sorry to tell you there is no actual solution but "hacks".
Here you can find several of those workarounds. I like to use the one true layout method.
By the way, this is thinking you don't want to use the experimental css3 columns properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With