Positioning an image in a 100vh box - html

I've been looking around for some time but couldn't find a solution.
So I'm working on a Personal portfolio with different sections (height: 100vh;). The problem I have is that I'm unable to position the images within the section itself (I want the image of the pinguïns to be positioned like the first lion image. But in the section below.). Can someone help me with this? (I'm using a bootstrap grid)
Code:
.section-1 {
background: radial-gradient(#2d2d2d, #1a1a1a);
height: 100vh;
}
.section-2 {
background: #fc6621;
height: 100vh;
}
.section-3 {
background: #20468b;
height: 100vh;
}
.col-sm-6 {
height: 100vh;
}
#profile img {
display: inline;
float: right;
position: absolute;
bottom: 0;
right: 0;
z-index: 0;
}
.center {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
}
.text {
height: 100vh;
position: relative;
z-index: 10;
}
<!-- 1st section -->
<div class="section-1">
<div id="profile"><img src="https://i.gyazo.com/4cefd23a7fdc59ac022cc46d44fe9321.jpg" width="1006" height="821"></div>
<div class="container">
<div class="row">
<div class="col-sm-6 center text">
<h1>I'm <strong>Gilles</strong></h1>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit. Vestibulum id ligula porta felis euismod semper. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam
id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum.</p>
<div class="col-sm-4 button">CONTACT ME</div>
</div>
</div>
</div>
</div>
<!-- 2nd section -->
<div class="section-2">
<div id="smartschool"><img src="https://i.gyazo.com/abdeb771b58043c53cfb08e5ffd42f6e.jpg" width="990" height="753"></div>
<div class="container">
<div class="row">
<div class="col-sm-6 center text">
<h1>I'm <strong>Gilles</strong></h1>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit. Vestibulum id ligula porta felis euismod semper. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam
id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum.</p>
<div class="col-sm-4 button">READ MORE</div>
</div>
</div>
</div>
</div>
<!-- 3th section -->
<div class="section-3">
<div id="dutchcreativestudio"><img src="https://i.gyazo.com/4cefd23a7fdc59ac022cc46d44fe9321.jpg" width="933" height="643"></div>
<div class="container">
<div class="row">
<div class="col-sm-6 center text">
<h1>I'm <strong>Gilles</strong></h1>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Nullam id dolor id nibh ultricies vehicula ut id elit. Vestibulum id ligula porta felis euismod semper. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam
id dolor id nibh ultricies vehicula ut id elit. Donec sed odio dui. Cras mattis consectetur purus sit amet fermentum.</p>
<div class="col-sm-4 button">READ MORE</div>
</div>
</div>
</div>
</div>
The first one does the right thing!
But then it gets a mess (or they stack above each other)

position: absolute; is relative to the nearest parent. if no parents have a set position, it will be relative to the body which is what seems to be happening here.
so each 100vh section will need to have position: relative;
its also worth noting that float won't do anything on an element with absolute positioning, since position: absolute; takes the element out of the document flow.

Related

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

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.

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/

How can I align the paragraphs in this div with pure CSS?

JSfiddle
I have a situation where I would like to float a small image to the left of text within a div. I don't want the text to wrap under the image, and some research led me to add the overflow:hidden; property on <p>. While this makes the paragraph next to the image behave as I want, the following paragraphs are then not aligned with the first. Is there a nice way to get all paragraphs aligned? I tried display: table-row;, but this affects other elements on the page (and I have read up on why this is the case).
I need to work within the constraints present in the JSFiddle (i.e., can't really modify html), and cross-browser support is a priority.
.header {
color: white;
background-color: red;
padding: 15px;
}
.header p {
overflow: hidden;
}
.img {
background-color: green;
width: 45px;
height: 45px;
float: left;
}
<div class="header">
<div class="img">
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet turpis vel diam elementum imperdiet eu id ex. Nam dictum blandit ullamcorper. Nam ultrices risus neque, eget finibus dolor suscipit a. Fusce lobortis dictum odio sit amet tempus. Ut
pretium augue vitae neque finibus, quis ornare dolor fermentum.
</p>
<p>
Maecenas suscipit risus tellus, posuere commodo diam egestas ut. Suspendisse ex enim, ullamcorper et faucibus nec, viverra vel leo. Aliquam venenatis mi metus, et tincidunt nulla laoreet quis. Donec sodales nunc ut finibus cursus.
</p>
</div>
Use a margin-left on the paragraphs that is the width of the image + the margin/space you want between the image and paragraph. Then you have no need for the overflow.
.header {
color: white;
background-color: red;
padding: 15px;
}
.header p {
margin: 0 0 1em 55px;
}
.img {
background-color: green;
width: 45px;
height: 45px;
float: left;
}
<div class="header">
<div class="img">
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet turpis vel diam elementum imperdiet eu id ex. Nam dictum blandit ullamcorper. Nam ultrices risus neque, eget finibus dolor suscipit a. Fusce lobortis dictum odio sit amet tempus. Ut
pretium augue vitae neque finibus, quis ornare dolor fermentum.
</p>
<p>
Maecenas suscipit risus tellus, posuere commodo diam egestas ut. Suspendisse ex enim, ullamcorper et faucibus nec, viverra vel leo. Aliquam venenatis mi metus, et tincidunt nulla laoreet quis. Donec sodales nunc ut finibus cursus.
</p>
</div>
So, you should set a div for the whole thing, one for the image and one for the text.
I don't know if that's what you're looking for, but here you go.
.container {
width: 400px;
height: auto;
}
.imageDiv {
max-width: 200px;
height: auto;
float: left;
}
.image {
max-width: 100%;
}
.text {
max-width: 200px;
min-width: 200px;
text-align: center;
float: left;
}
<div class="container">
<div class="text">
<p>
Some text.
</p>
</div>
<div class="imageDiv">
<img class="image" src="http://nexceris.com/wp-content/uploads/2014/04/bokeh-cover-bg.jpg">
</div>
</div>
Code the one div for other content and manage that two inside div like you want.
<div class="header">
<div class="img">
</div>
<div class="other">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet turpis vel diam elementum imperdiet eu id ex. Nam dictum blandit ullamcorper. Nam ultrices risus neque, eget finibus dolor suscipit a. Fusce lobortis dictum odio sit amet tempus. Ut pretium augue vitae neque finibus, quis ornare dolor fermentum.
</p>
<p>
Maecenas suscipit risus tellus, posuere commodo diam egestas ut. Suspendisse ex enim, ullamcorper et faucibus nec, viverra vel leo. Aliquam venenatis mi metus, et tincidunt nulla laoreet quis. Donec sodales nunc ut finibus cursus.
</p>
</div>
</div>

Pure CSS solution blocks flowing out of grid

I've made an illustration of the situation:
The blue lines illustrate the grid the website is in. Let's assume a 960 grid for now, with a 300px left side (red part), a 20px gap and the remaining 640px for the right side (the black and green parts). I want to know if there's a solution for this problem that doesn't use calc() (due to older browsers) or background-image (because that's not really pretty).
Is there a pretty way to make this work, using just CSS while keeping the content centered within the grid, and the backgrounds flowing all the way to the borders of the screen?
http://codepen.io/anon/pen/avoKwQ
Done by pseudo elements and absolute positioning. Used bootstrap for faster demo. Actually, it is a specific problem and my solution may not fit your project. Especially not work when you require horizontal scrolling. But problem is solved.
&:after {
content: " ";
position: absolute;
top: 0; right: 6px;
width: 99999%;
height: 100%;
background: red;
z-index: -1;
}
Parent of this element ofcourse require position: relative. In example this is done by bootstrap.
Flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This one has the added benefit of the columns always being equal height:
* { margin:0; padding:0; box-sizing: border-box; }
.grid {
display: flex;
}
.col-3 {
flex: 1 1 320px;
border-right: 20px solid #fff;
}
.col-2-3 {
flex: 1 1 640px;
}
.col-3 {
display: flex;
justify-content: flex-end;
}
.col-3>div {
padding: 20px;
flex: 0 1 300px;
}
.col-2-3>div {
display: flex;
justify-content: flex-start;
}
.col-2-3>div>div {
flex: 0 1 640px;
padding: 20px;
}
.red { background: #f00; color: #fff; }
.green { background: #0f0;}
.black { background: #000; color: #fff;}
<div class="grid">
<div class="col-3 red">
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis rhoncus erat. Morbi id pretium tortor. Sed tristique, leo non fringilla tempor, orci ligula lobortis velit, a efficitur tortor dui eget libero. Ut aliquam tortor sed diam placerat, ut lacinia ipsum lacinia. Cras a neque vehicula arcu rutrum luctus. Aliquam placerat ac ex in tincidunt. Quisque nulla diam, cursus nec orci sit amet, aliquet tempor massa.
</p>
</div>
</div><!-- col -->
<div class="col-2-3 green">
<div class="black">
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis rhoncus erat. Morbi id pretium tortor. Sed tristique, leo non fringilla tempor, orci ligula lobortis velit, a efficitur tortor dui eget libero. Ut aliquam tortor sed diam placerat, ut lacinia ipsum lacinia. Cras a neque vehicula arcu rutrum luctus. Aliquam placerat ac ex in tincidunt. Quisque nulla diam, cursus nec orci sit amet, aliquet tempor massa.
</p>
</div>
</div><!-- .black -->
<div class="green">
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis rhoncus erat. Morbi id pretium tortor. Sed tristique, leo non fringilla tempor, orci ligula lobortis velit, a efficitur tortor dui eget libero. Ut aliquam tortor sed diam placerat, ut lacinia ipsum lacinia. Cras a neque vehicula arcu rutrum luctus. Aliquam placerat ac ex in tincidunt. Quisque nulla diam, cursus nec orci sit amet, aliquet tempor massa.
</p>
</div>
</div><!-- .green -->
</div><!-- .col -->
</div><!-- .grid -->