In the below code, I want all the three boxes to have same height and also the links in the three boxes should be in same line as shown in the screenshot below. I have used flexbox for doing this. Please help.
.wrapper {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: stretch;
padding-top: 35px;
padding-bottom: 35px;
background-color: pink;
}
.wrapper div:not(:last-child) {
border-right: 1px solid #fdfdfd;
}
.wrapper div {
flex-basis: 33%;
text-align: center;
padding: 10px 4%;
}
<div class="wrapper">
<div>
<span>Heading1</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent erat ex, scelerisque sed pellentesque ut, egestas eget velit. Vestibulum sodales finibus faucibus. </p>
Link1
</div>
<div>
<span>Heading2</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent erat ex, sceleriit. Vestibulum sodales finibus fausque.sit amet, consectetur adipiscin </p>
Link2
</div>
<div>
<span>Heading3</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing . esent erat ex, sceler erat ex, sciit. Vestileriibulum sodales finibus fausque sed pellentesque ut, egestas eget velit. Vestibulum sodales finibus faucibus. </p>
Link3
</div>
</div>
Remove align-items: flex-start; from the wrapper, give the div display: flex; flex-direction: column;, and set margin-top: auto on the links
.wrapper {
display: flex;
flex-direction: row;
justify-content: space-between;
padding-top: 35px;
padding-bottom: 35px;
background-color: pink;
}
.wrapper div:not(:last-child) {
border-right: 1px solid #fdfdfd;
}
.wrapper div {
flex-basis: 33%;
text-align: center;
padding: 10px 4%;
display: flex; /* added property */
flex-direction: column; /* added property */
}
.wrapper div a { /* added rule */
margin-top: auto;
}
<div class="wrapper">
<div>
<span>Heading1</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent erat ex, scelerisque sed pellentesque ut, egestas eget velit. Vestibulum sodales finibus faucibus. </p>
Link1
</div>
<div>
<span>Heading2</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent erat ex, sceleriit. Vestibulum sodales finibus fausque.sit amet, consectetur adipiscin </p>
Link2
</div>
<div>
<span>Heading3</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing . esent erat ex, sceler erat ex, sciit. Vestileriibulum sodales finibus fausque sed pellentesque ut, egestas eget velit. Vestibulum sodales finibus faucibus. </p>
Link3
</div>
</div>
.wrapper {
display: flex;
flex-direction: row;
justify-content: stretch;
padding-top: 35px;
padding-bottom: 35px;
background-color: pink;
}
.wrapper div:not(:last-child) {
border-right: 1px solid #fdfdfd;
}
.wrapper div {
display: flex;
flex-basis: 33%;
flex-direction: column;
justify-content: space-between;
text-align: center;
padding: 10px 4%;
}
.wrapper div a {
flex-grow: 1;
display: flex;
justify-content: center;
align-items: flex-end;
}
<div class="wrapper">
<div>
<span>Heading1</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent erat ex, scelerisque sed pellentesque ut, egestas eget velit. Vestibulum sodales finibus faucibus. </p>
Link1
</div>
<div>
<span>Heading2</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent erat ex, sceleriit. Vestibulum sodales finibus fausque.sit amet, consectetur adipiscin </p>
Link2
</div>
<div>
<span>Heading3</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing . esent erat ex, sceler erat ex, sciit. Vestileriibulum sodales finibus fausque sed pellentesque ut, egestas eget velit. Vestibulum sodales finibus faucibus. </p>
Link3
</div>
</div>
Related
I have try to set using flex. please check my demo my code
its possible using flote but my required using flex.
I set it up using Flex but I not found success in it. You help me...
my code
.cg-box-layout-two{display: -ms-flexbox;display: flex;-ms-flex-wrap: wrap;flex-wrap: wrap;align-items: stretch;position: relative;}
.cg-box-layout-two .cg-box-name{flex: 0 0 100%;max-width: 100%;}
.cg-box-layout-two .cg-layout-img{flex: 0 0 36%;max-width:36%;box-sizing: border-box;border-radius: 6px;overflow: hidden;box-shadow:0 0px 10px rgba(0,0,0,0.2);position: relative;}
.cg-box-layout-two .cg-layout-img .cg-our-top-pick{position: absolute;background-color: #77b21d;color: #fff;font-size: 12px;font-weight: 700;text-transform: uppercase;padding: 4px 0px;transform: rotate(45deg);right: -68px;top: -23px;transform-origin: 0 0;width: 153px;box-sizing: border-box;text-align: center;white-space: nowrap;overflow: hidden;box-shadow: 1px 2px 7px rgba(0,0,0,0.2);}
.cg-box-layout-two .cg-layout-img .cg-li-photo{max-height:220px;padding: 32px 4px 16px;box-sizing: border-box;}
.cg-box-layout-two .cg-layout-content{flex: 0 0 calc(64% - 15px);max-width:calc(64% - 15px);box-sizing: border-box;padding:16px;position: relative;box-shadow:0px 0px 6px rgba(0,0,0,0.1);border-radius: 6px;overflow: hidden;margin-left: 15px;}
.cg-box-layout-two .cg-layout-img .cg-li-photo img{max-width: 100%;
display: block;
margin: 0 auto;
max-height: 180px;}
.cg-rate{position: relative;font-size: 20px;color: #0d3153;font-weight: bold;line-height: 20px;text-align: center;display: inline-block;padding: 0 15px;min-width: 100px;}
.cg-rate>span{font-size: 14px;display: block;line-height: 14px;}
.cg-rate:before,
.cg-rate:after{content: "";position: absolute;left: 0px;height: 31px;width: 15px;background-size: 100%;background-repeat: no-repeat;background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAfCAMAAAAP3mfjAAAAb1BMVEUAAAANMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVN1VGFuAAAAJHRSTlMA82fJ6LAjEgaim3U93YpINs24V00N4tS9kX9vYFMrHxqolkKuk4aZAAAA40lEQVQY002PiRKDIAxEEw5F8b5q1dYe+//fWBgRmxkGHskmGwqRVq2/Ipbg8z26YwF5ci5fpIH6ZInS6LmI2hl4UCG+JrAA1g7+M0QF6bA7oFh2arJy+oyxeiOq77kJeYDTO1Be47AAsNFqBgX48mi4KR66CpDJfKceyAO7Vuo1ASJwwi4H3JJT3UhwWa18LWQM1ZcgHbbE77+dAwCsM3iwoaGCa8e94vT4eHaqXVIL9PQXH0BkY5BUbyHAFvoQ8NHhDTzJh3Wsaj9pCAIxGPKmdoq2u0m3OuKX4Re90i0gE6If9SsTmsaqO/oAAAAASUVORK5CYII=');}
.cg-rate:after{left: auto;right: 0px;top: 0;transform: rotateY(180deg);}
.cg-box-layout-two .cg-layout-img .cg-li-ratebadge,
.cg-box-layout-one .cg-layout-img .cg-li-ratebadge{margin:12px auto;text-align: center;}
<div class="cg-box-layout-two cg-red">
<div class="cg-layout-img">
<div class="cg-our-top-pick">Our Top Pick</div>
<div class="cg-li-photo">
<a href="https://www.amazon.com/dp/B01AZC3I6U/?tag=10b-gm-20" target="_blank" rel="nofollow" class="cg-aff-link ">
<img src="https://m.media-amazon.com/images/I/41h0H4SCgPL.jpg" class="cg-img-1" alt="Best Projector Under $200">
</a> </div>
<div class="cg-li-ratebadge"><div class="cg-rate"><span>7.8/10</span> <span>Our Score</span></div></div>
</div>
<div class="cg-layout-content">
<div class="cg-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p> </div>
<div class="cg-lc-button">
Check Price
</div>
</div>
</div>
There are a few things I modified.
I used two flex boxes, the first one has a direction of column, which contains tow vertical objects. the second one has a direction of row, which contains two horizontal objects. the image and the upper box are grouped into the second flex box since they have to show at the same row. the first flex box wraps everything.
I assigned a fixed height of the image box, 290px, since I've used JS to rearrange layout meanwhile detecting overflow occasions.
const upperText = document.querySelector('.cg-layout-content');
const lowerText = document.querySelector('.cg-layout-below');
function paragraphAppender(...sentences){
let flag = false;
for(let i = 0; i < sentences.length; i++){
let pNode = document.createTextNode(sentences[i]);
if(flag){
lowerText.appendChild(pNode);
}else{
let beforeAdd = 290;
upperText.appendChild(pNode);
if(upperText.getBoundingClientRect().height > beforeAdd){
flag = true;
upperText.removeChild(pNode);
}
}
}
}
let exp = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. ';
paragraphAppender(exp, exp, exp, exp);
.flex-row{
display: flex;
flex-direction: row;
margin-top: 2vmin;
}
.flex-column{
display: flex;
flex-direction: column;
}
.cg-box-layout-two{
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
align-items: stretch;
position: relative;
}
.cg-box-layout-two .cg-box-name{
flex: 0 0 100%;
max-width: 100%;
}
.cg-box-layout-two .cg-layout-img{
flex: 0 0 36%;
max-width:36%;
box-sizing: border-box;
border-radius: 6px;
overflow: hidden;
box-shadow:0 0px 10px rgba(0,0,0,0.2);
position: relative;
}
.cg-box-layout-two .cg-layout-img .cg-our-top-pick{
position: absolute;
background-color: #77b21d;
color: #fff;
font-size: 12px;
font-weight: 700;
text-transform: uppercase;
padding: 4px 0px;
transform: rotate(45deg);
right: -68px;
top: -23px;
transform-origin: 0 0;
width: 153px;
box-sizing: border-box;
text-align: center;
white-space: nowrap;
overflow: hidden;
box-shadow: 1px 2px 7px rgba(0,0,0,0.2);
}
.cg-box-layout-two .cg-layout-img .cg-li-photo{
max-height:220px;
padding: 32px 4px 16px;
box-sizing: border-box;
}
.cg-box-layout-two .cg-layout-content{
flex: 0 0 calc(64% - 15px);
max-width:calc(64% - 15px);
box-sizing: border-box;
padding:16px;
position: relative;
box-shadow:0px 0px 6px rgba(0,0,0,0.1);
border-radius: 6px;
overflow: hidden;
margin-left: 15px;
}
.cg-layout-below{
box-sizing: border-box;
padding:16px;
position: relative;
box-shadow:0px 0px 6px rgba(0,0,0,0.1);
border-radius: 6px;
overflow: hidden;
}
.cg-box-layout-two .cg-layout-img .cg-li-photo img{
max-width: 100%;
display: block;
margin: 0 auto;
max-height: 180px;
}
.cg-rate{
position: relative;
font-size: 20px;
color: #0d3153;
font-weight: bold;
line-height: 20px;
text-align: center;
display: inline-block;
padding: 0 15px;
min-width: 100px;
}
.cg-rate>span{
font-size: 14px;
display: block;
line-height: 14px;
}
.cg-rate:before,
.cg-rate:after{
content: "";
position: absolute;
left: 0px;
height: 31px;
width: 15px;
background-size: 100%;
background-repeat: no-repeat;
background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAfCAMAAAAP3mfjAAAAb1BMVEUAAAANMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVMNMVN1VGFuAAAAJHRSTlMA82fJ6LAjEgaim3U93YpINs24V00N4tS9kX9vYFMrHxqolkKuk4aZAAAA40lEQVQY002PiRKDIAxEEw5F8b5q1dYe+//fWBgRmxkGHskmGwqRVq2/Ipbg8z26YwF5ci5fpIH6ZInS6LmI2hl4UCG+JrAA1g7+M0QF6bA7oFh2arJy+oyxeiOq77kJeYDTO1Be47AAsNFqBgX48mi4KR66CpDJfKceyAO7Vuo1ASJwwi4H3JJT3UhwWa18LWQM1ZcgHbbE77+dAwCsM3iwoaGCa8e94vT4eHaqXVIL9PQXH0BkY5BUbyHAFvoQ8NHhDTzJh3Wsaj9pCAIxGPKmdoq2u0m3OuKX4Re90i0gE6If9SsTmsaqO/oAAAAASUVORK5CYII=');
}
.cg-rate:after{
left: auto;
right: 0px;
top: 0;
transform: rotateY(180deg);
}
.cg-box-layout-two .cg-layout-img .cg-li-ratebadge,
.cg-box-layout-one .cg-layout-img .cg-li-ratebadge{
margin:12px auto;
text-align: center;
}
<div class='flex-column'>
<div class="cg-box-layout-two cg-red">
<div class='flex-row'>
<div class="cg-layout-img">
<div class="cg-our-top-pick">Our Top Pick</div>
<div class="cg-li-photo">
<a href="https://www.amazon.com/dp/B01AZC3I6U/?tag=10b-gm-20" target="_blank" rel="nofollow" class="cg-aff-link ">
<img src="https://m.media-amazon.com/images/I/41h0H4SCgPL.jpg" class="cg-img-1" alt="Best Projector Under $200">
</a> </div>
<div class="cg-li-ratebadge"><div class="cg-rate"><span>7.8/10</span> <span>Our Score</span></div></div>
</div>
<div class="cg-layout-content">
<div class="cg-text">
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p> -->
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p> -->
</div>
<div class="cg-lc-button">
Check Price
</div>
</div>
</div>
<div class="cg-layout-below">
<div class="cg-text">
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p> -->
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p> -->
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. </p> -->
</div>
<div class="cg-lc-button">
Check Price
</div>
</div>
</div>
</div>
Here are a few things to notice:
Paragraph contends are directly injected into .cg-layout-content and .cg-layout-below, since .cg-text has no text styling. in addition I don't know how you are going to arrange Check Price.
by using this method, you must make sure there are some context to write in as paragraph, otherwise the layout mess up.
I am making cards using flexbox(https://jsfiddle.net/vs37qo0r/):
/* Only included flex related styles*/
.container {
display: flex;
flex-direction: row;
/*default*/
align-items: stretch;
/*default*/
justify-content: space-around;
}
.card {
flex-basis: 20%;
}
<div class="container">
<div class="card">
<h3>Feature 1</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
<button type="button">Go Somewhere</button>
</div>
<!-- two more cards of same format-->
</div>
Each <h3> and <p> line up with each other. But, not every <p> is the same size, which then throws off where the <button> is layed out. How can I tell all of the <button>s to line up with each other regardless of the size of the <p> above it?
Set .card to display: flex
Enclose h3, p in a wrapper with flex: 1
Set the button to be at flex-end
jfFiddle
body{
background-color: white;
margin-top: 100px;
padding: 0;
}
.container{
display:flex;
flex-direction: row; /*default*/
align-items: stretch; /*default*/
justify-content: space-around;
}
.card{
border: 1px solid grey;
border-radius: 3px;
background-color: white;
flex-basis: 20%;
text-align: center;
padding: 30px;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
}
.card__content {
flex: 1;
}
.button {
align-self: flex-end;
}
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="card">
<div class="card__content">
<h3>Feature 1</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
</div>
<button type="button">Go Somewhere</button>
</div>
<div class="card">
<div class="card__content">
<h3>Feature 2</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum
</p>
</div>
<button type="button">Go Somewhere</button>
</div>
<div class="card">
<div class="card__content">
<h3>Feature 3</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
</div>
<button type="button">Go Somewhere</button>
</div>
</div>
</body>
jsFiddle
There is no need for a wrapper or more than 3 additional properties. Set .card to flex:
.card {
display:flex;
flex-direction: column;
....
}
Set .card p to flex: 1
.card p {
flex: 1;
}
Try making the .card elements flex-parents themselves, then play with the justify-content property.
.card{
…
display: flex;
flex-direction: column;
justify-content: space-between;
}
body {
background-color: white;
margin-top: 100px;
padding: 0;
}
.container {
display: flex;
flex-direction: row;
/*default*/
align-items: stretch;
/*default*/
justify-content: space-around;
}
.card {
border: 1px solid grey;
border-radius: 3px;
background-color: white;
flex-basis: 20%;
text-align: center;
padding: 30px;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
justify-content: space-between;
}
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="card">
<h3>Feature 1</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
<button type="button">Go Somewhere</button>
</div>
<div class="card">
<h3>Feature 2</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum
</p>
<button type="button">Go Somewhere</button>
</div>
<div class="card">
<h3>Feature 3</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
<button type="button">Go Somewhere</button>
</div>
</div>
</body>
I'm working with you jsfiddle version:
there I added these extra code, and you never have to touch your HTML for it!
.card{
...
display: flex;
flex-direction: column;
align-items: center;
}
button {
margin-top: auto !important;
}
and it's working fine!
body {
background-color: white;
margin-top: 100px;
padding: 0;
}
.container {
display: flex;
flex-direction: row;
/* default */
align-items: stretch;
/* default */
justify-content: space-around;
}
.card {
border: 1px solid grey;
border-radius: 3px;
background-color: white;
flex-basis: 20%;
text-align: center;
padding: 30px;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
}
button {
margin-top: auto;
}
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="card">
<h3>Feature 1</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
<button type="button">Go Somewhere</button>
</div>
<div class="card">
<h3>Feature 2</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum
</p>
<button type="button">Go Somewhere</button>
</div>
<div class="card">
<h3>Feature 3</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam finibus arcu est, id mollis ex tincidunt blandit. Morbi dictum dignissim turpis. Ut lacus leo, sagittis at ullamcorper eu, auctor a arcu. Sed non mi sed turpis rhoncus faucibus eu viverra.
</p>
<button type="button">Go Somewhere</button>
</div>
</div>
</body>
You need to add display: flex, flex-dicrection: column and justify-content: space-between.
Your new css .card class looks like:
.card{
flex-basis: 20%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
I hope this will work for you!
I am trying to make a box with a few sections of text. Each section will have a floating label on the left of it. However I have encountered a problem where the end of the text overflows onto the next section.
Is there a way to prevent this?
.punktBox {
width: 550px;
margin-bottom: 15px;
font-size: 1.1em;
display: flex;
flex-wrap: wrap;
}
.punktSection, .punktSectionHalf {
font-size: 1em;
padding: 2px 10px;
min-height: 24px;
display: inline-block;
width: 100%;
flex: 0 1 auto;
}
.punktSecLabel {
float: left;
height: 100%;
min-width: 100px;
font-weight: bold;
}
<div class="punktBox">
<div class="punktSection">
<div class="punktSecLabel">Desc: </div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris venenatis, felis id euismod lacinia, ligula sapien consequat augue, sed volutpat felis ipsum ut ipsum. In hac habitasse platea dictumst. Nunc porttitor nisl a suscipit suscipit.<i> (3 min lub mniej) </i>
</div>
<div class="punktSectionHalf">
<div class="punktSecLabel">Person: </div>John Doe
</div>
<div class="punktSection">
<div class="punktSecLabel">Lorem: </div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
I suggest just use inline-flex and put your content inside a <p> or <div> element otherwise it will break.
.punktBox {
width: 550px;
margin-bottom: 15px;
font-size: 1.1em;
display: flex;
flex-wrap: wrap;
}
.punktSection, .punktSectionHalf {
font-size: 1em;
padding: 2px 10px;
min-height: 24px;
display: inline-flex;
width: 100%;
flex: 0 1 auto;
}
.punktSecLabel {
height: 100%;
min-width: 100px;
font-weight: bold;
}
<div class="punktBox">
<div class="punktSection">
<div class="punktSecLabel">Desc: </div><div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris venenatis, felis id euismod lacinia, ligula sapien consequat augue, sed volutpat felis ipsum ut ipsum. In hac habitasse platea dictumst. Nunc porttitor nisl a suscipit suscipit.<i> (3 min lub mniej) </i></div>
</div>
<div class="punktSectionHalf">
<div class="punktSecLabel">Person: </div><div>John Doe</div>
</div>
<div class="punktSection">
<div class="punktSecLabel">Lorem: </div><div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</div>
</div>
Instead of display: inline-block on your .punktSection and .punktSectionHalf, you're looking for display: inline-flex:
.punktBox {
width: 550px;
margin-bottom: 15px;
font-size: 1.1em;
display: flex;
flex-wrap: wrap;
}
.punktSection, .punktSectionHalf {
font-size: 1em;
padding: 2px 10px;
min-height: 24px;
display: inline-flex;
width: 100%;
flex: 0 1 auto;
}
.punktSecLabel {
float: left;
height: 100%;
min-width: 100px;
font-weight: bold;
}
<div class="punktBox">
<div class="punktSection">
<div class="punktSecLabel">Desc: </div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris venenatis, felis id euismod lacinia, ligula sapien consequat augue, sed volutpat felis ipsum ut ipsum. In hac habitasse platea dictumst. Nunc porttitor nisl a suscipit suscipit.<i> (3 min lub mniej) </i>
</div>
<div class="punktSectionHalf">
<div class="punktSecLabel">Person: </div>John Doe
</div>
<div class="punktSection">
<div class="punktSecLabel">Lorem: </div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
Your problem is that you had a float:left on your punktSecLabel.
Just remote it, and add a display:flex; on your punktSection. Your content must also be wrapped in a bigger div.
Hope it helps !
.punktBox {
width: 550px;
margin-bottom: 15px;
font-size: 1.1em;
display: flex;
flex-wrap: wrap;
}
.punktSection, .punktSectionHalf {
font-size: 1em;
padding: 2px 10px;
min-height: 24px;
display: inline-block;
width: 100%;
flex: 0 1 auto;
display:flex;
}
.punktSecLabel {
height: 100%;
min-width: 100px;
font-weight: bold;
}
<div class="punktBox">
<div class="punktSection">
<div class="punktSecLabel">Desc: </div><div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris venenatis, felis id euismod lacinia, ligula sapien consequat augue, sed volutpat felis ipsum ut ipsum. In hac habitasse platea dictumst. Nunc porttitor nisl a suscipit suscipit.<i> (3 min lub mniej) </i></div>
</div>
<div class="punktSectionHalf">
<div class="punktSecLabel">Person: </div>John Doe
</div>
<div class="punktSection">
<div class="punktSecLabel">Lorem: </div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
I've got div containers that are using flex. I have a bold senescence inside my flex child containers.
example
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at lectus vitae libero pulvinar fringilla. Nullam vel vestibulum orci.
However, when I create my flex container it's not making the bold text inline. It's creating a block between the regular text and the bold text.
example
Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Nunc at lectus vitae libero
pulvinar fringilla. Nullam vel vestibulum orci.
I've set my flex container as follows:
.flexparent { display: flex; flex-direction: row; justifty-content: center; flex-wrap: wrap-reverse }
.flexchild1 { display: inline-flex; flex-direction: column; flex-wrap: nowrap; justify-contetn: center; width: 65%; margin-right: 4%;}
.flexchild2 { display: inline-flex; flex-direction: column; flex-wrap: nowrap; justify-contetn: center; width: 35%;}
My ideal solution is something like this where .flexchild1 is green and .flexchild2 is yellow.
If you're going to use a flex container, keep in mind that all child elements will become flex items and stack vertically or horizontally, depending on flex-direction.
So, if we consider this code:
<div class="flex-container"><b>Lorem ipsum dolor sit amet</b> consectetur adipiscing elit. <span>Nunc at lectus vitae libero</span> pulvinar fringilla. <i>Nullam vel vestibulum orci.</i></div>
Although, the <b>, <span> and <i> elements are inline-level in a block formatting content...
.flex-container {
display: block;
flex-direction: row;
background-color: lightgreen;
}
span { color: red; }
<div class="flex-container"><b>Lorem ipsum dolor sit amet</b> consectetur adipiscing elit. <span>Nunc at lectus vitae libero</span> pulvinar fringilla. <i>Nullam vel vestibulum orci.</i></div>
ALL child elements are blockified in a flex formatting context...
.flex-container1 {
display: flex;
flex-direction: row;
background-color: lightgreen;
}
.flex-container2 {
display: flex;
flex-direction: column;
background-color: lightgreen;
}
span { color: red; }
<div class="flex-container1"><b>Lorem ipsum dolor sit amet</b> consectetur adipiscing elit. <span>Nunc at lectus vitae libero</span> pulvinar fringilla. <i>Nullam vel vestibulum orci.</i></div>
<hr>
<div class="flex-container2"><b>Lorem ipsum dolor sit amet</b> consectetur adipiscing elit. <span>Nunc at lectus vitae libero</span> pulvinar fringilla. <i>Nullam vel vestibulum orci.</i></div>
What you may want to do is wrap your text in its own block-level container within the flex container.
.flex-container1 {
display: flex;
flex-direction: row;
background-color: lightgreen;
}
.flex-container2 {
display: flex;
flex-direction: column;
background-color: lightgreen;
}
span {
color: red;
}
<div class="flex-container1">
<div>
<b>Lorem ipsum dolor sit amet</b> consectetur adipiscing elit. <span>Nunc at lectus vitae libero</span> pulvinar fringilla. <i>Nullam vel vestibulum orci.</i>
</div>
</div>
<hr>
<div class="flex-container2">
<div>
<b>Lorem ipsum dolor sit amet</b> consectetur adipiscing elit. <span>Nunc at lectus vitae libero</span> pulvinar fringilla. <i>Nullam vel vestibulum orci.</i>
</div>
</div>
I want to have two stacked divs on one side, and then have a single column on the other side with the same height as the left divs.
Kind of like this:
I have the two divs and a side bar, but the two divs won't stack.
Here is what I have so far Fiddle
#import url(https://fonts.googleapis.com/css?family=Oxygen);
body {
background-color: #222;
}
.description h1 {
text-align: left;
padding: 20px;
}
#wrapper {
text-align: center;
}
.description,
.sidebar,
.demo-container {
display: inline-block;
vertical-align: top;
}
.description {
background: #eee;
width: 50%;
font-family: "Oxygen";
font-size: 14px;
color: #000;
line-height: 1.2;
}
.sidebar {
background: #eee;
width: 15%;
height: 575px;
}
.demo-container {
background: #eee;
width: 50%;
font-family: "Oxygen";
font-size: 14px;
color: #000;
line-height: 1.2;
}
<div id='wrapper'>
<div class="demo-container">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum.</p>
</div>
<div class="description">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum.</p>
</div>
<div class="sidebar">
</div>
</div>
you are complicating a lot, here is a basic demo of what you want using flexbox
*,
*::before,
*::after {
box-sizing: border-box
}
body {
margin: 0
}
.flex {
display: flex;
flex-basis: 100%
}
.fl {
flex: 1;
display: flex;
flex-direction: column;
margin: 0 5px;
justify-content: space-between
}
.flex-item {
border: 1px solid black
}
.flex-item:not(:first-of-type) {
margin: 10px 0 0
}
.sidebar {
border: 1px solid black;
}
<div class="flex">
<div class="fl">
<div class="flex-item">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum, et aliquam erat feugiat. Duis interdum enim vitae justo cursus pulvinar eu ac nulla. Donec consectetur vehicula turpis. Nunc laoreet tincidunt elit</p>
</div>
<div class="flex-item">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum, et aliquam erat feugiat. Duis interdum enim vitae justo cursus pulvinar eu ac nulla. Donec consectetur vehicula turpis. Nunc laoreet tincidunt elit
ultrices elementum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Curabitur augue magna, posuere id tortor vel, condimentum consectetur lacus. Pellentesque dui est, ornare vitae semper et, dapibus ut lacus.
Etiam sed porta dui. Phasellus non nisl eget dolor commodo imperdiet.</p>
</div>
</div>
<div class="fl sidebar"></div>
</div>
Just put <div class="sidebar"></div> before the other two divs, then float them all right. See fiddle https://jsfiddle.net/y71tkmtw/1/
.description,
.sidebar, .demo-container {
float: right;
margin: 40px;
}
Just add another <div> surrounding the 2 divs on the left-hand side, with float:left. Add float:right to the sidebar.
.left-container
{
width: 85%;
float:left;
}
.sidebar {
background: #eee;
width: 15%;
height: 575px;
float:right;
}
Fiddle: https://jsfiddle.net/dncgytef/2/