Image and text columns, grow image up to text column height - html

Is there any way in pure CSS to ensure that another one of the divisions in flex container never exceeds height of another division?
For situations, when images are high, I don't want them to make vertically centered text next to them be pushed down so far that reader scrolling down would see top of the image and empty column next to it, scroll down more and more, for text only to appear there.
What are your suggestions how to solve this issue with other means?
This is my attempt so far. This is to build a responsive layout for various situations, without knowing height of text or window width.
https://jsfiddle.net/Deele/khj9n42g/
.row {
display: flex;
align-items: stretch;
margin-top: 1rem;
}
.col {
flex: 1 0 0%;
flex-basis: 50%;
display: flex;
justify-content: center;
flex-direction: column;
padding: 1rem;
}
.container {
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
.col_image {
text-align: center;
overflow: hidden;
}
figure {
height: 100%;
margin: 0;
}
figure img {
height: 100%;
width: auto;
}
/* for debug only */
.col_text {
background-color: rgba(255, 0, 0, 0.1)
}
.col_image {
background-color: rgba(0, 255, 0, 0.1)
}
<div class="container">
<div class="row">
<div class="col col_text">
<h3>This text is higher than image, image should scale up</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat sapien a imperdiet congue. Vestibulum non nulla aliquam, varius massa euismod, faucibus lacus. Quisque scelerisque facilisis rutrum. Nulla eu eros efficitur, aliquam libero nec, suscipit dolor. Morbi eleifend luctus orci, id condimentum felis luctus in. Sed accumsan mi in leo varius venenatis. Morbi et venenatis ex.</p>
</div>
<div class="col col_image">
<figure><img src="https://via.placeholder.com/200x100" /></figure>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col col_text">
<h3>This text is longer than image, image should scale up</h3>
<h4>Image is wider than column, it should be cut off to fill height</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat sapien a imperdiet congue. Vestibulum non nulla aliquam, varius massa euismod, faucibus lacus. Quisque scelerisque facilisis rutrum. Nulla eu eros efficitur, aliquam libero nec, suscipit dolor. Morbi eleifend luctus orci, id condimentum felis luctus in. Sed accumsan mi in leo varius venenatis. Morbi et venenatis ex.</p>
</div>
<div class="col col_image">
<figure><img src="https://via.placeholder.com/500x100" /></figure>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col col_text">
<h3>This text is shorter than image, image should scale down</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat sapien a imperdiet congue. Vestibulum non nulla aliquam, varius massa euismod, faucibus lacus. Quisque scelerisque facilisis rutrum. Nulla eu eros efficitur, aliquam libero nec, suscipit dolor. Morbi eleifend luctus orci, id condimentum felis luctus in. Sed accumsan mi in leo varius venenatis. Morbi et venenatis ex.</p>
</div>
<div class="col col_image">
<figure><img src="https://via.placeholder.com/720x490" /></figure>
</div>
</div>
</div>

This looks more like an overall grid than a series of flexboxes.
We don't want the dimensions of the images to influence the height of each row so this snippet makes just one container which has the grid setting for columns, but leaves the height of the rows to be decided by content.
It puts the images in as backgrounds so their dimensions have no influence on the row height which is now determined solely by the text in the first column.
.container {
width: 100vw;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.container>* {
background: cyan;
}
.col_image {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
width: 100%;
height: 100%;
}
<div class="container">
<div class="col col_text">
<h3>This text is higher than image, image should scale up</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat sapien a imperdiet congue. Vestibulum non nulla aliquam, varius massa euismod, faucibus lacus. Quisque scelerisque facilisis rutrum. Nulla eu eros efficitur, aliquam libero nec,
suscipit dolor. Morbi eleifend luctus orci, id condimentum felis luctus in. Sed accumsan mi in leo varius venenatis. Morbi et venenatis ex.</p>
</div>
<div class="col col_image" style="background-image: url(https://via.placeholder.com/200x100);" />
</div>
<div class="col col_text">
<h3>This text is longer than image, image should scale up</h3>
<h4>Image is wider than column, it should be cut off to fill height</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat sapien a imperdiet congue. Vestibulum non nulla aliquam, varius massa euismod, faucibus lacus. Quisque scelerisque facilisis rutrum. Nulla eu eros efficitur, aliquam libero nec,
suscipit dolor. Morbi eleifend luctus orci, id condimentum felis luctus in. Sed accumsan mi in leo varius venenatis. Morbi et venenatis ex.</p>
</div>
<div class="col col_image" style="background-image: url(https://via.placeholder.com/500x100);">
</div>
<div class="col col_text">
<h3>This text is shorter than image, image should scale down</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat sapien a imperdiet congue. Vestibulum non nulla aliquam, varius massa euismod, faucibus lacus. Quisque scelerisque facilisis rutrum. Nulla eu eros efficitur, aliquam libero nec,
suscipit dolor. Morbi eleifend luctus orci, id condimentum felis luctus in. Sed accumsan mi in leo varius venenatis. Morbi et venenatis ex.</p>
</div>
<div class="col col_image" style="background-image: url(https://via.placeholder.com/720x490);">
</div>
</div>
Note: obviously you will want to add any dimensions required for the overall container, padding etc. Also the snippet centers the images on the cells, by using position center and size cover. Alter this if you really do want the images to sit to the top/left and be cut off on the bottom/right.

Related

Bootstrap 4.5, Separate Scrollbars, and Make Div Stick to Bottom

I'm trying to organize some elements across 3 columns using Bootstrap 4.5.
The center column will have a long body.
The right column with have content (2 divs) that should be either stuck to the top / bottom. I'm having exceeding difficulty getting the bottom element to stick. The element auto-expands, and I want it to auto-expand from the bottom.
I'm using Tocify as my ToC in the top of this right column.
The left column has several divs. The top div is a banner, which I would like stuck there. The rest of the divs are less important. Depending on the size of the viewport, this column may overflow, in which case I'd like an independent scrollbar for this left column. There should be 2 separate, independent scroll bars (webpage scroll and left-panel scroll).
Here's a bootstrap loaded fiddle with an example (with a long body to demonstrate the issue): https://jsfiddle.net/x1nhrwtf/5/
<body>
<div class="container-fluid">
<main class="container py-3">
<div class="row">
<aside class="col-md-2">
<div class="row banner sticky-top bg-white p-3">
This will be some banner. Should always stick to the top.
</div>
<div class="scrollable-area hide-this-on-small-devices">
<div class="row bg-white p-3">
This column is <em>not</em> supposed to scroll along with the middle section, <em>unless</em> the elements are overflown (in which case, I want a separate scrollbar).
<hr />
</div>
<div class="row bg-white p-3">
This will have a search bar. Hide this on small devices.
</div>
<div class="row bg-white p-3">
This will have announcements. Hide this on small devices.
</div>
<div class="row bg-white p-3">
This will have BuiltWith. Hide this on small devices.
</div>
</div>
</aside>
<section class="content col-md-6">
Lorem ipsum dolor sit amet...
</section>
<aside class="col-md-4">
<div class="toc sticky-top bg-white p-3">
<h3>ToC Section, sticky</h3>
<hr />
This is positioned correct, pretty much.
Should stay at the top, even on small devices.
This element auto-expands to 60% height.
This is a Tocify style ToC:
<div id="toc" class="pl-1"></div>
</div>
<div class="comments sticky-bottom bg-white p-3">
<h3>Comment section</h3>
<hr />
This should stick to the bottom of the column (and page).
This element auto-expands to 40% height.
</div>
</aside>
</div>
</main>
<footer class="footer">Here is a footer. It should be stuck across the bottom. Why is it not there?</footer>
</div>
</body>
CSS Attempt:
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.toc {
max-height: 60%;
}
.comments {
max-height: 40%;
}
.scrollable-area {
overflow-y: auto;
}
This is the solution i worked out. There is the container for the three columns, with overflow: hidden and height: 100vh to avoid page scroll. And the three columns with overflow scroll to allow parallel scrolling.
The rest of your requirements are met, i think. The top components of left and right are marked gray and tay on top. The comment stays on bottom of page and column. And the footer is visible.
html,
body {
margin: 0;
padding: 0;
}
.container {
display: flex;
flex-direction: row;
justify-content: space-evenly;
width: 100vw;
height: 100vh;
border: solid 1px red;
overflow: hidden;
}
.col {
display: flex;
flex-direction: column;
justify-content: flex-start;
height: auto;
overflow: auto;
padding: 3px;
}
.col-md-2 {
width: 16.6666666667%;
}
.col-md-4 {
width: 33.3333333334%;
}
.col-md-6 {
width: 50%;
}
.center {
background-color: green;
text-align: justify;
}
.sticky-top {
position: fixed;
width: inherit;
top: 0;
background-color: gray;
}
.sticky-bottom {
position: sticky;
bottom: 0;
}
.scrollable-area {
position: relative;
z-index: -1;
}
.toc {
height: 60%;
max-height: 60%;
}
.comments {
position: fixed;
bottom: 0;
z-index: -1;
height: 40%;
max-height: 40%;
}
footer {
position: fixed;
bottom: 0;
width: 100%;
z-index: 100;
background-color: black;
color: white;
}
<div class="container">
<div class="col left col-md-2">
<div class="banner sticky-top">
This will be some banner. Should always stick to the top.
</div>
<div class="scrollable-area hide-this-on-small-devices">
<div class="row bg-white p-3">
This column is <em>not</em> supposed to scroll along with the middle section, <em>unless</em> the elements are overflown (in which case, I want a separate scrollbar).
<hr />
</div>
<div class="row bg-white p-3">
This will have a search bar. Hide this on small devices.
<hr />
</div>
<div class="row bg-white p-3">
This will have announcements. Hide this on small devices.
<hr />
</div>
<div class="row bg-white p-3">
This will have BuiltWith. Hide this on small devices.
<hr />
</div>
</div>
</div>
<div class="col center col-md-6">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Volutpat sed cras ornare arcu dui vivamus arcu. Iaculis eu non diam phasellus vestibulum lorem sed risus ultricies. Suscipit tellus
mauris a diam maecenas. Egestas maecenas pharetra convallis posuere morbi leo urna molestie. Augue neque gravida in fermentum et sollicitudin ac. Amet purus gravida quis blandit turpis cursus in hac. Aenean pharetra magna ac placerat vestibulum. Quis
ipsum suspendisse ultrices gravida dictum fusce ut placerat orci. Ut placerat orci nulla pellentesque dignissim enim sit amet venenatis. Lacus vestibulum sed arcu non odio euismod.<br> Amet venenatis urna cursus eget nunc scelerisque viverra.
Sodales ut eu sem integer vitae justo eget. Tempor orci eu lobortis elementum. Dictum at tempor commodo ullamcorper a lacus. Vel facilisis volutpat est velit egestas dui id ornare. Urna duis convallis convallis tellus. Blandit massa enim nec dui nunc
mattis enim ut. Quisque non tellus orci ac. Tempus egestas sed sed risus pretium quam vulputate dignissim suspendisse. Fermentum leo vel orci porta. Duis tristique sollicitudin nibh sit amet commodo nulla facilisi. Elementum facilisis leo vel fringilla
est ullamcorper eget. Condimentum lacinia quis vel eros donec ac. Felis eget velit aliquet sagittis id consectetur purus. Fringilla ut morbi tincidunt augue interdum velit euismod. Faucibus a pellentesque sit amet porttitor. Sapien eget mi proin sed
libero enim sed. Nulla porttitor massa id neque aliquam vestibulum morbi blandit cursus.<br> Mattis pellentesque id nibh tortor id aliquet lectus proin nibh. Elit duis tristique sollicitudin nibh sit. Risus commodo viverra maecenas accumsan lacus
vel. Elementum sagittis vitae et leo duis ut diam. Mauris vitae ultricies leo integer malesuada nunc vel. Adipiscing tristique risus nec feugiat in fermentum posuere. Orci sagittis eu volutpat odio. Aliquet bibendum enim facilisis gravida neque convallis
a. Eget lorem dolor sed viverra ipsum nunc. Orci eu lobortis elementum nibh tellus molestie nunc non. Nulla aliquet porttitor lacus luctus accumsan tortor posuere ac. Gravida arcu ac tortor dignissim convallis aenean et. Tincidunt tortor aliquam nulla
facilisi cras fermentum odio. Vel pretium lectus quam id leo in vitae turpis. Ullamcorper velit sed ullamcorper morbi tincidunt ornare. Sit amet commodo nulla facilisi nullam. Senectus et netus et malesuada. Id porta nibh venenatis cras sed felis
eget.<br> Ultrices sagittis orci a scelerisque. Faucibus et molestie ac feugiat sed lectus vestibulum mattis ullamcorper. Id velit ut tortor pretium viverra suspendisse potenti nullam. Purus gravida quis blandit turpis cursus. Non curabitur gravida
arcu ac tortor dignissim. Porta nibh venenatis cras sed. Gravida dictum fusce ut placerat orci nulla. Justo laoreet sit amet cursus sit amet dictum. Non diam phasellus vestibulum lorem sed risus. Non enim praesent elementum facilisis leo vel fringilla
est ullamcorper.<br> Mattis aliquam faucibus purus in massa tempor nec feugiat nisl. Porta non pulvinar neque laoreet suspendisse interdum. Leo urna molestie at elementum. Aliquet porttitor lacus luctus accumsan. Arcu non sodales neque sodales ut.
Vitae turpis massa sed elementum tempus egestas. Faucibus in ornare quam viverra orci sagittis. Sociis natoque penatibus et magnis dis parturient. Lacus suspendisse faucibus interdum posuere. Odio facilisis mauris sit amet massa vitae tortor condimentum
lacinia.
</div>
<div class="col right col-md-4">
<div class="toc sticky-top bg-white p-3">
<h3>ToC Section, sticky</h3>
<hr /> This is positioned correct, pretty much. Should stay at the top, even on small devices. This element auto-expands to 60% height.
</div>
<div class="comments sticky-bottom bg-white p-3">
<h3>Comment section</h3>
<hr /> This should stick to the bottom of the column (and page). This element auto-expands to 40% height.
</div>
</div>
</div>
<footer class="footer">Here is a footer. It should be stuck across the bottom. Why is it not there?</footer>
The footer still right there (at the bottom). I think you didn't see it because jsfiddle's console covered it.

Maintain same height in elements inside columns located side by side with CSS

I have a template like this:
I want to maintain the same height between each item of both columns, depending on the one that has the biggest height, but only when they are side by side. In smaller screens, when they have width: 100%, each div has its own height depending of its own content height.
It should look like this:
I think that what I want is something like display: table, but I need both columns to be responsive.
All the questions I´have found are about maintaining the same height in both columns, but I´m already using flexbox to achieve this.
Is it possible to achieve what I vant with css only?
EDIT: Added code snippet. I forgot to mention that it needs to be supported by Chrome 36 (Android L WebView).
This question´s first answer shows what I wanted to achieve, but display:subgrid is not supported by any version Chrome at present:
Align child elements of different blocks
.title {
background: #b6fac0;
}
.content {
background: #b6b6fa;
}
.footer {
background: #f7f5b5;
}
.col-50 {
border: 1px solid red;
}
<link href="http://code.ionicframework.com/1.3.3/css/ionic.min.css" rel="stylesheet" />
<ion-content>
<div class="row responsive-sm">
<div class="col-50">
<div class="padding title">
Veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery loooooooooooong title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra
</div>
<div class="padding footer">
Footer
</div>
</div>
<div class="col-50">
<div class="padding title">
Title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra. Phasellus tortor tortor, luctus
in dapibus sed, ultrices eget lorem. Morbi vehicula fermentum arcu, nec egestas augue. Fusce orci ex, sodales ut tellus sit amet, pretium pulvinar odio. Suspendisse potenti. Phasellus convallis metus sed erat rhoncus, eu tristique lacus fermentum.
</div>
<div class="padding footer">
Footer
</div>
</div>
</div>
</ion-content>
you may take a look at #supports to filter possible display:option or subgrid .
example with display:contents
.title {
background: #b6fac0;
}
.content {
background: #b6b6fa;
}
.footer {
background: #f7f5b5;
}
.col-50 {
border: 1px solid red;
}
#supports (display: contents) {
.row.responsive-sm {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-column-gap: 1em;
}
.col-50 {
display: contents
}
.title {
grid-row: 1
}
.content {
grid-row: 2;
}
#media screen and (max-width:500px) {
/* set the break point to the right value */
.row.responsive-sm,
.col-50 {
display: block;
}
}
}
<link href="http://code.ionicframework.com/1.3.3/css/ionic.min.css" rel="stylesheet" />
<ion-content>
<div class="row responsive-sm">
<div class="col-50">
<div class="padding title">
Veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery loooooooooooong title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra
</div>
<div class="padding footer">
Footer a
</div>
</div>
<div class="col-50">
<div class="padding title">
Title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra. Phasellus tortor tortor, luctus
in dapibus sed, ultrices eget lorem. Morbi vehicula fermentum arcu, nec egestas augue. Fusce orci ex, sodales ut tellus sit amet, pretium pulvinar odio. Suspendisse potenti. Phasellus convallis metus sed erat rhoncus, eu tristique lacus fermentum.
</div>
<div class="padding footer">
Footer
</div>
</div>
</div>
</ion-content>
usefull for a fast check on supports on properties: https://caniuse.com/

The height of inner divs in a flexbox child

We've been looking all over the web, but can't find a solution to a seemingly unsolvable problem basically we've got two divs who need to be equal in height. In them we've got multiple other divs who need to scale in height with them.
We tried 100% height, flexbox, inherit, overflow hidden and other things we could think of. To no avail.
This is a simplistic view of what we've got:
.col-sm-12 {
width: 100%;
display: flex
}
.col-sm-6 {
width: 50%;
float: left;
flex: 1;
}
.c1 {
}
.c2 {
padding: 20px;
}
.c3 {
border: 1px solid grey;
padding: 20px;
}
.image {
width: 100%;
height: 300px;
background-color: grey;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="col-sm-12">
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean consectetur dui quis arcu varius, sit amet consectetur risus auctor. Nulla id mattis ligula. Aliquam euismod dui et viverra ultrices. Praesent eget quam quam. Aenean sit amet lectus et leo ultrices sodales id sed nulla. Proin fringilla, dui vitae tincidunt tincidunt, nisi tellus efficitur lacus, ac facilisis libero elit ut tellus. In finibus tortor leo, hendrerit sagittis libero maximus sed. Sed rhoncus maximus odio, nec vestibulum enim fringilla ac. Nulla faucibus, justo nec fermentum blandit, est nisl eleifend purus, non pretium orci sapien at eros. Fusce non laoreet augue. Aenean ac eros augue. Sed sit amet enim sit amet lorem finibus volutpat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris placerat, diam sed vulputate aliquet, augue erat luctus massa, molestie egestas diam metus at dolor. Vivamus a metus vitae magna dignissim pulvinar.
</p>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Etiam id ullamcorper augue, a pharetra nisi. Sed justo enim, malesuada elementum erat non, vehicula varius turpis. Sed quis scelerisque eros, in vestibulum mi. Maecenas et consectetur risus, sed sagittis ex. Aliquam vestibulum fermentum hendrerit. Nulla eget hendrerit purus. Suspendisse commodo vel tortor ut sollicitudin.
</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
How can we get the two boxes below the image to equal height?
Any help is appreciated!
There is no CSS method of equalising heights of elements that do not share a parent. If the top image is always the same height between columns you can use flexbox to expand the smaller/shorter column though.
.col-sm-12 {
display: flex;
}
.col-sm-6 {
width: 50%;
flex: 1;
display: flex;
flex-direction: column;
}
.c1 {
flex: 1;
display: flex;
flex-direction: column;
}
.c2 {
padding: 20px;
flex: 1;
display: flex;
flex-direction: column;
}
.c3 {
border: 1px solid grey;
padding: 20px;
flex: 1;
}
.image {
width: 100%;
height: 300px;
background-color: grey;
}
<div class="col-sm-12">
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean consectetur dui quis arcu varius, sit amet consectetur risus auctor. Nulla id mattis ligula. Aliquam euismod dui et viverra ultrices. Praesent eget quam quam. Aenean sit amet lectus et leo
ultrices sodales id sed nulla. Proin fringilla, dui vitae tincidunt tincidunt, nisi tellus efficitur lacus, ac facilisis libero elit ut tellus. In finibus tortor leo, hendrerit sagittis libero maximus sed. Sed rhoncus maximus odio, nec vestibulum
enim fringilla ac. Nulla faucibus, justo nec fermentum blandit, est nisl eleifend purus, non pretium orci sapien at eros. Fusce non laoreet augue. Aenean ac eros augue. Sed sit amet enim sit amet lorem finibus volutpat. Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Mauris placerat, diam sed vulputate aliquet, augue erat luctus massa, molestie egestas diam metus at dolor. Vivamus a metus vitae magna dignissim pulvinar.
</p>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="c1">
<div class="c2">
<div class="image">
</div>
<div class="c3">
<p>
Etiam id ullamcorper augue, a pharetra nisi. Sed justo enim, malesuada elementum erat non, vehicula varius turpis. Sed quis scelerisque eros, in vestibulum mi. Maecenas et consectetur risus, sed sagittis ex. Aliquam vestibulum fermentum hendrerit. Nulla
eget hendrerit purus. Suspendisse commodo vel tortor ut sollicitudin.
</p>
</div>
</div>
</div>
</div>
</div>
Just use inline-style on the text div tags:
style="height:30em;overflow:scroll"
lol. There might be a lot of new, flashy and sexy frameworks & technologies out there (which I really like), but sometimes going back to the old school methods is a lot simpler and more efficient.

How do I make my side column extend all the way to the end?

For my website, I can't get my side column to extend all the way to the end of the body column without giving it a fixed max height (it's supposed to adjust according to the length of the body, which is altered either by the amount of words/content the body has and/or the wrapping of the body in a smaller screen). Please keep in mind that I have a footer at the bottom that is supposed to take up the entire width of the screen so I can't do something that makes the side column longer than anything and keep everything else on the body column.
Here is my example: https://jsfiddle.net/r7g20fvk/
Here is the code:
<style>
.sidebar_container {
float: right;
width: 70%;
max-width: 230px;
margin: 0px 20px 20px 0;
min-width: 300px;
/*I can add a min-height until the side column is long enough to reach the entire bottom rather than end after the content runs out, but it doesn't adjust accordingly (to the length of the body column, whether the screen makes the body longer or the amount of text makes the body longer)*/
}
.left {
overflow: hidden width: 70%;
line-height: 2;
font-size: 18px;
}
</style>
<div class="left">
<h2>Home</h2>
</div>
<div>
<div class="sidebar_container" style="float: right;">
<div class="sidebar">
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</div>
<div class="sidebar">
<h2>Post 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus.. Read More</p>
</div>
<div class="sidebar">
<h2>Post 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat id. Donec vehicula lorem
neque, vel mattis arcu semper in...Read More</p>
</div>
<!--close sidebar-->
</div>
<div class="left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat id. Donec vehicula lorem
neque, vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu enim a mauris ullamcorper
tincidunt ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus in mauris. Nunc molestie libero
quis odio tristique euismod.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat
id. Donec vehicula lorem neque, vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu
enim a mauris ullamcorper tincidunt ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus in mauris.
Nunc molestie libero quis odio tristique euismod.</p>
</div>
</div>
Is there a way to make it adjust accordingly? Perhaps make the side column's width be a percentage of the entire width of the screen so it isn't a fixed width when viewing at a smaller screen size, or make it completely disappear or something when in super-small mobile screens. I'm trying to make it mobile friendly and adjust its height based off of the bottom.
Do you think making a table (with two columns, one as body and one on the side) would be a better way of making the webpage mobile friendly and automatically adjust to the wrapping of content? Or is there a better way using div grouping?
Something like this?: https://jsfiddle.net/xcy9s64g/
The trick is to position the right child div absolutely:
position: absolute;
right: 0;
top: 0;
And, of course, positioning the parent container as relative, to provide a reference point for the absolute positioning. Then, you can use percentages for the children.
#container {
position: relative;
width: 100%;
}
Do you think making a table (with two columns, one as body and one on
the side) would be a better way of making the webpage mobile friendly
and automatically adjust to the wrapping of content? Or is there a
better way using div grouping?
Using a table for layout is a bad idea. Use flexbox instead if you want to try something different.
I think you should use flexbox, hope it solves your problem.
Please check this codepen solution
body {
background: #eee;
}
section {
padding: 10px;
}
h2 {
margin: 0;
padding: 0;
display: inline-block;
}
.wrapper {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.main-container {
background: #fff;
margin: 10px;
display: flex;
/*flex-wrap: wrap;*/
/*justify-content: space-between;*/
}
.left-container {
flex: 3 3 70%;
background-color: #fff;
}
.right-container {
flex: 1 1 30%;
flex-direction: column;
background-color: #ccc;
}
#media screen and (max-width:768px) {
.main-container {
display: flex;
flex-wrap: wrap;
}
.left-container {
flex: 0 1 100%;
order: 1;
/*change the order of the blocks for smaller screens as you like */
background-color: #fff;
}
.right-container {
flex: 0 1 100%;
order: 2;
/*change the order of the blocks for smaller screens as you like */
background-color: #ccc;
}
}
<body>
<div class="wrapper">
<div class="main-container">
<section class="left-container">
<h2>Home</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat id. Donec vehicula lorem neque,
vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu enim a mauris ullamcorper tincidunt
ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus in mauris. Nunc molestie libero quis odio
tristique euismod.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat
id. Donec vehicula lorem neque, vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
eu enim a mauris ullamcorper tincidunt ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus
in mauris. Nunc molestie libero quis odio tristique euismod.
</p>
</section>
<section class="right-container">
<article>
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</article>
<article>
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</article>
<article>
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</article>
</section>
</div>
</div>
</body>

Force image to overflow padding of parent div and be 100% wide

I want images with class wide to go over the parent div's padding. When I give them negative margin to do it, they don't stretch to full width (max-width:100% keeps them the same size).
#content {
padding: 20px;
border: 1px solid red;
}
/* regular images */
#content img {
max-width: 100%;
}
/* full width images, videos etc */
#content .wide {
margin-left: -20px;
margin-right: -20px;
}
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet non libero eget ornare. Proin commodo tortor risus, vitae malesuada lectus pharetra quis. Aliquam quis elit in erat facilisis pellentesque. Donec ornare ligula eu massa dignissim posuere
sed eu sapien.</p>
<!-- this should stretch -->
<img class="wide" src="http://pic.templetons.com/brad/pano/europe/epidaurus-wide.jpg">
<p>orci. Proin nec nunc pulvinar, feugiat lorem in, imperdiet ante. Proin interdum quam id congue tincidunt. Praesent pellentesque facilisis dictum. Nulla vel nulla turpis. Fusce mauris elit</p>
<!-- this one should NOT -->
<img src="http://pic.templetons.com/brad/pano/europe/epidaurus-wide.jpg">
<p>orci. Proin nec nunc pulvinar, feugiat lorem in, imperdiet ante. Proin interdum quam id congue tincidunt. Praesent pellentesque facilisis dictum. Nulla vel nulla turpis. Fusce mauris elit, s</p>
</div>
How can I achieve it? I want the image to be left to right without no spaces on sides.
Images without the class wide should be contained inside the paddings as normal.
(ps. giving margin to everything but the images will work, but it's a lot of work and not very elegant)
I'd suggest adding markup as isherwoord suggested, which would allow for better browser support than my answer. If that is not possible, you can use the calc function to add the negative margins to the 100% width. Browser support isn't even that bad!
#content {
padding: 20px;
border: 1px solid red;
}
/* regular images */
#content img {
max-width: 100%;
}
/* full width images, videos etc */
#content .wide {
margin-left: -20px;
margin-right: -20px;
max-width: calc(100% + 40px);
}
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet non libero eget ornare. Proin commodo tortor risus, vitae malesuada lectus pharetra quis. Aliquam quis elit in erat facilisis pellentesque. Donec ornare ligula eu massa dignissim posuere
sed eu sapien.</p>
<!-- this should stretch -->
<img class="wide" src="http://pic.templetons.com/brad/pano/europe/epidaurus-wide.jpg">
<p>orci. Proin nec nunc pulvinar, feugiat lorem in, imperdiet ante. Proin interdum quam id congue tincidunt. Praesent pellentesque facilisis dictum. Nulla vel nulla turpis. Fusce mauris elit</p>
<!-- this one should NOT -->
<img src="http://pic.templetons.com/brad/pano/europe/epidaurus-wide.jpg">
<p>orci. Proin nec nunc pulvinar, feugiat lorem in, imperdiet ante. Proin interdum quam id congue tincidunt. Praesent pellentesque facilisis dictum. Nulla vel nulla turpis. Fusce mauris elit, s</p>
</div>
Instead of stretching the image with negative margins, add a container element:
#content {
padding: 20px;
border: 1px solid red;
}
/* regular images */
#content img {
max-width: 100%;
}
/* full width images, videos etc */
#content .wide {
margin-left: -20px;
margin-right: -20px;
}
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquet non libero eget ornare. Proin commodo tortor risus, vitae malesuada lectus pharetra quis. Aliquam quis elit in erat facilisis pellentesque. Donec ornare ligula eu massa dignissim posuere
sed eu sapien.</p>
<!-- this should stretch -->
<div class="wide">
<img src="http://pic.templetons.com/brad/pano/europe/epidaurus-wide.jpg">
</div>
<p>orci. Proin nec nunc pulvinar, feugiat lorem in, imperdiet ante. Proin interdum quam id congue tincidunt. Praesent pellentesque facilisis dictum. Nulla vel nulla turpis. Fusce mauris elit</p>
</div>