Width ratio for divs/columns in a flex box - html

I have a responsive template made with a flex box containing a picture div/column and a text div/column. When the width is 50% for both columns, its working fine. But now i want the picture width to be 60% and the text width to be 40%. My problem is when i remove the flex:0 0 auto; width: 50%; in the .container .columns css section and try to give the .columns.image a width of 60% and the .columns.content a width of 40% it creates problems with the media query.
#import url("https://fonts.googleapis.com/css2?family=Assistant&display=swap");
#import url("https://use.typekit.net/yoj6eqg.css");
* {
padding: 0;
margin: 0;
}
body {
overflow-x: hidden;
}
.container {
--bs-gutter-x: 1.5rem;
--bs-gutter-y: 0;
display: flex;
flex-wrap: wrap;
margin: 5% 15% 5% 15%;
}
.container .columns {
flex: 0 0 auto;
width: 50%;
}
.container .columns.image {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.container .columns.content .content-container {
padding: 40px 50px;
background-color: #e6e6e6;
}
.container .columns.content .content-container h1 {
font-weight: 700;
font-size: 35px;
color: #86b530;
margin-bottom: 20px;
font-family: "p22-underground", sans-serif;
font-weight: 600;
font-style: strong;
}
.container .columns.content .content-container p {
font-weight: 400;
font-size: 16px;
color: #333333;
margin-bottom: 20px;
margin-bottom: 15px;
text-align: justify;
font-family: "Assistant", sans-serif;
}
#media screen and (max-width: 767px) {
.container {
flex-flow: row wrap;
}
.container .columns.image {
display: block;
order: 1;
width: 100%;
height: 250px;
}
.container .columns.content {
display: block;
order: 2;
width: 100%;
}
.container .columns.content .content-container {
padding: 20px 35px;
}
.container .columns.content .content-container h1 {
margin-bottom: 5px;
}
}
<div class="container">
<div style="background-image: url('https://wallpaperset.com/w/full/a/c/7/185665.jpg');" class="columns image">
</div>
<div class="columns content">
<div class="content-container">
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor
sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam
erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer
adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud.</p>
</div>
</div>
</div>
I tried to apply the different flex ratios and edited the media query, but to no success. I would prefer to keep the flex box instead of changing to a grid. If anyone has a solution, i would be very thankful.

For the equal (50%) column space distribution inside parent .container you used:
.container .columns {
flex: 0 0 auto;
width: 50%;
}
This was sufficient CSS as both columns were equally wide. However, for uneven distribution (60% vs. 40%) you will have to define per column how much parent space it gets:
.container .columns { flex: 0 0 auto }
.container .columns.image { width: 60% }
.container .columns.content { width: 40% }
On smaller devices (<960px) container .columns.content now gets a bit too narrow to my taste, but that's another problem to solve. Maybe another #media with your original 50% distribution...

Related

Using flexbox to align 3 items in a row

I'm trying to align three div's in one row at a 800px break point.
I have two break points in my code and everything works until it hits 800px. At 800px, 'Reviewer 3' ends up on it's own line below 'Reviewer 1 & 2'.
.cards {
display: flex;
flex-direction: column;
align-items: center;
}
.border {
padding: 50px;
font-size: 22px;
}
.center {
position: relative;
left: 25%;
}
#media screen and (min-width: 600px) {
h3 {
color: blue;
}
.cards {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.border {
padding: 50px;
text-align: center;
}
.center {
display: relative;
left: 0;
}
.wrapper {
display: flex;
flex-direction: row;
}
.card-1,
.card-2 {
margin: 15px;
border: 1px solid black;
text-align: center;
width: 50%;
}
.card-3 {
position: relative;
left: 25%;
border: 1px solid black;
margin: 15px;
width: 50%;
text-align: center;
}
#media screen and (min-width: 800px) {
h3 {
color: red;
}
.cards {
display: flex-box;
flex-direction: row;
}
.card-1,
.card-2,
.card-3 {
margin: 30px;
border: 1px solid black;
text-align: center;
width: 30%;
height: 20%;
}
}
<div class="cards">
<div class="wrapper">
<div class="card-1">
<h3>Reviewer 1</h3>
<img class="center" src="https://via.placeholder.com/250" alt="placeholder">
<p class="border">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</p>
</div>
<div class="card-2">
<h3>Reviewer 2</h3>
<img class="center " src="https://via.placeholder.com/250" alt="placeholder">
<p class="border">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</p>
</div>
</div>
<div class="card-3">
<h3>Reviewer 3</h3>
<img class="center" src="https://via.placeholder.com/250" alt="placeholder">
<p class="border" id="b3">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</p>
</div>
</div>
Your problem is an HTML problem. The third box is outside the .wrapper element.
Also, use flex-basis or min-width instead of width. Finally, are you sure you want to use left: 30%?
Update:
Move #media (min-width: 600px) below #media (min-width: 800px) so the 600 one will override when the screen hits the breakpoint
Add some calc() statements to account for borders + margin
Add flex-wrap: wrap to .wrapper (not .cards) because .wrapper is the parent of .card-1, .card-2, and .card-3 (not .cards).
.cards {
display: flex;
flex-direction: column;
align-items: center;
}
.border {
padding: 50px;
font-size: 22px;
}
img {
max-width: 100%;
height: auto;
}
.wrapper {
/* This works for wrapper's children, namely card-1, card-2, card-3 */
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.card-1,
.card-2,
.card-3 {
border: 1px solid black;
text-align: center;
flex-basis: 100%;
}
#media screen and (min-width: 600px) {
h3 {
color: blue;
}
.card-1,
.card-2 {
margin: 15px;
flex-basis: calc(50% - 32px);
}
.card-3 {
position: relative;
margin: 15px;
flex-basis: 100%;
}
}
#media screen and (min-width: 800px) {
h3 {
color: red;
}
.card-1,
.card-2,
.card-3 {
margin: 30px;
flex-basis: calc(33.33% - 62px);
height: 20%;
}
}
<div class="cards">
<div class="wrapper">
<div class="card-1">
<h3>Reviewer 1</h3>
<img class="center" src="https://via.placeholder.com/250" alt="placeholder">
<p class="border">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</p>
</div>
<div class="card-2">
<h3>Reviewer 2</h3>
<img class="center " src="https://via.placeholder.com/250" alt="placeholder">
<p class="border">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</p>
</div>
<div class="card-3">
<h3>Reviewer 3</h3>
<img class="center" src="https://via.placeholder.com/250" alt="placeholder">
<p class="border" id="b3">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam."</p>
</div>
</div>
</div>

Full width element: How to make an absolute positioned element to be full width within a grid

I have an article which is within a grid.
The Article body spans 6 columns
I need one of the items within the article body to go full width (beyond the 6 columns container)
The element i am trying make full width is a video / iframe which needs to keep an aspect ratio of 16:9
The video / iframe is absolutely positioned
Here is the code pen so far.
https://codepen.io/miteshsevani/pen/xxEGQdX
.container {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 1536px;
padding-bottom: 24px;
padding-left: 48px;
padding-right: 48px;
width: 100%;
}
.grid {
display: grid;
flex-wrap: nowrap;
grid-gap: 16px;
grid-template-columns: repeat(12, 1fr);
margin-left: 0;
margin-right: 0;
list-style-type: none;
margin: 0 -8px;
padding-left: 0;
}
.article__layout {
grid-column: 2/9;
width: auto;
padding-top: 8px;
padding-left: 0;
padding-right: 0;
}
.video-player.u-align--full-width {
display: grid;
grid-gap: 16px;
grid-template-columns: repeat(7, 1fr);
margin-bottom: 32px;
position: relative;
width: 100vw;
height: auto;
padding-bottom: 56.25%;
padding-bottom: 0;
}
.u-align__wrapper {
padding-bottom: 56.25%;
position: relative;
width: 100vw;
grid-column: 1/7;
align-items: center;
/* display: flex; */
grid-column: 1/-1;
justify-content: center;
vertical-align: middle;
}
.video-player__source.u-align__container {
left: 0;
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
<div class="container">
<div class="grid">
<div class="article__layout">
<div>
<div class="article-body-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent tristique magna sit amet purus gravida. Leo integer malesuada nunc vel risus. Mi sit amet mauris commodo quis
imperdiet.</p>
<!-- VIDEO BLOCK START -->
<div>
<div class="alignBodyVideoPlayer">
<div clas="video-player u-align--full-width">
<div class="u-align__wrapper">
<iframe class="video-player__source u-align__container" width="640" height="360" src="https://www.youtube.com/embed/C0DPdy98e4c">
</iframe>
</div>
</div>
</div>
</div>
<!-- VIDEO BLOCK END -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent tristique magna sit amet purus gravida. Leo integer malesuada nunc vel risus. Mi sit amet mauris commodo quis
imperdiet.</p>
</div>
</div>
</div>
</div>
</div>
How can I get it to go full width / edge to edge?
I suggest to remove your class grid in your design and add width:100% to the class .u-align__wrapper from what I've observed .u-align__wrapper class contains width:100vw.
Here's the full preview.
.container {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 1536px;
padding-bottom: 24px;
padding-left: 48px;
padding-right: 48px;
width: 100%;
}
.grid {
display: grid;
flex-wrap: nowrap;
grid-gap: 16px;
grid-template-columns: repeat(12,1fr);
margin-left: 0;
margin-right: 0;
list-style-type: none;
margin: 0 -8px;
padding-left: 0;
}
.article__layout {
grid-column: 2/9;
width: auto;
padding-top: 8px;
padding-left: 0;
padding-right: 0;
}
.video-player.u-align--full-width {
display: grid;
grid-gap: 16px;
grid-template-columns: repeat(7,1fr);
margin-bottom: 32px;
position: relative;
width: 100vw;
height: auto;
padding-bottom:56.25%;
padding-bottom: 0;
}
.u-align__wrapper {
padding-bottom: 56.25%;
position: relative;
width: 100%;
grid-column: 1/7;
align-items: center;
/* display: flex; */
grid-column: 1/-1;
justify-content: center;
vertical-align: middle;
}
.video-player__source.u-align__container {
left: 0;
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
<div class="container">
<div class="">
<div class="article__layout">
<div>
<div class="article-body-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent tristique magna sit amet purus gravida. Leo integer malesuada nunc vel risus. Mi sit amet mauris commodo quis imperdiet.</p>
<!-- VIDEO BLOCK START -->
<div>
<div class="alignBodyVideoPlayer">
<div clas="video-player u-align--full-width">
<div class="u-align__wrapper">
<iframe class="video-player__source u-align__container" width="640" height="360" src="https://www.youtube.com/embed/C0DPdy98e4c">
</iframe>
</div>
</div>
</div>
</div>
<!-- VIDEO BLOCK END -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent tristique magna sit amet purus gravida. Leo integer malesuada nunc vel risus. Mi sit amet mauris commodo quis imperdiet.</p>
</div>
</div>
</div>
</div>
</div>
As much as I'm able to understand your problem, if you remove position: relative; style from your .u-align__wrapper class and add position: relative; to your parent div, i.e .container class, then the video will be of full width and height.

Align contents vertically in middle of flexed div

I would like to align the contents of div in the middle of vertical alignment. Table-cell will not function here, due to the fact, that parent is and must be displayed flex. This is used in the new WordPress Gutenberg editor. I do not want to modify the editor itself if possible and achieve this with CSS alone. Below you will find how the code looks currently. Custom HTML also cannot be added without editing editor. Is there a possibility of this be achieved in the current state?
Desired result:
Current code and state:
JSFiddle
HTML:
<div class="wp-block-columns has-2-columns right-33">
<div class="wp-block-column">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
</div>
<div class="wp-block-column">
<figure class="wp-block-image">Here be image</figure>
</div>
</div>
CSS:
h3 {margin: 0 0 20px 0;}
.wp-block-columns {
display: flex;
flex-wrap: no-wrap;
padding: 5px;
border: solid 1px red;
}
.wp-block-column {
flex: 1;
margin-bottom: 1em;
flex-basis: 100%;
min-width: 0;
word-break: break-word;
overflow-wrap: break-word;
flex-grow: 0;
border: solid 1px blue;
}
.right-33 > div:first-child {
flex-basis: 66.6666%;
margin-right: 32px;
}
.right-33 > div:last-child {
flex-basis: 33.3333%;
margin-left: 32px;
}
.wp-block-image {
background: green;
margin: 0 auto;
width: 100%;
height: 200px;
}
You can add this to your wp-block-column column:
.wp-block-column {
display: flex;
flex-direction: column;
justify-content: center;
}
Here's your updated JSFiddle.
This is a great visual guide on Flexbox, it might help you in the future.
Create a column flexbox to .right-33>div:first-child and align to center using justify-content: center - see demo below:
h3 {
margin: 0 0 20px 0;
}
.wp-block-columns {
display: flex;
flex-wrap: no-wrap;
padding: 5px;
border: solid 1px red;
}
.wp-block-column {
flex: 1;
margin-bottom: 1em;
flex-basis: 100%;
min-width: 0;
word-break: break-word;
overflow-wrap: break-word;
flex-grow: 0;
border: solid 1px blue;
}
.right-33>div:first-child {
flex-basis: 66.6666%;
margin-right: 32px;
/*ADDED FLEXBOX*/
display: flex;
flex-direction: column;
justify-content: center;
}
.right-33>div:last-child {
flex-basis: 33.3333%;
margin-left: 32px;
}
.wp-block-image {
background: green;
margin: 0 auto;
width: 100%;
height: 200px;
}
<div class="wp-block-columns has-2-columns right-33">
<div class="wp-block-column">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
</div>
<div class="wp-block-column">
<figure class="wp-block-image">Here be image</figure>
</div>
</div>
The setting to use for vertically centered alignment of flex children is align-items: center;, applied to the flex container. I added it to your code here (at the end of the CSS section):
h3 {
margin: 0 0 20px 0;
}
.wp-block-columns {
display: flex;
flex-wrap: no-wrap;
padding: 5px;
border: solid 1px red;
}
.wp-block-column {
flex: 1;
margin-bottom: 1em;
flex-basis: 100%;
min-width: 0;
word-break: break-word;
overflow-wrap: break-word;
flex-grow: 0;
border: solid 1px blue;
}
.right-33>div:first-child {
flex-basis: 66.6666%;
margin-right: 32px;
}
.right-33>div:last-child {
flex-basis: 33.3333%;
margin-left: 32px;
}
.wp-block-image {
background: green;
margin: 0 auto;
width: 100%;
height: 200px;
}
.wp-block-columns.has-2-columns.right-33 {
align-items: center;
}
<div class="wp-block-columns has-2-columns right-33">
<div class="wp-block-column">
<h3>Some title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
</div>
<div class="wp-block-column">
<figure class="wp-block-image">Here be image</figure>
</div>
</div>

Align text under picture, in relation to picture width

I'm using CSS to try to align 2 pictures side by side with some text underneath each picture. I'm trying to make it so that the text under the picture justifies to the width of the picture, no matter what the size of the picture. But what I get as a result is the two blocks of text overlapping. For example, I want it to look like:
**************** ***************
* Image * * Image *
* * * *
**************** ***************
Lorem ipsum dolor Lorem ipsum dolor
sit amet, sit amet,
consectetuer consectetuer
adipiscing adipiscing
elit, sed diam elit, sed diam
But I can't get the text under the image to justify, instead, they overlap. I also want it to come right before the footer (last element on the page before the footer), but the footer is overlapping some of the text as well. Here is my code:
HTML:
<div class="container">
<div class="img">
<img src="flower1small.jpg" alt="flower">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
<div class="image">
<img src="flower1small.jpg" alt="flower">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div>
</div>
And the CSS:
.container{
margin-top: 15%;
margin-left: 10%;
}
.img {
width:800px;
margin-left:auto;
margin-right:auto;
position: absolute;
}
.image {
width:800px;
margin-left:auto;
margin-right:auto;
position: relative;
}
div.img p{
text-align: justify;
display: block;
width:800px;
}
.bottom{
padding: 15px;
}
footer{
background: #660000;
position:absolute;
bottom:0;
width: 85%;
height:100px;
margin-right: 10%;
margin-left: 10%;
}
footer a{
color: #ffffff;
text-decoration: none;
font-size: 10px;
}
footer label{
color: #ffffff;
font-size: 10px;
}
What can I do to make it align properly? Any help would be greatly appreciated. Thanks in advance.
Do you mean like this: Example Fiddle ?
You would have to set a max-width for the .img elements. I used an example of a max-width of 250px and images with a width of 200px. Also you need to float them and apply a clearfix, so that the footer is positioned correctly. The footer needs to get rid of position: absolute.
That the whole .img element just uses the width of the picture for the text is not possible without javascript, so you would have to set the width via CSS.
.container{
margin-top: 15%;
margin-left: 10%;
display: block;
}
.img {
max-width:250px;
float: left;
margin: 0 5%;
}
.img img {
margin: 0 auto;
display: block;
}
.img p{
text-align: justify;
width:250px;
display: block;
}
.bottom{
padding: 15px;
}
footer{
background: #660000;
width: 85%;
height:100px;
margin-right: 10%;
margin-left: 10%;
}
footer a{
color: #ffffff;
text-decoration: none;
font-size: 10px;
}
footer label{
color: #ffffff;
font-size: 10px;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
Since both of these elements are within a container. You could easily set the percentage of the containers child elements to the same percentage. This way the image and the paragraph will always be the same width, no matter what your container size may be.
EX:
.image img, .image p { width: 90% }

Align Text with Image in CSS

I'm trying to line up text and an image below a title acting as a header, but the image keeps throwing off the divider between entries and messing up the page's alignment. Here's what it looks like (Django templates in use here)
Here's the code:
<script src="/static/js/downloadEntry.js" type="text/javascript"></script>
{% for entry in entries %}
<div class="entry">
<label class="titleText">{{ entry.title }}</label>
<div class="contentContainer">
{% if entry.image %}
<img class="image" src="{{ entry.image.url }}">
{% endif %}
<p class="contentText">{{ entry.content }}</p>
</div>
<script>styleTitle("{{ entry.title }}");</script>
</div>
<hr class="entryDivider">
{% endfor %}
The relevant CSS:
.entryDivider {
margin-top: 10px;
size: 1px;
width: 66%;
}
.entry {
width: 66%;
margin-top: 30px;
margin-bottom: 10px;
}
.titleText {
font-family: "Helvetica Neue";
font-size: 24px;
font-weight: bold;
color: #666666;
text-align: left;
font-style: normal;
text-transform: uppercase;
display: block;
margin-bottom: 15px;
}
.contentContainer {
width:100%;
display: block;
}
.contentText {
font-family: "Helvetica Neue";
font-size: 14px;
text-align: left;
font-weight: 200;
display: block;
overflow: hidden;
}
.image {
float: left;
display: block;
background-color: #ff0000;
margin-right: 15px;
width: 90px;
height: 80px;
}
I've tried a couple of different techniques to no avail. Ideally it looks something like this:
http://jsfiddle.net/cSazm/5/, but within the div container. Something like:
[Title]
[Image, if one exists] [Content]
[Divider]
Here's a screenshot of how this is rendered:
Any suggestions? I don't have much experience with frontend work (which is probably apparent)
Is this what you are looking for?
.content {
width: 100%;
}
.image {
float: left;
padding-right: 5px;
}
.entryDivider {
margin-top: 10px;
size: 1px;
width: 66%;
}
http://jsfiddle.net/XZ2Ax/
Just put everything in a div above the divider.
In your containing div (in this case .entry), you can clear it:
.entry {
width: 66%;
margin-top: 30px;
margin-bottom: 10px;
clear: both;
}
However, I recommend using something known as a clearfix:
.entry::after {
content: '';
display: table;
clear: both;
}
This way, anything after the .entry will be cleared automatically.
As a side note, I recommend removing the hr elements and using border-bottom on the .entry.
See jsFiddle.
Is this what you are looking to do? JSFiddle
div{
display: block;
width: 100%;
overflow: hidden;
padding:10px 10px 0;
}
h2 {
font-weight: bold;
font-size: 20px;
margin-bottom: 5px;
}
img{
float:left;
margin-right: 10px;
vertical-align:top;
}
p{
display: block;
overflow: hidden;
}
div hr {
clear: both;
border: none;
padding-top: 5px;
margin:0;
border-bottom: 1px solid #ccc;
}
after floated elements you should have a clearing element so that the floats dont "mix"
CSS
.clearfix {
clear:both;
height:0px;
}
HTML
<div>
<img src="http://lorempixel.com/g/80/80/" />
<p>
Lorem ipsum dolor sit amet,
</p>
</div>
<br class="clearfix" />
<div>
<img src="http://lorempixel.com/g/80/80/" />
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
</p>
</div>
JSFiddle