I'm trying to achieve a layout similar to this:
Where:
Each content block has multiple elements inside of it
Content blocks and sidebar height is variable
Not using javascript
The closest I've got is this (but notice how the articles before the sidebar ends occupy much more space than desired, and buttons in the 3rd article occupy 100% of the page while the rest of the article's content occupy less):
.page {
width: 1000px;
margin: auto;
}
.sidebar {
float: right;
width: 300px;
height: 410px;
background: red;
}
.content {
padding-right: 20px;
}
article {
background: #cdcdcd;
padding: 15px;
margin-bottom: 20px;
h3 { margin: 0; }
}
.buttons {
display: flex;
justify-content: space-between;
}
<div class="page">
<div class="sidebar"></div>
<div class="content">
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
</div>
</div>
Please let me know if I'm not being clear.
You need to define width for first 3 article divs.
.page {
width: 1000px;
margin: auto;
}
.sidebar {
float: right;
width: 300px;
height: 527px;
background: red;
}
.content {
padding-right: 20px;
}
article {
background: #cdcdcd;
padding: 15px;
margin-bottom: 20px;
h3 { margin: 0; }
}
.buttons {
display: flex;
justify-content: space-between;
}
.small-box-content{
width: 67%;
display: inline-block;
}
<div class="page">
<div class="sidebar"></div>
<div class="content">
<article class="small-box-content">
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article class="small-box-content">
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article class="small-box-content">
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
</div>
</div>
please let me know this is what you want Just added new div class for three article .side_left
.page {
width: 1000px;
margin: auto;
}
.side_left{
width:650px;
}
.sidebar {
float: right;
width: 300px;
height: 420px;
margin-top:20px;
background: red;
}
.content {
padding-right: 20px;
}
article {
background: #cdcdcd;
padding: 15px;
width:100%;
margin-bottom: 20px;
}
h3 { margin: 0; }
.buttons {
display: flex;
justify-content: space-between;
}
<div class="page">
<div class="sidebar"></div>
<div class="content">
<div class="side_left">
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
</div>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
<article>
<h3>Lorem, ipsum dolor.</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos non nostrum distinctio officia aliquid maxime doloremque harum id consequuntur quo.</p>
<div class="buttons">
<button>btn1</button>
<button>btn2</button>
</div>
</article>
</div>
</div>
Related
This question already has answers here:
How can you set the height of an outer div to always be equal to a particular inner div?
(2 answers)
Closed 4 months ago.
I have align-items: stretch flexbox and inside this flexbox I have image and some text content.
text content is static and I need height of img to be as same as height of text content.
When I use different imgs with different aspect ratio I see different height on each img but I want the height of all images to be same.
*Please test snippet in fullscreen mode to see the problem
.card {
display: flex;
flex-direction: row;
align-items: stretch;
box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.1);
margin: 20px;
}
.title {
align-items: center;
display: flex;
flex-wrap: wrap;
font-size: 1.25rem;
font-weight: 700;
letter-spacing: 0.0125em;
line-height: 1.93rem;
word-break: break-all;
}
.title img {
object-fit: cover;
width: 150px;
height: 100%;
}
<div class="card">
<div class="title">
<img
src="https://s3-alpha-sig.figma.com/img/b579/835c/2b73668d5d42b127f5ed4e206c9c6576?Expires=1668384000&Signature=DoZ8O~AWDj6UhiZgP-5njh0zCqIk0ahZTAqvBVDjvyibc0seggNTv9lBjN-Xhkr6g0oiPnKyfGrqyhzfuPYN-S0T132EdQjEp1LH8FpNHmgBm1SyYVoxMQhnyCcsAF762M6~7lQ5SBqsujpbdmxwee6MChnRRrp706gkHXUYml3Mjd3kR7EsqViVjm39GTyW9DEPIer-qFBTQkILSGrkKjM-9zTitycyzO6c9no0PpclhAqpeeta0sz1JxmsSz7tVHQI9CoDLXWc0epbY7zcnhPqOKYqGkGf2~IS0S46x01CSvTDYIWj0dTt-vma4nOavEWShJhKBXwyjyk5VbQoHQ__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
alt="alt"
/>
</div>
<div class="content">
<p class="text-caption grey3--text">2day ago</p>
<p class="text-subtitle-1 grey5--text font-weight-medium">some title</p>
<p class="ellipsis">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id beatae
quia fugiat, minima eos fuga amet tenetur neque officia optio nulla
voluptatem ducimus dolores, cum animi tempore veritatis libero
repellat. Lorem ipsum dolor sit amet consectetur adipisicing elit. Id
beatae quia fugiat, minima eos fuga amet tenetur neque officia optio
</p>
</div>
</div>
<div class="card">
<div class="title">
<img
src="https://s3-alpha-sig.figma.com/img/bb5a/75f4/c083c0a5a79974bd94152c99b0f0d213?Expires=1668384000&Signature=Um5O0ddvXIROx5txgjSCEF1HcQVv2n6PVHdV81zu1KfaqIZUQw3qZDDgdBAjpnSPJ35-taxYHPLFlhV~tIPoxtJMlXFbJpihC6XIKaiyBUyuXJEicoLCm9fKm5UwbbFLJRU63MSHEDJWVYh8sTxAFaAEwNX~XoVgkfgN0c6ozOdImLOc0G8Hs3WYnDiURZ8jglC25XJRb9uPj7hiiL6tdCOWinA2F9uyLGtSxKHi~RU6ESMKgWOGpavQdeJ5M~iIRpkge2Ka2ySerfZh4184XLTxO8EUG-cin-lW7ncGcjiqLtDIXyt2PyQptpTIENAPMH7dSn1TvvpzjFbadavvnQ__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
alt="alt"
/>
</div>
<div class="content">
<p class="text-caption grey3--text">2day ago</p>
<p class="text-subtitle-1 grey5--text font-weight-medium">some title</p>
<p class="ellipsis">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id beatae
quia fugiat, minima eos fuga amet tenetur neque officia optio nulla
voluptatem ducimus dolores, cum animi tempore veritatis libero
repellat. Lorem ipsum dolor sit amet consectetur adipisicing elit. Id
beatae quia fugiat, minima eos fuga amet tenetur neque officia optio
</p>
</div>
</div>
if your text is going to contain the same line heights, you can use em measurements, 1em being 1 line of rem text size, if you plan on having different text contentss and line heights per span, you could also do this by having a class for each image, and then changing the height through those rather than a universal img tag, meaning you can change settings per image, rather than universally in your container.
.card {
display: flex;
flex-direction: row;
align-items: stretch;
box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.1);
margin: 20px;
}
.title {
align-items: center;
display: flex;
flex-wrap: wrap;
font-size: 1.25rem;
font-weight: 700;
letter-spacing: 0.0125em;
line-height: 1.93rem;
word-break: break-all;
}
.title > img {
object-fit: cover;
width: 150px;
height: 7.25em;
}
<div class="card">
<div class="title">
<img
src="https://s3-alpha-sig.figma.com/img/b579/835c/2b73668d5d42b127f5ed4e206c9c6576?Expires=1668384000&Signature=DoZ8O~AWDj6UhiZgP-5njh0zCqIk0ahZTAqvBVDjvyibc0seggNTv9lBjN-Xhkr6g0oiPnKyfGrqyhzfuPYN-S0T132EdQjEp1LH8FpNHmgBm1SyYVoxMQhnyCcsAF762M6~7lQ5SBqsujpbdmxwee6MChnRRrp706gkHXUYml3Mjd3kR7EsqViVjm39GTyW9DEPIer-qFBTQkILSGrkKjM-9zTitycyzO6c9no0PpclhAqpeeta0sz1JxmsSz7tVHQI9CoDLXWc0epbY7zcnhPqOKYqGkGf2~IS0S46x01CSvTDYIWj0dTt-vma4nOavEWShJhKBXwyjyk5VbQoHQ__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
alt="alt"
/>
</div>
<div class="content">
<p class="text-caption grey3--text">2day ago</p>
<p class="text-subtitle-1 grey5--text font-weight-medium">some title</p>
<p class="ellipsis">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id beatae
quia fugiat, minima eos fuga amet tenetur neque officia optio nulla
voluptatem ducimus dolores, cum animi tempore veritatis libero
repellat. Lorem ipsum dolor sit amet consectetur adipisicing elit. Id
beatae quia fugiat, minima eos fuga amet tenetur neque officia optio
</p>
</div>
</div>
<div class="card">
<div class="title">
<img
src="https://s3-alpha-sig.figma.com/img/bb5a/75f4/c083c0a5a79974bd94152c99b0f0d213?Expires=1668384000&Signature=Um5O0ddvXIROx5txgjSCEF1HcQVv2n6PVHdV81zu1KfaqIZUQw3qZDDgdBAjpnSPJ35-taxYHPLFlhV~tIPoxtJMlXFbJpihC6XIKaiyBUyuXJEicoLCm9fKm5UwbbFLJRU63MSHEDJWVYh8sTxAFaAEwNX~XoVgkfgN0c6ozOdImLOc0G8Hs3WYnDiURZ8jglC25XJRb9uPj7hiiL6tdCOWinA2F9uyLGtSxKHi~RU6ESMKgWOGpavQdeJ5M~iIRpkge2Ka2ySerfZh4184XLTxO8EUG-cin-lW7ncGcjiqLtDIXyt2PyQptpTIENAPMH7dSn1TvvpzjFbadavvnQ__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
alt="alt"
/>
</div>
<div class="content">
<p class="text-caption grey3--text">2day ago</p>
<p class="text-subtitle-1 grey5--text font-weight-medium">some title</p>
<p class="ellipsis">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id beatae
quia fugiat, minima eos fuga amet tenetur neque officia optio nulla
voluptatem ducimus dolores, cum animi tempore veritatis libero
repellat. Lorem ipsum dolor sit amet consectetur adipisicing elit. Id
beatae quia fugiat, minima eos fuga amet tenetur neque officia optio
</p>
</div>
</div>
You have to give height and width to the parent of img.
I have created a snippet for this.
.card {
display: flex;
flex-direction: row;
align-items: stretch;
box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.1);
margin: 20px;
}
.title {
width: 150px
}
.content{
width: calc(100% - 150px)
}
.title img {
object-fit: cover;
object-position: center;
width: 100%;
height: 100%;
}
<div class="card">
<div class="title">
<img src="https://s3-alpha-sig.figma.com/img/b579/835c/2b73668d5d42b127f5ed4e206c9c6576?Expires=1668384000&Signature=DoZ8O~AWDj6UhiZgP-5njh0zCqIk0ahZTAqvBVDjvyibc0seggNTv9lBjN-Xhkr6g0oiPnKyfGrqyhzfuPYN-S0T132EdQjEp1LH8FpNHmgBm1SyYVoxMQhnyCcsAF762M6~7lQ5SBqsujpbdmxwee6MChnRRrp706gkHXUYml3Mjd3kR7EsqViVjm39GTyW9DEPIer-qFBTQkILSGrkKjM-9zTitycyzO6c9no0PpclhAqpeeta0sz1JxmsSz7tVHQI9CoDLXWc0epbY7zcnhPqOKYqGkGf2~IS0S46x01CSvTDYIWj0dTt-vma4nOavEWShJhKBXwyjyk5VbQoHQ__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
alt="alt" />
</div>
<div class="content">
<p class="text-caption grey3--text">2day ago</p>
<p class="text-subtitle-1 grey5--text font-weight-medium">some title</p>
<p class="ellipsis">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id beatae quia fugiat, minima eos fuga amet tenetur neque officia optio nulla voluptatem ducimus dolores, cum animi tempore veritatis libero repellat. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Id beatae quia fugiat, minima eos fuga amet tenetur neque officia optio
</p>
</div>
</div>
<div class="card">
<div class="title">
<img src="https://s3-alpha-sig.figma.com/img/bb5a/75f4/c083c0a5a79974bd94152c99b0f0d213?Expires=1668384000&Signature=Um5O0ddvXIROx5txgjSCEF1HcQVv2n6PVHdV81zu1KfaqIZUQw3qZDDgdBAjpnSPJ35-taxYHPLFlhV~tIPoxtJMlXFbJpihC6XIKaiyBUyuXJEicoLCm9fKm5UwbbFLJRU63MSHEDJWVYh8sTxAFaAEwNX~XoVgkfgN0c6ozOdImLOc0G8Hs3WYnDiURZ8jglC25XJRb9uPj7hiiL6tdCOWinA2F9uyLGtSxKHi~RU6ESMKgWOGpavQdeJ5M~iIRpkge2Ka2ySerfZh4184XLTxO8EUG-cin-lW7ncGcjiqLtDIXyt2PyQptpTIENAPMH7dSn1TvvpzjFbadavvnQ__&Key-Pair-Id=APKAINTVSUGEWH5XD5UA"
alt="alt" />
</div>
<div class="content">
<p class="text-caption grey3--text">2day ago</p>
<p class="text-subtitle-1 grey5--text font-weight-medium">some title</p>
<p class="ellipsis">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id beatae quia fugiat, minima eos fuga amet tenetur neque officia optio nulla voluptatem ducimus dolores, cum animi tempore veritatis libero repellat. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Id beatae quia fugiat, minima eos fuga amet tenetur neque officia optio
</p>
</div>
</div>
This question already has answers here:
CSS-only masonry layout
(4 answers)
Closed 8 months ago.
I want to move element to up like in photo in attachment. which code I should write to my css ?
here is photo of my code
*{box-sizing: border-box;}
body{
height: 100vh;
width: 100vw;
font-family: sans-serif;
}
h2{padding: 5px;}
p{padding: 5px;}
.container{
display: flex;
width: 1200px;
margin: 50px auto;
flex-wrap: wrap;
align-items: flex-start;
justify-content: space-around;
background-color: aquamarine;
}
.container__item{
width: 350px;
/* height: 100%; */
background-color: #fff;
}
[class*="image"]{
width: 350px;
background-color: rgb(200, 200, 200);
color: gray;
font-size: 2rem;
display: flex;
justify-content: center;
align-items: center;
}
[class$="150"]{height: 150px;}
[class$="100"]{height: 100px;}
[class$="350"]{height: 350px;}
[class$="220"]{height: 220px;}
[class$="230"]{height: 230px;}
<div class="container">
<div class="container__item">
<div class="container__item-image 350x150">350x150</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x100">350x100</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x100">350x100</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x220">350x220</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x230">350x230</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x350">350x350</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x100">350x100</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x150">350x150</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x150">350x150</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
</div>
I already tried justify-content: flex-start; and align-items: flex-start; but they didn't help for this example. Maybe I have another problem ? I can't solve it. I try to solve it about two days :D I can't find answer for this. Please somebody help to solve this exercise.
Check this. You can use display:grid to check it out.
*{box-sizing: border-box;}
body{
height: 100vh;
width: 100vw;
font-family: sans-serif;
}
h2{padding: 5px;}
p{padding: 5px;}
.container{
width: 1200px;
margin: 50px auto;
column-count: 4;
column-gap: 5px;
}
.container__item{
margin: 0;
display: grid;
grid-template-rows: 1fr auto;
margin-bottom: 0px;
break-inside: avoid;
}
[class*="image"]{
width: 100%;
background-color: rgb(200, 200, 200);
color: gray;
font-size: 2rem;
display: flex;
justify-content: center;
align-items: center;
}
[class$="150"]{height: 150px;}
[class$="100"]{height: 100px;}
[class$="350"]{height: 350px;}
[class$="220"]{height: 220px;}
[class$="230"]{height: 230px;}
<div class="container">
<div class="container__item">
<div class="container__item-image 350x150">350x150</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x100">350x100</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x100">350x100</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x220">350x220</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x230">350x230</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x350">350x350</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x100">350x100</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x150">350x150</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
<div class="container__item">
<div class="container__item-image 350x150">350x150</div>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque accusamus impedit recusandae enim maxime, animi at hic aliquam quod fugiat.</p>
</div>
</div>
I tried to display information in form of cards. Each cards is inside ordered list li. On adding more card in form of li, the content goes out of page from top. How can I set the height to adjust automatically according to the number of cards.
Html code
<body>
<section>
<div class="leftBox">
<div class="content">
<h1>Events</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vitae quia atque cupiditate commodi
nihil
cum? Autem rem voluptates aperiam. Est non dolor, unde quam laborum eveniet quidem doloribus
iure
ad!
</p>
</div>
</div>
<div class="events">
<ul>
<li>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere
deleniti corporis deserunt doloribus maxime.
</p>
View Details
</div>
<div style="clear: both;"></div>
</li>
<li>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere
deleniti corporis deserunt doloribus maxime.
</p>
View Details
</div>
<div style="clear: both;"></div>
</li>
</ul>
</div>
</section>
</body>
Corresponding CSS
body{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
section{
width: 100%;
height: 100vh;
background: #323a45;
background-size: cover;
}
``
Can you please check the below code? Hope it will work for you. We have used display flex property to create cards element, it seems like you have used float element because of float it creates height alignment issue. We provide you two alignment structure so you can use any of according to your convenience.
Please refer to this link: https://jsfiddle.net/yudizsolutions/1vLqr6uo/2/
body {
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
section {
width: 100%;
height: 100vh;
/* background: #323a45;*/
background-size: cover;
}
ul {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
ul li {
width: 33.33%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.events.copy ul li {
display: block;
}
<body>
<section>
<div class="leftBox">
<div class="content">
<h1>Events</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vitae quia atque cupiditate commodi nihil cum? Autem rem voluptates aperiam. Est non dolor, unde quam laborum eveniet quidem doloribus iure ad!
</p>
</div>
</div>
<div class="events">
<ul>
<li>
<div>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime.
</p>
</div>
</div>
View Details
</li>
<li>
<div>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime.
</p>
</div>
</div>
View Details
</li>
<li>
<div>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus
maxime.Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime.
</p>
</div>
</div>
View Details
</li>
</ul>
</div>
<div class="events copy">
<ul>
<li>
<div>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime.
</p>
</div>
</div>
View Details
</li>
<li>
<div>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime.
</p>
</div>
</div>
View Details
</li>
<li>
<div>
<div class="time">
<h2>2<br><span>April</span></h2>
</div>
<div class="details">
<h3>Celestial</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus
maxime.Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore nam veritatis facere deleniti corporis deserunt doloribus maxime.
</p>
</div>
</div>
View Details
</li>
</ul>
</div>
</section>
</body>
This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 3 years ago.
The 4 divs have a width of 23% and are displayed inline-block, they have a height of 220px and margin 0. The issue is that they are not horizontally aligned
I tried to change the height and width already and removed the margin but that does not fix it.
It looks like this...
.aside-column {
width: 23%;
display: inline-block;
height: 220px;
margin: 0;
}
<div class="aside-column aside-column1">
<h4>Lufthansa vs Airbus</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam, exercitationem nulla? Ea rerum necessitatibus ratione optio iure. Aliquid?</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column2">
<h4>Bill Gates History</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero in labore assumenda tempora nostrum nisi possimus saepe dolor incidunt voluptatem, iure cum atque!</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column3">
<h4>Tescos Stabbing</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sed quis quaerat quo reprehenderit?</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column4">
<h4>Amazon Forest Fire</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Pariatur aliquid sint tenetur.</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
Give vertical-align:top; to .aside-column class.
.aside-column {
width: 23%;
display: inline-block;
height: 220px;
margin: 0;
vertical-align:top;
}
<div class="aside-column aside-column1">
<h4>Lufthansa vs Airbus</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam, exercitationem nulla? Ea rerum necessitatibus ratione optio iure. Aliquid?</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column2">
<h4>Bill Gates History</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero in labore assumenda tempora nostrum nisi possimus saepe dolor incidunt voluptatem, iure cum atque!</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column3">
<h4>Tescos Stabbing</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sed quis quaerat quo reprehenderit?</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column4">
<h4>Amazon Forest Fire</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Pariatur aliquid sint tenetur.</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
You can also use a parent container which is a flexbox.
.container {
display: flex;
}
.aside-column {
width: 23%;
height: 220px;
margin: 1%;
}
<div class="container">
<div class="aside-column aside-column1">
<h4>Lufthansa vs Airbus</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam, exercitationem nulla? Ea rerum necessitatibus ratione optio iure. Aliquid?</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column2">
<h4>Bill Gates History</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero in labore assumenda tempora nostrum nisi possimus saepe dolor incidunt voluptatem, iure cum atque!</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column3">
<h4>Tescos Stabbing</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sed quis quaerat quo reprehenderit?</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
<div class="aside-column aside-column4">
<h4>Amazon Forest Fire</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Pariatur aliquid sint tenetur.</p>
<div class="aside-readMore">
Continue Reading
</div>
</div>
</div>
I am trying to get this red line exactly between the columns, precisely to make it stand between Lorem ipsum's and paragraphs. The problem is that it should be one long line that goes through the page, but this one breaks because of the new row. Is there a better way to do it maybe..?
Here's the current state: http://codepen.io/anon/pen/WReerM
.content--border {
border-right: 2px solid red;
}
<div class="container content">
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum</p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor!</p>
</div>
</div>
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum 2</p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor! Lorem ipsum dolor sit
amet, consectetur adipisicing elit. A asperiores, quisquam illo animi eaque repudiandae excepturi tenetur, vel laudantium quas corporis explicabo laborum non minus dolor temporibus nesciunt vero. Id!
</p>
</div>
</div>
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum 3</p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor!</p>
</div>
</div>
</div>
The easiest way is to move content--border class to col-md-7 instead of col-md-3.
You can move the border to the left edge of col-md-7 instead.
.content--border {
border-left: 2px solid red;
}
Also can put it in a media query so it disappears on smaller screens:
#media screen and (min-width: 992px) {
.content--border {
border-left: 2px solid red;
}
}
Demo here
Move the border to the left of your other column:
.content--border {
border-left: 2px solid red;
}
see my working codepen:
http://codepen.io/egerrard/pen/pRzzRx
HTML:
<div class="container content">
<div class="row">
<div class="col-md-3">
<p>Lorem ipsum</p>
</div>
<div class="col-md-7 content--border">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor!</p>
</div>
</div>
<div class="row">
<div class="col-md-3 ">
<p>Lorem ipsum 2</p>
</div>
<div class="col-md-7 content--border">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor! Lorem ipsum dolor sit
amet, consectetur adipisicing elit. A asperiores, quisquam illo animi eaque repudiandae excepturi tenetur, vel laudantium quas corporis explicabo laborum non minus dolor temporibus nesciunt vero. Id!
</p>
</div>
</div>
<div class="row">
<div class="col-md-3">
<p>Lorem ipsum 3</p>
</div>
<div class="col-md-7 content--border">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor!</p>
</div>
</div>
</div>
CSS:
.content--border {
border-left: 2px solid red;
}
You can use :before pseudo element of parent element (.container) to draw this line. This will allow to have straight line without any breaks irrespective of content length in both columns.
Note: Please see the demo in full page mode.
Necessary CSS:
.container {
position: relative;
}
#media (min-width: 992px) {
.container:before {
position: absolute;
margin-left: -2px;
background: red;
display: block;
content: '';
width: 2px;
bottom: 0;
left: 25%;
top: 0;
}
}
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css");
.container {
position: relative;
}
#media (min-width: 992px) {
.container:before {
position: absolute;
margin-left: -2px;
background: red;
display: block;
content: '';
width: 2px;
bottom: 0;
left: 25%;
top: 0;
}
}
<div class="container content">
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum</p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor!</p>
</div>
</div>
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum 2</p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor! Lorem ipsum dolor sit
amet, consectetur adipisicing elit. A asperiores, quisquam illo animi eaque repudiandae excepturi tenetur, vel laudantium quas corporis explicabo laborum non minus dolor temporibus nesciunt vero. Id!
</p>
</div>
</div>
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum 3</p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis facere assumenda magni dolor velit ullam deleniti tempora! Officia quo laboriosam dicta, animi ipsam expedita quasi magnam velit eligendi similique, dolor!</p>
</div>
<div class="row">
<div class="col-md-3 content--border">
<p>Lorem ipsum 3 Lorem ipsum 3 Lorem ipsum 3 Lorem ipsum 3 </p>
</div>
<div class="col-md-7">
<p>Lorem ipsum dolor sit amet,</p>
</div>
</div>
</div>
it would be easier to make a div element and place it between them with absolute positioning, give the div a height and manipulate using its margin or the top left property and position it where you want, also encase it all in a div...