I'm wondering what the best way to go about doing this is...
I have 3 div
s:
a div#container
with width=100%;
that holds 2 inner div
s
a div#inner_left
with width
changing dynamically, but no wider than 200px (will hold a product image)
an div#inner_right
where the width should fill the rest of the space in the container (will contain text to describe the product shown)
#container { width:100% } #inner_left { display:inline-block: max-width:200px; } #inner_right { display:inline-block; width:100%; }
The problem is that the div#inner_right
creates a line break and fills the entire width. How can I make them align next to each other, with the right div
accounting for the width taken by the left div
(which changes dynamically?). I've gotten this to work other ways, but I'm looking for a clean solution...
Any help for a CSS noob is much appreciated!
What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.
The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
Set display to inline-block to make the div width fit to its content. Use position: relative and left: 50% to position its left edge to 50% of its containing element. Use transform: translateX(-50%) which will "shift" the element to the left by half its own width.
I haven't really seen a good solution in the answers here. So I'll share mine.
Best way to do this is by using the table-cell
option in CSS. One important thing to add is a 'min-width' to the element that has a pixel width.
Example:
<div id="left"> Left </div> <div id="right"> right </div>
CSS:
#left { display: table-cell; min-width: 160px; } #right { display: table-cell; width: 100%; vertical-align: top; }
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