I want to align all the list items perfectly but I am not able to do it.
If you see the image since the second li has more text, it is causing them to not align.
I can't use text-overflow on the name of the person, unlike notes.
Margin and padding are also not working.
Please help me how to solve it .
#data-table .list {
display: flex;
align-items: center;
justify-content: space-between;
text-align: center;
color: #97A1A9;
font-size: .9rem;
white-space: nowrap;
}
#data-table .list>* {
padding: 1rem 2rem;
}
#data-table .list div:first-child {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
#data-table .list div:first-child input[type="checkbox"] {
margin-right: 7px;
}
#data-table .list div:last-child {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 221px;
}
<div id="data-table">
<ul>
<li class="list">
<div><input type="checkbox">Customer Name</div>
<div>Seller #</div>
<div>Bill #</div>
<div>Amount</div>
<div>Due Date</div>
<div>Bill Payment Date</div>
<div>Notes</div>
</li>
<!-- Dummy -->
<li class="list">
<div><input type="checkbox">Roshan Ahmad Shaheen</div>
<div>2523532</div>
<div> 73457346735</div>
<div>122.76k</div>
<div>23-Jan-2021</div>
<div> --</div>
<div>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quasi, accusamus?</div>
</li>
<li class="list">
<div><input type="checkbox">Roshan Ahmad</div>
<div>2523532</div>
<div> 73457346735</div>
<div>122.76k</div>
<div>23-Jan-2021</div>
<div> --</div>
<div>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quasi, accusamus?</div>
</li>
There is no way to align flexbox elements on different rows without setting fixed widths. Frankly this is tabular data and so you should be using a table.
Or CSS-Tables
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
::before,
::after {
box-sizing: inherit;
}
#data-table ul {
display: table;
}
#data-table .list {
display: table-row;
text-align: left;
color: #97A1A9;
font-size: .9rem;
white-space: nowrap;
}
#data-table .list>* {
padding: 1rem 2rem;
display: table-cell;
}
#data-table .list div:first-child input[type="checkbox"] {
margin-right: 7px;
}
<div id="data-table">
<ul>
<li class="list">
<div><input type="checkbox">Customer Name</div>
<div>Seller #</div>
<div>Bill #</div>
<div>Amount</div>
<div>Due Date</div>
<div>Bill Payment Date</div>
<div>Notes</div>
</li>
<!-- Dummy -->
<li class="list">
<div><input type="checkbox">Roshan Ahmad Shaheen</div>
<div>2523532</div>
<div> 73457346735</div>
<div>122.76k</div>
<div>23-Jan-2021</div>
<div> --</div>
<div>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quasi, accusamus?</div>
</li>
<li class="list">
<div><input type="checkbox">Roshan Ahmad</div>
<div>2523532</div>
<div> 73457346735</div>
<div>122.76k</div>
<div>23-Jan-2021</div>
<div> --</div>
<div>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quasi, accusamus?</div>
</li>
Related
I am trying to create a scrollable horizontal timeline with a fixed width. I have overflow-x: auto on the parent container and whenever I add white-space: nowrap to that same element, the child list elements start getting cut off. I assume this is something to do with the behavior of flex-box. I have tried adding min-width: 0 to the flex elements and flex-grow: 1 but no luck.
body {
font-family: Arial, Helvetica, sans-serif;
}
.container {
height: 200px;
width: 500px;
margin: 0 auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}
.timeline {
display: flex;
justify-content: center;
min-width: 0;
}
.timeline ol {
list-style: none;
display: flex;
justify-content: center;
}
.timeline .horizontal-line {
position: relative;
background-color: #0d6a3d;
height: 3px;
border-radius: 4px;
margin: 5em 0;
}
.event {
margin: 0px 10px;
position: relative;
}
.date {
position: relative;
text-align: center;
top: -70px;
width: 100%;
}
.date::after {
content: "";
position: absolute;
bottom: -28px;
left: 50%;
right: auto;
height: 20px;
width: 20px;
border-radius: 50%;
border: 3px solid #00a950;
background-color: #fff;
transition: 0.3s ease;
transform: translateX(-50%);
}
.content {
width: 100%;
text-align: center;
position: relative;
top: -45px;
}
<section class="container">
<div class="timeline">
<div class="horizontal-line">
<ol>
<li class="event">
<h3 class="date">07/02/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
</ol>
</div>
</div>
</section>
Add width: fit-content; to your timeline. That gets all elements to fit in the horizontal scroll. Then you are left with the default padding-inline-start on the ol. You can remove that gap by setting padding: 0; or padding-inline-start: 0;.
body {
font-family: Arial, Helvetica, sans-serif;
}
.container {
height: 200px;
width: 500px;
margin: 0 auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}
.timeline {
display: flex;
justify-content: center;
min-width: 0;
width: fit-content;
}
.timeline ol {
list-style: none;
display: flex;
justify-content: center;
padding: 0;
}
.timeline .horizontal-line {
position: relative;
background-color: #0d6a3d;
height: 3px;
border-radius: 4px;
margin: 5em 0;
}
.event {
margin: 0px 10px;
position: relative;
}
.date {
position: relative;
text-align: center;
top: -70px;
width: 100%;
}
.date::after {
content: "";
position: absolute;
bottom: -28px;
left: 50%;
right: auto;
height: 20px;
width: 20px;
border-radius: 50%;
border: 3px solid #00a950;
background-color: #fff;
transition: 0.3s ease;
transform: translateX(-50%);
}
.content {
width: 100%;
text-align: center;
position: relative;
top: -45px;
}
<section class="container">
<div class="timeline">
<div class="horizontal-line">
<ol>
<li class="event">
<h3 class="date">07/02/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
</ol>
</div>
</div>
</section>
As far as I know, width of a flex item adjusts to its content(when flex-direction: row;).
Here you see, the width of second .item is too long even though I set the width of h1 to 50%.
* {
margin: 0;
padding: 0;
}
.container {
display: flex;
justify-content: space-between;
border: 2px solid red;
padding: 10px;
}
.item {
border: 1px solid black;
}
.test {
width: 50%;
}
<div class="container">
<div class="item">Lorem ipsum dolor sit amet.</div>
<div class="item">
<h1 class="test">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi,
quo.
</h1>
</div>
</div>
But when I use px instead of %, the result that I wanted comes out. (Please view it in a full page)
* {
margin: 0;
padding: 0;
}
.container {
display: flex;
justify-content: space-between;
border: 2px solid red;
padding: 10px;
}
.item {
border: 1px solid black;
}
.test {
width: 400px;
}
<div class="container">
<div class="item">Lorem ipsum dolor sit amet.</div>
<div class="item">
<h1 class="test">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi,
quo.
</h1>
</div>
</div>
I can't understand how % is calculated in the first code. Can somebody help? Thanks
You have to apply the width on the .item element.
* {
margin: 0;
padding: 0;
}
.container {
display: flex;
justify-content: space-between;
border: 2px solid red;
padding: 10px;
}
.item {
border: 1px solid black;
}
.item:nth-child(2) {
width: 50%;
}
<div class="container">
<div class="item">Lorem ipsum dolor sit amet.</div>
<div class="item">
<h1 class="test">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi, quo.
</h1>
</div>
</div>
You are not applying 50% to children (.item) but rather to (.test), which is not child of display:flex. Fix it and you'll get result!
* {
margin: 0;
padding: 0;
}
.container {
display: flex;
justify-content: space-between;
border: 2px solid red;
padding: 10px;
}
.item {
border: 1px solid black;
width: 50%;
}
.test {
background: yellow;
}
<div class="container">
<div class="item">Lorem ipsum dolor sit amet.</div>
<div class="item">
<h1 class="test">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi,quo. </h1>
</div>
</div>
I'm trying to align the 3 li items, but I'm not sure what I'm doing wrong. I've tried different options of flexbox but nothing is making the lines of text move up, i've tried putting them in tags but that just increases the gap.
I'd also like to know if it's possible to 'push' the discount section without adding such a big margin like I have done? I feel the margin isn't necessary?
Any help is really appreciated.
<!-- DISCOUNT SECTION -->
<section class="section3">
<div class="section3wrap">
<div class="section3text">
<h2>Pay now and get</br> a 25% <span class="yellow-text">Discount</span></h2>
<div class="test">
<ul>
<li><img src="img/check-icon.png">Lorem ipsum dolor sit amet, consectetur adipiscing elit.<li>
<li><img src="img/check-icon.png">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li><img src="img/check-icon.png">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
</ul>
</div>
<a class="site-btn2">Join the Gym</a>
</div>
</div>
</section>
.section3 {
background-image: url("img/add-bg.jpg");
height: 600px;
background-repeat: no-repeat;
background-size: cover;
background-position: top center;
}
.section3wrap {
display: flex;
justify-content: flex-end;
margin-right: 250px;
}
.section3text {
color: white;
}
.section3text li {
list-style-type: none;
}
.test {
display: flex;
justify-content: ;
}
Make your li element a display: flex; align-items: center;, and surround the images with a div. Inline elements, like images, sometimes can act a bit different when aligning it to the text.
Add extra css
.test ul {
margin:0px;
padding:0px
}
.section3text li {
list-style-type: none;
display: flex;
}
.section3text li img{
margin-right:8px;
}
I hope this is what u r expecting:
.section3 {
background-image: url("https://dummyimage.com/100x100/000/fff");
height: 400px;
background-repeat: no-repeat;
background-size: cover;
background-position: top center;
}
.section3wrap {
display: flex;
height: inherit;
}
.section3text {
color: white;
width: 50%;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.test ul {
padding: 0;
}
.section3text li {
list-style-type: none;
padding:4px;
line-height:15px;
align-items:center;
display:flex;
}
.section3text img {
padding:4px;
}
.test {
display: flex;
}
.site-btn2{
background-color:yellow;
width:100px;
display:flex;
justify-content:center;
line-height:40px;
color:black;
border-radius:3px;
}
<section class="section3">
<div class="section3wrap">
<div class="section3text">
</div>
<div class="section3text">
<h2>Pay now and get<br> a 25% <span class="yellow-text">Discount</span></h2>
<div class="test">
<ul>
<li><img src="https://dummyimage.com/12x12/fff/fff">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</li>
<li><img src="https://dummyimage.com/12x12/fff/fff">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li><img src="https://dummyimage.com/12x12/fff/fff">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
</ul>
</div>
<a class="site-btn2">Join the Gym</a>
</div>
</div>
</section>
Today I've faced with specific design: there is row of cards and text inside card is aligned with another text from other cards. So title is aligned with title from other cards, text is aligned with other texts. It is very difficult for me to explain it clearly so I make a screenshot of the thing I'm trying to reach
By now I'm ready to completely ignore this issue due to impossibility of realization by pure css, but who knows, may be there is some solution?
UPDATE: I'm sorry for lack of explanation. Here is the code. My aim is to make the same alignment as in screeenshot above without using <br>s and fixed heights.
.list {
display: flex;
}
.item {
flex: 0 0 auto;
display: flex;
flex-direction: column;
align-items: center;
width: 120px;
padding: 10px;
background-color: #fff;
border-radius: 10px;
text-align: center;
background-color: rebeccapurple;
color: #fff;
}
.item>* {
flex: 0 0 auto;
}
.item>*+* {
margin-top: 10px;
}
.item+.item {
margin-left: 20px;
}
.icon {
background-color: red;
border-radius: 100%;
width: 20px;
height: 20px;
}
.title {
text-transform: uppercase;
font-weight: bold;
}
.text {
float: left;
clear: left;
}
<div class="list">
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum dolor sit amet.</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est, amet.</div>
</div>
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum.</div>
<div class="text">Lorem ipsum dolor sit amet</div>
</div>
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum dolor.</div>
<div class="text">Lorem ipsum dolor sit amet</div>
</div>
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum dolor sit amet, consectetur.</div>
<div class="text">Lorem ipsum dolor sit amet</div>
</div>
</div>
Thanks in advance.
What you are trying to do can be easily achieved using CSS grids and a bit of HTML restructuring.
The other way to do this would be to give fixed heights to your text elements.
If you are not familiar with CSS grids and don't like the idea of giving fixed heights to your elements, you can achieve similar result by using a little bit of JavaScript. Check the attached snippet.
I have written a small function equalizeClass() to equalize heights of all the elements belonging to a particular class. What it does is basically scans through all the elements belonging to a particular class and finds the element with maximum height. It then sets the heights of all the elements equal to the calculated maximum height.
Don't forget to call equalize() every time you update your related DOM elements.
I have not changed anything in your HTML structure.
In CSS, I have just added justify-content to your item class.
justify-content: space-between;
function equalizeClass(className) {
var images = document.getElementsByClassName(className);
var max_height = 0;
for (var i = 0; i < images.length; i++) {
if (images[i].clientHeight > max_height) {
max_height = images[i].clientHeight;
}
}
for (var i = 0; i < images.length; i++) {
images[i].style.height = max_height + 'px';
}
}
function equalize() {
equalizeClass("title");
equalizeClass("text");
}
window.addEventListener("orientationchange", equalize());
window.addEventListener('resize', equalize());
.list {
display: flex;
}
.item {
flex: 0 0 auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
width: 120px;
padding: 10px;
background-color: #fff;
border-radius: 10px;
text-align: center;
background-color: rebeccapurple;
color: #fff;
}
.item>* {
flex: 0 0 auto;
}
.item>*+* {
margin-top: 10px;
}
.item+.item {
margin-left: 20px;
}
.icon {
background-color: red;
border-radius: 100%;
width: 20px;
height: 20px;
}
.title {
text-transform: uppercase;
font-weight: bold;
}
.text {
float: left;
clear: left;
}
<div class="list">
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum dolor sit amet.</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est, amet.</div>
</div>
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum.</div>
<div class="text">Lorem ipsum dolor sit amet</div>
</div>
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum dolor.</8>
</div>
<div class="text">Lorem ipsum dolor sit amet</div>
</div>
<div class="item">
<div class="icon"></div>
<div class="title">Lorem ipsum dolor sit amet, consectetur.</div>
<div class="text">Lorem ipsum dolor sit amet</div>
</div>
</div>
You need to make your title div a fixed height, ideally a height that is taller than the title text itself. See the code below for your title div:
.title {
text-transform: uppercase;
font-weight: bold;
height: 100px;
max-width: 100%;
}
Then give your text div this style:
.text{
display: flex;
justify-content: center;
align-items: top;
}
See this pen.
I'm trying to learn flexbox, but I'm struggling to understand the concept. I want to create a list of e-mails where every item is a flexbox container (see underneath).
Rules:
The tag is optional but if it is shown, it's shown directly next to the name.
The date is always there, the width varries
The Name of the person fills the remaining space. If it becomes to big it is truncated.
The space between the name and the tag is always 5px
The mail subject is shown on a new line and is also truncated
My attempt so far: https://jsbin.com/sepobipiwa/edit?html,css,output
.container {
width: 350px;
background-color: #FFF;
}
html {
font-family: 'Nunito Sans', sans-serif;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
li {
display: flex;
flex-direction: row;
align-items: baseline;
padding: 20px;
border-bottom: 1px solid #ccc;
}
.name {
font-size: 16px;
font-weight: bold;
text-overflow: ellipsis;
}
.tag {
margin-left: 5px;
font-size: 10px;
font-weight: bold;
background-color: #EFEFEF;
padding: 3px 5px;
border-radius: 3px;
text-transform: uppercase;
}
.subject {
font-size: 15px;
font-weight: 300;
color: #888;
text-overflow: ellipsis;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
<title>JS Bin</title>
</head>
<body>
<div class="container">
<ul>
<li>
<div class="name">John Doe</div>
<div class="date">14:50</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Marrie Antoinette</div>
<div class="tag">Concept</div>
<div class="date">16:01</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Someone with a long name</div>
<div class="tag">tag</div>
<div class="date">18:50</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Someone with a long name</div>
<div class="tag">concept</div>
<div class="date">yesterday</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
</ul>
</div>
</body>
</html>
So I did this to your code:
Made your flexbox to wrap by adding flex-wrap: wrap to the li
Forced the subject to the next line by telling it to take the full available width in the row by giving it flex-basis: 100%
Add margin-left: auto to place the date to the right-most end.
To finish it up, you can add these styles to name and subject to get the ellispsis woking:
white-space: nowrap;
overflow: hidden;
Also added max-width: 50% to name to adjust the first line.
See demo below:
.container {
width: 350px;
background-color: #FFF;
}
html {
font-family: 'Nunito Sans', sans-serif;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
li {
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: baseline;
padding: 20px;
border-bottom: 1px solid #ccc;
}
.name {
font-size: 16px;
font-weight: bold;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
max-width: 50%;
}
.tag {
margin-left: 5px;
font-size: 10px;
font-weight: bold;
background-color: #EFEFEF;
padding: 3px 5px;
border-radius: 3px;
text-transform: uppercase;
}
.subject {
font-size: 15px;
font-weight: 300;
color: #888;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
flex-basis: 100%;
}
.date {
margin-left: auto;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
<title>JS Bin</title>
</head>
<body>
<div class="container">
<ul>
<li>
<div class="name">John Doe</div>
<div class="date">14:50</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Marrie Antoinette</div>
<div class="tag">Concept</div>
<div class="date">16:01</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Someone with a long name</div>
<div class="tag">tag</div>
<div class="date">18:50</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Someone with a long name</div>
<div class="tag">concept</div>
<div class="date">yesterday</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
</ul>
</div>
</body>
</html>
Suggestion:
You should edit you markup and create a wrapper for the first row that contains the name,tag and date which is a better design (you can remove the untidy max-width: 50% used above) - see demo below:
.container {
width: 350px;
background-color: #FFF;
}
html {
font-family: 'Nunito Sans', sans-serif;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
li {
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: baseline;
padding: 20px;
border-bottom: 1px solid #ccc;
}
.name {
font-size: 16px;
font-weight: bold;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.tag {
margin-left: 5px;
font-size: 10px;
font-weight: bold;
background-color: #EFEFEF;
padding: 3px 5px;
border-radius: 3px;
text-transform: uppercase;
}
.subject {
font-size: 15px;
font-weight: 300;
color: #888;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
flex-basis: 100%;
}
.date {
margin-left: auto;
}
.header {
display: flex;
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
<title>JS Bin</title>
</head>
<body>
<div class="container">
<ul>
<li>
<div class="header">
<div class="name">John Doe</div>
<div class="date">14:50</div>
</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="header">
<div class="name">Marrie Antoinette</div>
<div class="tag">Concept</div>
<div class="date">16:01</div>
</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="header">
<div class="name">Someone with a long name</div>
<div class="tag">tag</div>
<div class="date">18:50</div>
</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="header">
<div class="name">Someone with a long name</div>
<div class="tag">concept</div>
<div class="date">yesterday</div>
</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
</ul>
</div>
</body>
</html>
Just an extension on kukkuz excelent answer.
Here , we are acheiving the same results, but without needing to change the markup. (Some how trickier, but sometimes you just can change your markup).
What you really need is to get rid of flex-wrap and set all the first 3 elements in a single row. One alternative is to set the subject element outside of the flex container, positioning it absolute. The remains of the modifications are only to recover the broken layout.
.container {
width: 350px;
background-color: #FFF;
}
html {
font-family: 'Nunito Sans', sans-serif;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
li {
display: flex;
flex-direction: row;
align-items: baseline;
padding: 20px 0px 40px 0px;
margin: 0px 20px;
border-bottom: 1px solid #ccc;
position: relative;
}
.name {
font-size: 16px;
font-weight: bold;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.tag {
margin-left: 5px;
font-size: 10px;
font-weight: bold;
background-color: #EFEFEF;
padding: 3px 5px;
border-radius: 3px;
text-transform: uppercase;
}
.subject {
font-size: 15px;
font-weight: 300;
color: #888;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
flex-basis: 100%;
position: absolute;
bottom: 20px;
max-width: 100%;
}
.date {
margin-left: auto;
}
.header {
display: flex;
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
<title>JS Bin</title>
</head>
<body>
<div class="container">
<ul>
<li>
<div class="name">John Doe</div>
<div class="date">14:50</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Marrie Antoinette</div>
<div class="tag">Concept</div>
<div class="date">16:01</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Someone with a long name</div>
<div class="tag">tag</div>
<div class="date">18:50</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
<li>
<div class="name">Someone with a long name</div>
<div class="tag">concept</div>
<div class="date">yesterday</div>
<div class="subject">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
</li>
</ul>
</div>
</body>
</html>