Stretch flexbox item vertically - html

I'm trying to make the list take up all the blue space, but I don't want to add another item.
I could just give the items the right amount of padding to make it fit perfectly, but I feel like that's not the right way. So I thought there must be a way to do this with flexbox.
See plunker and snippet:
html,
body {
margin: 0px;
height: 100%;
}
main {
display: flex;
}
#art1 {
flex: 2;
margin-right: 20px;
background: red;
display: flex;
}
#art2 {
background: blue;
flex: 1;
}
#art1>img,
#art1>p {
flex: 1;
}
article {}
#media (max-width: 800px) {
main {
flex-direction: column;
}
#art1 {
margin: 0;
}
}
.activiteiten {
background: yellow;
list-style-type: none;
margin: 0;
padding: 0;
}
.activiteiten>li {
background: white;
border: 1px solid green;
padding: 10px;
}
<main>
<article id="art1">
<p>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum </p>
<img src="http://via.placeholder.com/150x250" alt="">
</article>
<article id="art2">
<ul class="activiteiten">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</article>
</main>

Make your ul a flexbox too:
height: 100%;
margin: 0; // reset the margin
display: flex;
flex-direction: column; // list vertically
justify-content: space-around; // spread the li vertically
and add flex: 1 to the lis
See demo below:
html,
body {
margin: 0px;
height: 100%;
}
main {
display: flex;
}
#art1 {
flex: 2;
margin-right: 20px;
background: red;
display: flex;
}
#art2 {
background: blue;
flex: 1;
}
#art1>img,
#art1>p{
flex: 1;
}
article {}
article ul {
height: 100%;
margin: 0;
display: flex;
flex-direction: column;
justify-content: space-around;
}
article ul li {
flex: 1;
}
#media (max-width: 800px) {
main {
flex-direction: column;
}
#art1 {
margin: 0;
}
}
.activiteiten {
background: yellow;
list-style-type: none;
margin: 0;
padding: 0;
}
.activiteiten>li{
background: white;
border: 1px solid green;
padding: 10px;
}
<main>
<article id="art1">
<p>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum </p>
<img src="http://via.placeholder.com/150x250" alt="">
</article>
<article id="art2">
<ul class="activiteiten">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</article>
</main>

Related

Png images with text. Break line image + at least some text

Hi I have some text in quoutes (I used png files as quoutes).
The problem is with the line breaking when you shrink down the window size. I am trying to avoid breaking line with image only, like this :
It should only break line with at least some text to the left, like this:
How can I achieve this? Any help would be much appreciated.
.testimonials {
padding: 80px 0;
padding: 60px 0;
position: relative;
}
.testimonials::before {
content: "";
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.testimonials .testimonial-item {
text-align: center;
color: #fff;
}
.testimonials .testimonial-item .testimonial-img {
width: 100px;
border-radius: 50%;
border: 2px solid #fff;
margin: 0 auto;
}
.testimonials .testimonial-item h3 {
font-size: 30px;
font-weight: bold;
margin: 10px 0 5px 0;
color: black;
}
.testimonials .testimonial-item h4 {
font-size: 20px;
color: red;
margin: 0 0 15px 0;
}
.testimonials .testimonial-item .quote-icon-left, .testimonials .testimonial-item .quote-icon-right {
color: rgba(255, 255, 255, 0.6);
font-size: 26px;
}
.testimonials .testimonial-item .quote-icon-left {
display: inline-block;
left: -2px;
position: relative;
top: 5px;
}
.testimonials .testimonial-item .quote-icon-right {
display: inline-block;
right: -2px;
position: relative;
}
.testimonials .testimonial-item p {
font-style: italic;
margin: 0 auto 15px auto;
color: black;
}
#media (min-width: 1024px) {
.testimonials {
background-attachment: fixed;
}
}
#media (min-width: 992px) {
.testimonials .testimonial-item p {
width: 80%;
}
}
<div class="testimonials">
<div class="testimonial-item">
<h3>John</h3>
<h4>Master</h4>
<p>
<img src="https://www.pngall.com/wp-content/uploads/12/Quotes-Mark-Symbol-PNG-Image.png" class="bi bi-quote quote-icon-left" style="max-width:26px;"/>
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
<img src="https://www.pngall.com/wp-content/uploads/12/Quotes-Mark-Symbol-PNG-Image.png" class="bi bi-quote quote-icon-right" style="max-width:26px;"/>
</p>
</div>
</div>
I just figured out an asnwer based on post : Keep <img> always at the end of text line
<div class="testimonials">
<div class="testimonial-item">
<h3>John</h3>
<h4>Master</h4>
<p>
<img src="https://www.pngall.com/wp-content/uploads/12/Quotes-Mark-Symbol-PNG-Image.png" class="bi bi-quote quote-icon-left" style="max-width:26px;"/>
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem
<span style="white-space:nowrap;">ipsum
<img src="https://www.pngall.com/wp-content/uploads/12/Quotes-Mark-Symbol-PNG-Image.png" class="bi bi-quote quote-icon-right" style="max-width:26px;"/>
</span>
</p>
</div>
</div>
We have to combine last word with the image in the <span></span> element. Then give it a white-space:nowrap styling.

Items in one row but in different blocks

Have a little issue to force items to be in one row without a table.
For example I have like this:
Problem is if somehow long text in left block has word break (because of screen width, maybe), then two columns will not match.
I know it is easy to do with table, but is there another way to do it flexible?
html
<div class="data">
<div class="data__name">
<ul>
<li>Lorem ipsum dolor sit amet.:</li>
<li>Lorem ipsum dolor sit amet.:</li>
<li>Lorem ipsum dolor sit amet.:</li>
<li>Lorem ipsum dolor sit amet.:</li>
</ul>
</div>
<div class="data__line"></div>
<div class="data__info">
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
</div>
css
.data {
font-size: 15pt;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin: 25px 0;
}
.data__name {
color: #666666;
-webkit-box-flex: 0;
-ms-flex: 0 40%;
flex: 0 40%;
}
.data__line {
border-left: 2px solid gray;
}
.data__info {
font-weight: bold;
margin-left: 5%;
white-space: nowrap;
}
you can use word-break: break-word; on li element to wrap text inside component if text is too long
.data {
font-size: 15pt;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin: 25px 0;
}
.data__name {
color: #666666;
-webkit-box-flex: 0;
-ms-flex: 0 40%;
flex: 0 40%;
}
.data__name li {
word-break: break-word;
}
.data__line {
border-left: 2px solid gray;
}
.data__info {
font-weight: bold;
margin-left: 5%;
white-space: nowrap;
}
<div class="data">
<div class="data__name">
<ul>
<li>Lorem ipsum dolorvvvvvvvvvvvv sit amet.:</li>
<li>Lorem ipsum dolor sit amet.vvvvvvvvvvvvvvvvvvv:</li>
<li>Lorem ipsum dolor sit amet.:</li>
<li>Lorem ipsum dolor sit amet.:</li>
</ul>
</div>
<div class="data__line"></div>
<div class="data__info">
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>
</div>
Add flex-wrap: wrap; for the items

Make text to break under own

What I want to achieve is make a tag text to start new line under it own text not under numbers
ul.myul {
counter-reset: li;
}
ul.myul li {
counter-increment: li;
list-style: none;
margin-bottom: 10px;
}
ul.myul li a::before {
content: "0" counter(li);
font-size: 22px;
font-family: 'poppinsbold';
color: red;
margin-right: 10px;
}
<div style="width:400px">
<ul class="myul">
<li><a>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</a></li>
<li><a>lorem ipsum lorem</a></li>
</ul>
</div>
This is what I want actually, it should goes to new line after red line, not behind the redline:
ul.myul {
counter-reset: li;
}
ul.myul li {
counter-increment: li;
list-style: none;
margin-bottom: 10px;
}
ul.myul li a::before {
content: "0" counter(li);
font-size: 22px;
font-family: 'poppinsbold';
color: red;
margin-right: 10px;
}
.myul::after {
content: "";
width: 2px;
height: 100%;
background: red;
position: absolute;
top: 0;
left: 78px;
}
<div style="width:400px">
<ul class="myul">
<li><a>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</a></li>
<li><a>lorem ipsum lorem</a></li>
</ul>
</div>
#CBroe had already mentioned it correctly in the comment. The ul CSS property list-style-position: outside; is the right way to go here.
ul.myul {
counter-reset: li;
}
ul.myul li {
counter-increment: li;
list-style: none;
margin-bottom: 10px;
padding-left: 50px;
list-style-position: outside;
position: relative;
}
ul.myul li::before {
content: "0" counter(li) ".";
font-size: 22px;
font-family: 'poppinsbold';
color: red;
left: 0;
position: absolute;
top: 0;
}
.myul::after {
content: "";
width: 2px;
height: 100%;
background: red;
position: absolute;
top: 0;
left: 86px;
}
<div style="width:400px">
<ul class="myul">
<li>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</li>
<li><a>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</a></li>
<li><a>lorem ipsum lorem</a></li>
</ul>
</div>

Width of a flex item doesn't change when I use %

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>

Align card contents with other card contents (photo)

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.