CSS text overflows padding when height is not set - css

I'm encountering a problem when trying to pad a div with overflow: hidden with two child divs where the content overflows the bottom of the padding if the parent doesn't have a height set, despite a max-height being set. On top of that, using overflow: hidden on the child div causes it to act like it's display: inline-block where the content doesn't flow around its sibling that's float: left. Below is my example case.
Descriptive picture of example case
So my two main questions are, is there a way to achieve the child div (.content) growing until it reaches the max-height of the parent without overshooting, primarily so that the child div will be hidden by the parent's padding? And is overflow: hidden on .content supposed to cause .content to behave oddly when the text wraps or is that a bug?
.wrapper {
max-height: 150px;
/* height: 150px; /* Required for .content to get correct height. Why isn't max-height sufficient? */
overflow: hidden;
padding: 25px;
border: 1px solid #000;
}
.left {
float: left;
border: 1px solid #000;
}
.content {
/* height: 100%; /* Doesn't do anything if the parent has no height set. */
max-height: 150px; /* Resolves not being able to inherit the parent's height. */
overflow: hidden; /* <- Required to hide overflow text but causes odd text wrapping behavior. */
}
<div class="wrapper">
<div class="left">
Left
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquam quam sit amet neque ullamcorper varius. Aliquam porta, nulla a accumsan laoreet, ipsum nibh rhoncus lectus, sit amet placerat nibh felis ut leo. Nam in turpis at felis rutrum euismod a a sem. Donec efficitur lorem non vehicula luctus. Nulla pulvinar ultrices blandit. Donec ipsum arcu, tempus nec vulputate quis, porta nec sapien. Curabitur pellentesque, felis ut suscipit sodales, risus arcu consequat odio, vel porta ligula leo et quam. Praesent quam nisi, eleifend non viverra non, molestie nec nulla. Curabitur vel scelerisque dui, facilisis tempus enim. Etiam ac scelerisque dui. Etiam pretium tortor ac dictum eleifend. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam ornare malesuada risus, sed iaculis tellus lacinia vitae. Vivamus ut rhoncus nisl. Pellentesque vel sapien diam. Duis id felis massa.
</div>
</div>
Edit:
I've realized I could move the max-height amount to the child div, but the text still wraps strangely due to the overflow: hidden rule. I want to believe that this is a bug, but I am not certain.

Try This:
.wrapper {
overflow: auto;
padding: 25px;
border: 1px solid #000;
}
.left {
float: left;
border: 1px solid #000;
}
.content {
display: block;
overflow: auto;
/* Required but causes inline-block behavior? */
}
::-webkit-scrollbar {
width: 0px;
background: transparent; /* make scrollbar transparent */
}
<div class="wrapper">
<div class="left">
Left
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla aliquam quam sit amet neque ullamcorper varius. Aliquam porta, nulla a accumsan laoreet, ipsum nibh rhoncus lectus, sit amet placerat nibh felis ut leo. Nam in turpis at felis rutrum euismod a a sem. Donec efficitur lorem non vehicula luctus. Nulla pulvinar ultrices blandit. Donec ipsum arcu, tempus nec vulputate quis, porta nec sapien. Curabitur pellentesque, felis ut suscipit sodales, risus arcu consequat odio, vel porta ligula leo et quam. Praesent quam nisi, eleifend non viverra non, molestie nec nulla. Curabitur vel scelerisque dui, facilisis tempus enim. Etiam ac scelerisque dui. Etiam pretium tortor ac dictum eleifend. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam ornare malesuada risus, sed iaculis tellus lacinia vitae. Vivamus ut rhoncus nisl. Pellentesque vel sapien diam. Duis id felis massa.
</div>
</div>

Related

CSS: When flex row wraps, how to keep scrollable column from being pushed down below its container's fold?

In a fixed-height container, I have a flexbox (.main) with flex-direction: row and flex-wrap: wrap. At a wide screen size, I'd like its children — an image (.image-column), and a long amount of text (.text-column) — to be columns, in which the image remains static and the text scrolls. So far, so good. When sized down past the columns' min widths, I'd like them to wrap and stack. This all works, but here's the problem: when they wrap and stack, the scrollable text is offset by the min-height of the .image-column above it, such that when you scroll down to the bottom of the text, the scrollbar disappears offscreen rather than remaining within its container. But if you adjust the height to account for this offset, the .text-column is squished in the unwrapped state.
The two conflicting elements seem to be:
.image-column's min-height: 200px — but without this, the image doesn't show up at all when wrapped
.text-column's height: 100% — but without this, the text doesn't scroll
I've tried .text-column with height: calc(100% - 200px) — this fixes the offset when stacked, but creates unnecessary whitespace when in columns, and I'd prefer to avoid such specificity anyway
I'd like to figure out a solution with CSS only and no media queries, since this container may be in a multi-column layout with other containers. I'm willing to use flex, grid, float, or any other arcane layout trick.
Has anyone else experienced this issue with flex row wrapping and scrolling?
(You can run the code snippet below to see the layout wrapped, and press Full Page to see the layout in its wide 2-column state.)
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 40px;
padding: 40px;
background: #f6f6f6;
font-family: sans-serif; font-size: 120%; line-height: 1.5; color: #111;
}
.container {
height: 600px;
min-width: 300px;
max-width: 900px;
width: 100%;
display: flex;
flex-direction: column;
background-color: white;
border-radius: 10px;
overflow: hidden; /* don't scroll */
border: 1px solid #ccc;
}
.header {
border-bottom: 1px solid #ccc;
padding: 20px;
}
.main {
flex: 1 1 auto; /* fills remainder of height */
display: flex;
flex-direction: row;
flex-wrap: wrap; /* wrap after elements reach min-width / flex-basis */
overflow: hidden; /* don't scroll */
}
.image-column {
min-height: 200px;
flex: 1 1 300px; /* column width, min for wrapping */
background-image: url('https://images.unsplash.com/photo-1641361784653-73767ccfdf60?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHx0b3BpYy1mZWVkfDM0fDZzTVZqVExTa2VRfHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=900&q=60');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.text-column {
height: 100%;
flex: 2 1 420px; /* column width, min for wrapping */
overflow: auto; /* scroll */
padding: 20px;
}
.footer {
border-top: 1px solid #ccc;
padding: 20px;
}
<div class="container">
<div class="header">Header</div>
<div class="main">
<div class="image-column"></div>
<div class="text-column">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius enim eu justo posuere, a laoreet urna sodales. Mauris ac porta lorem, id malesuada ipsum. In ac ipsum sapien. Nunc nisi tellus, auctor vitae placerat sit amet, posuere id velit. In semper ex placerat purus sollicitudin, at aliquet metus viverra. Nam malesuada vel tellus malesuada fermentum. Curabitur iaculis vel lacus nec scelerisque. Praesent feugiat ac augue bibendum facilisis. Curabitur dapibus malesuada magna sit amet vehicula. Fusce ipsum eros, consectetur in sodales ac, lacinia at purus. Quisque laoreet justo et semper luctus. Nam ligula orci, ultricies et enim non, elementum rutrum massa. Aenean cursus lacus in magna hendrerit, in fermentum ex porttitor. Integer elementum, enim sit amet vehicula mollis, diam tortor congue massa, eget accumsan nulla arcu a leo. Maecenas convallis placerat magna, vitae lacinia mi ullamcorper quis. Etiam congue aliquet dolor eget dignissim. Donec malesuada laoreet nibh, sit amet tristique lacus facilisis nec. Quisque sit amet enim ac lectus bibendum laoreet. Pellentesque eleifend urna eget ultricies commodo. Nulla ex sapien, accumsan sit amet est vitae, pretium sollicitudin metus. Nullam finibus, ipsum id tincidunt tristique, diam tortor pellentesque orci, non rutrum turpis arcu ultricies eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius enim eu justo posuere, a laoreet urna sodales. Mauris ac porta lorem, id malesuada ipsum. In ac ipsum sapien. Nunc nisi tellus, auctor vitae placerat sit amet, posuere id velit. In semper ex placerat purus sollicitudin, at aliquet metus viverra. Nam malesuada vel tellus malesuada fermentum. Curabitur iaculis vel lacus nec scelerisque. Praesent feugiat ac augue bibendum facilisis. Curabitur dapibus malesuada magna sit amet vehicula. Fusce ipsum eros, consectetur in sodales ac, lacinia at purus. Quisque laoreet justo et semper luctus. Nam ligula orci, ultricies et enim non, elementum rutrum massa. Aenean cursus lacus in magna hendrerit, in fermentum ex porttitor. Integer elementum, enim sit amet vehicula mollis, diam tortor congue massa, eget accumsan nulla arcu a leo. Maecenas convallis placerat magna, vitae lacinia mi ullamcorper quis. Etiam congue aliquet dolor eget dignissim. Donec malesuada laoreet nibh, sit amet tristique lacus facilisis nec. Quisque sit amet enim ac lectus bibendum laoreet. Pellentesque eleifend urna eget ultricies commodo. Nulla ex sapien, accumsan sit amet est vitae, pretium sollicitudin metus. Nullam finibus, ipsum id tincidunt tristique, diam tortor pellentesque orci, non rutrum turpis arcu ultricies eros.</p>
</div>
</div>
<div class="footer">Footer</div>
</div>
I've found a solution to my own question.
Grid has a similar way of wrapping columns, using repeat's auto-fit with a minmax for each column in which the min is a fixed width.
.main {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
overflow: hidden; /* don't scroll */
}
Using this approach, when the columns wrap, the first column's min-height no longer offsets the second column and its scrollbar out of the container, as it did with flex row wrap.
The only small drawback is that the grid's two columns must be of equal width in order for the wrapping to work. For my uses, this is acceptable.
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 40px;
padding: 40px;
background: #f6f6f6;
font-family: sans-serif; font-size: 120%; line-height: 1.5; color: #111;
}
.container {
height: 600px;
min-width: 300px;
max-width: 900px;
width: 100%;
display: flex;
flex-direction: column;
background-color: white;
border-radius: 10px;
overflow: hidden; /* don't scroll */
border: 1px solid #ccc;
}
.header {
border-bottom: 1px solid #ccc;
padding: 20px;
}
.main {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
overflow: hidden; /* don't scroll */
}
.image-column {
min-height: 200px;
background-image: url('https://images.unsplash.com/photo-1641361784653-73767ccfdf60?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHx0b3BpYy1mZWVkfDM0fDZzTVZqVExTa2VRfHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=900&q=60');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.text-column {
overflow: auto; /* scroll */
padding: 20px;
}
.footer {
border-top: 1px solid #ccc;
padding: 20px;
}
<div class="container">
<div class="header">Header</div>
<div class="main">
<div class="image-column"></div>
<div class="text-column">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius enim eu justo posuere, a laoreet urna sodales. Mauris ac porta lorem, id malesuada ipsum. In ac ipsum sapien. Nunc nisi tellus, auctor vitae placerat sit amet, posuere id velit. In semper ex placerat purus sollicitudin, at aliquet metus viverra. Nam malesuada vel tellus malesuada fermentum. Curabitur iaculis vel lacus nec scelerisque. Praesent feugiat ac augue bibendum facilisis. Curabitur dapibus malesuada magna sit amet vehicula. Fusce ipsum eros, consectetur in sodales ac, lacinia at purus. Quisque laoreet justo et semper luctus. Nam ligula orci, ultricies et enim non, elementum rutrum massa. Aenean cursus lacus in magna hendrerit, in fermentum ex porttitor. Integer elementum, enim sit amet vehicula mollis, diam tortor congue massa, eget accumsan nulla arcu a leo. Maecenas convallis placerat magna, vitae lacinia mi ullamcorper quis. Etiam congue aliquet dolor eget dignissim. Donec malesuada laoreet nibh, sit amet tristique lacus facilisis nec. Quisque sit amet enim ac lectus bibendum laoreet. Pellentesque eleifend urna eget ultricies commodo. Nulla ex sapien, accumsan sit amet est vitae, pretium sollicitudin metus. Nullam finibus, ipsum id tincidunt tristique, diam tortor pellentesque orci, non rutrum turpis arcu ultricies eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla varius enim eu justo posuere, a laoreet urna sodales. Mauris ac porta lorem, id malesuada ipsum. In ac ipsum sapien. Nunc nisi tellus, auctor vitae placerat sit amet, posuere id velit. In semper ex placerat purus sollicitudin, at aliquet metus viverra. Nam malesuada vel tellus malesuada fermentum. Curabitur iaculis vel lacus nec scelerisque. Praesent feugiat ac augue bibendum facilisis. Curabitur dapibus malesuada magna sit amet vehicula. Fusce ipsum eros, consectetur in sodales ac, lacinia at purus. Quisque laoreet justo et semper luctus. Nam ligula orci, ultricies et enim non, elementum rutrum massa. Aenean cursus lacus in magna hendrerit, in fermentum ex porttitor. Integer elementum, enim sit amet vehicula mollis, diam tortor congue massa, eget accumsan nulla arcu a leo. Maecenas convallis placerat magna, vitae lacinia mi ullamcorper quis. Etiam congue aliquet dolor eget dignissim. Donec malesuada laoreet nibh, sit amet tristique lacus facilisis nec. Quisque sit amet enim ac lectus bibendum laoreet. Pellentesque eleifend urna eget ultricies commodo. Nulla ex sapien, accumsan sit amet est vitae, pretium sollicitudin metus. Nullam finibus, ipsum id tincidunt tristique, diam tortor pellentesque orci, non rutrum turpis arcu ultricies eros.</p>
</div>
</div>
<div class="footer">Footer</div>
</div>
(You can run the code snippet below to see the layout wrapped, and press Full Page to see the layout in its wide 2-column state.)
try setting the height of .text-column to 260px
.text-column {
height: 260px;
flex: 2 1 420px; /* column width, min for wrapping */
overflow: auto; /* don't scroll */
}

Place two divs next to each other using float: left

I have these two divs:
<div style="width:400px; height: 400px; background-color: red; float: left">my first div. width 400px</div>
<div style="width:600px; height: 400px; background-color: green; ">my second div. width 600px</div>
As you can see, I have floated the first one.
The problem: I expected the second to be placed on the right of the first one, but no..
Since having two paragraphs this way,
<p style="float: left">my first paragraph</p>
<p>my second paragraph</p>
the second paragraph is on the right of the first one, why it is not working in the same way for the divs?
NOTE: I know I can use other methods to put the divs next to each other. For example adding float: left to the second div, but what I really want to know is why is not working just adding float: left to the first one as with paragraphs or <li>s happens.
P tag by default have this style
clear: both;
margin-bottom: 1em;
margin-top: 0;
you should be overridden
try it
p {
width: 600px;
height: 400px;
display: block;
background-color: green;
margin: auto;
clear: inherit;
}
This is actually the standard mode for integrating images into longer text and the text "floating around" the image: The image gets a float (left or right), the text does not, the result is an image inside one or several paragraphs of text - a very useful principle:
img {
float: left;
margin: 0 10px 5px 0;
}
<img src="http://placehold.it/360x240/0af"/>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</p>
<p>Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.</p>
<p>Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.</p>
<p>Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>

Explanation on CSS float overflow property

I am a newbie to CSS. I started exploring CSS float property. I have two <div> elements inside a container. The two divs have equal width and height.
<div class="container">
<div class="one">
</div>
<div class="two">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,
</p>
</div>
</div>
And CSS for the above is :
.one{
width: 200px;
height: 200px;
background-color: green;
border: 1px solid blue;
float: left;
}
.two{
width: 200px;
height: 200px;
background-color: red;
border: 1px solid black;
overflow:visible;
}
.container{
overflow:hidden;
}
From the above what I can understand is that since the div that is floated is removed from the normal flow and floated to left and the second div which contains the text inside <p> elements merges underneath the .one div. And moreover since both have the same width and height I cannot see the content.
But when I set the overflow property of the .two to scroll I see the second div being placed adjacent to first div. This is confusing. Why is such a behavior? Please explain me. Link to codepen attached below for more details.
Link to Codepen
The float CSS property specifies that an element should be taken from the normal flow. However the non-float element still takes all the available width including the floating element. But if you set overflow: auto; or hidden to it, it will then align next to the floating element. See the demo following, it should explain it clearly.
.a1, .b1 {
background: rgba(0,0,0,.5); /*pure black with alpha*/
width: 50px;
height: 50px;
float: left;
}
.a2 {
background: lime;
}
.b2 {
background: lime;
overflow: auto; /*let the browser decide whether to clip or not*/
}
<div class="a1">hello</div>
<div class="a2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</div>
<br/>
<div class="b1">hello</div>
<div class="b2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</div>
What is happening here is because:
.container{
overflow:hidden;
}
What is happening?
Your floating div wants to take up space before your other div. Because your non-floating div has display: block, it wants a whole line to render itself. The floating div is pushing down your non-floating div which is then hidden by the style above. If you change display to inline-block, it will take up only the space it needs using the width and height properties.
Here is an example: http://codepen.io/anon/pen/LVpxZy

How to make text NOT flow around image, and to make it fall under image responsively

I want to have an image floated left, with text to the right that doesn't flow around it, and that falls underneath it when the browser is minimised. Like this:
This is the css I've got at the moment:
.item-container{ margin: 0 20px 20px 25px; }
.directory {display: inline; overflow: auto;}
.directory-image {float: left; margin-right: 17px;clear: left;}
You could add a float:left to the .directory div and give it a width of a certain value.
.directory {
float:left;
width:300px;
}
Like so: http://jsfiddle.net/aMA65/
You could also add a width in percentage to .directory and .directory-image to make it more responsive. (Don't forget img { max-width:100%; height:auto; } )
The trick to this is display: table;
HTML
<div class="wrap">
<img src="http://placekitten.com/150/150">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi facilisis ante id enim vestibulum viverra. Suspendisse malesuada justo et elit porttitor condimentum. Sed interdum mi dui, ut consequat risus laoreet quis. Sed quis elit nec arcu consectetur gravida vel eu lacus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras non nisl vehicula, aliquet sem nec, rutrum libero. Maecenas in mi felis. Curabitur et semper justo. Sed vel faucibus massa. Maecenas semper elementum aliquet. Nam mattis elementum fringilla. Etiam suscipit mi ut mauris vehicula, id tempor libero molestie. Vestibulum molestie nulla non adipiscing pretium. Cras volutpat magna auctor, ornare massa at, consequat lectus. Sed ac pharetra metus. Praesent eleifend nisi vitae eros fermentum fermentum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed porta vehicula augue nec elementum. Phasellus convallis lobortis dolor sed facilisis. Cras nisi elit, porta ac aliquet a, imperdiet eget turpis. Nullam euismod eros urna, in tincidunt enim feugiat id. Sed pharetra odio erat, et rhoncus massa sodales in. Nullam consectetur tortor sit amet ligula mollis, quis gravida eros pellentesque. Morbi eget laoreet mi, non euismod erat. Suspendisse elit est, dapibus a semper sed, molestie venenatis diam. Sed faucibus justo in ipsum molestie, et scelerisque ligula sodales. Vivamus sodales sodales arcu, ut bibendum diam consectetur sit amet. Donec id augue nibh. Nam vel mauris sem.
</div>
</div>
CSS:
.wrap { display: table; width: 100%; }
.wrap img { float: left; }
.wrap .content { display: table-cell; vertical-align: top; }
Then, in a media query:
#media screen and (max-width:600px){
.wrap { display: block; }
.wrap img { float: none; display: block; margin: 0 auto; }
.wrap .content { display: block; }
}
No tables or similar nonsenses needed, just pure CSS with media queries
here's how you can do it, btw re-size your browser under 400px width to see the result
you can change the value as you like for example:
#media only screen and (max-width: 960px) { }
in this case layout change will happen when browser window width is smaller than 960px.
here's the demo:
http://jsfiddle.net/darkosss/SE4p5/
And if you want images to be responsive too, follow the instructions for the "img" tag form the comment above.

Make div to strech in height between another divs, if overflow then scroll

I have a css problem like this:
I have 3 divs, imagine they're all stacked in a column (like table with 3 rows) and the top one and the bottom one has height: 100px; and position: absolute; for example and they're like header and footer, they always stick to the top and the bottom of my form.
The height of the whole form can vary depending on other elements in the form, so I need my middle div to be just between the other 2 divs, and if it doesn't fit with it's content, to scroll.
(For example header and footer are 100px height, the form is just 500px height and the text in middle div is very very long) <- at the moment the middle div expands and streches the whole form.
I've tried many things to solve this with positioning, marging, padding of the elements, but still no success... Can anyone help me? Thanks!
You can do it this way: jsFiddle
CSS
.header, .footer {
background-color: green;
height: 100px;
width: 100%;
}
.form {
height: 300px;
position: relative;
}
.content {
position: absolute;
top: 100px;
bottom: 100px;
overflow-y: scroll;
}
.footer {
position: absolute;
bottom: 0px;
}
What's wrong with just a little bit of JS as simple as this?
var form_height=300, footer_height=100, header_height=100;
document.getElementById('content').style.height=form_height - header_height - footer_height +'px';
Just adding that your code works:
http://jsfiddle.net/n8sZ7/23/
HTML
<div class="form">
<div class="header"></div>
<div id="content" class="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc
</div>
<div class="footer"></div>
</div>
CSS
.header, .footer {
background-color: green;
height: 100px;
}
.form {
height: 300px;
}
.content {
overflow-y: scroll; <!-- I want this to fit between header and footer (in this example to get 100px of height) without using any javascript -->
}

Resources