Flex order not working on unordered list - html

I'm trying out flex on a blog archive page, listing the last 8 entries per page with a sidebar as one of the flex items - 9 items in total. The sidebar shows first in the normal flex order but i'd like it to show third (as sidebars normally do). Trying any order number on the sidebar item doesn't move it about within the list
https://jsfiddle.net/oliver_p/2v3duxy4/2/
html * {
box-sizing: border-box;
}
.list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.list-item {
display: flex;
padding-right: 20px;
width: 33.33333%;
padding-bottom: 20px;
}
.list-item:first-child {
order: 2;
}
.list-content-blog {
background-color: white;
display: flex;
flex-direction: column;
width: 100%;
}
.list-content-blog .list-content-holder {
flex: 1 0 auto;
padding: 30px;
}
<ul>
<li class="list-item">
<div class="list-content-blog">
<div class="list-image-holder">
<a href="#">
<img class="img-responsive" src="#">
</a>
</div>
<div class="list-content-holder">
<p class="post-meta-date"><i class="far fa-clock"></i> 5 March 2018</p>
<h2 style="">Blog Title</h2>
</div>
</div>
</li>
<li class="list-item">
<div class="list-content-blog">
<div class="list-image-holder">
<a href="#">
<img class="img-responsive" src="#">
</a>
</div>
<div class="list-content-holder">
<p class="post-meta-date"><i class="far fa-clock"></i> 10 March 2018</p>
<h2 style="">Blog Title</h2>
</div>
</div>
</li>
<li class="list-item">
<div class="list-content-blog">
<div class="list-image-holder">
<a href="#">
<img class="img-responsive" src="#">
</a>
</div>
<div class="list-content-holder">
<p class="post-meta-date"><i class="far fa-clock"></i> 15 March 2018</p>
<h2 style="">Blog Title</h2>
</div>
</div>
</li>
</ul>

you added (.list) class in your css but you forget to add class in your html,
exp. <ul class="list">

You tried it with .list that does not exist in your html(class-"list") so try ul
ul{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
or add class-"list" to ul :
HTML:
<ul class-"list">
CSS:
.list{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}

You've got:
html * {
box-sizing: border-box;
}
.list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.list-item {
display: flex;
padding-right: 20px;
width: 33.33333%;
padding-bottom: 20px;
}
.list-item:first-child {
order: 2;
}
<ul>
<li class="list-item">
1
</li>
<li class="list-item">
2
</li>
<li class="list-item">
3
</li>
</ul>
...so you refer to the ul element by class that you have not applied.
Add class to the ul element and it will work:
html * {
box-sizing: border-box;
}
.list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.list-item {
display: flex;
padding-right: 20px;
width: 33.33333%;
padding-bottom: 20px;
}
.list-item:first-child {
order: 2;
}
<ul class="list">
<li class="list-item">
1
</li>
<li class="list-item">
2
</li>
<li class="list-item">
3
</li>
</ul>

Related

How can i change the text position in a div?

i have a section, and inside of it an ul with 4 li. In each li a div that are going to be cards. I want to centralize the text inside the div and put it closer to the bottom.
I tried using float: left, and then change the position with margin top and left, but i cannot centralize it.
.cards2 {
text-align: center;
}
.list2 {
list-style: none;
}
.list2 li {
display: inline-block;
}
.cardd2 {
width: 200px;
height: 300px;
background-color: blue;
}
.list2 p {
text-align: center;
}
<section class="cards2">
<ul class="list2">
<li>
<div class="cardd2" id="card1">
<p>Sobre mim</p>
</div>
</li>
<li>
<div class="cardd2" id="card2">
<p>Projetos</p>
</div>
</li>
<li>
<div class="cardd2" id="card3">
<p>Habilidades</p>
</div>
</li>
<li>
<div class="cardd2" id="card4">
<p>Contato</p>
</div>
</li>
</ul>
</section>
Add these to .cardd2
display: flex;
align-items: center;
justify-content: space-evenly;
take note of them young padawan, you're gonna use it a lot
also add margin-bottom: 1vh; for separation
.cards2 {
text-align: center;
}
.list2 {
list-style: none;
}
.list2 li {
display: inline-block;
}
.cardd2 {
width: 200px;
height: 300px;
background-color: blue;
display: flex;
align-items: center;
justify-content: space-evenly;
margin-bottom: 1vh;
}
.list2 p {
text-align: center;
}
<section class="cards2">
<ul class="list2">
<li>
<div class="cardd2" id="card1">
<p>Sobre mim</p>
</div>
</li>
<li>
<div class="cardd2" id="card2">
<p>Projetos</p>
</div>
</li>
<li>
<div class="cardd2" id="card3">
<p>Habilidades</p>
</div>
</li>
<li>
<div class="cardd2" id="card4">
<p>Contato</p>
</div>
</li>
</ul>
</section>
I think that this is the code that you want.
I assume that you need to have the text inside lis to be centered vertically and want it to be a bit down to the bottom.
.cards2{
text-align: center;
}
.list2{
list-style: none;
}
.list2 li{
display: inline-block;
}
.cardd2{
width: 200px;
height: 300px;
background-color: rgb(107, 255, 240);
display: flex;
align-content: center;
margin: 10px;
justify-content: center;
}
.list2 p{
text-align: center;
display: flex;
margin-top:100%;
}
<section class="cards2">
<ul class="list2">
<li>
<div class="cardd2" id="card1"><p>Sobre mim</p></div>
</li>
<li>
<div class="cardd2" id="card2"><p>Projetos</p></div>
</li>
<li>
<div class="cardd2" id="card3"><p>Habilidades</p></div>
</li>
<li>
<div class="cardd2" id="card4"><p>Contato</p></div>
</li>
</ul>
</section>
Add the following to .cardd2:
margin-bottom: .25rem;
display: flex;
align-items: center;
justify-content: center;
.cards2 {
text-align: center;
}
.list2 {
list-style: none;
}
.list2 li {
display: inline-block;
}
.cardd2 {
width: 200px;
height: 300px;
background-color: blue;
margin-bottom: .25rem;
display: flex;
align-items: center;
justify-content: center;
}
.list2 p {
text-align: center;
}
<section class="cards2">
<ul class="list2">
<li>
<div class="cardd2" id="card1"><p>Sobre mim</p></div>
</li>
<li>
<div class="cardd2" id="card2"><p>Projetos</p></div>
</li>
<li>
<div class="cardd2" id="card3"><p>Habilidades</p></div>
</li>
<li>
<div class="cardd2" id="card4"><p>Contato</p></div>
</li>
</ul>
</section>
Maybe Like this:-
* {
padding: 0px;
margin: 0px;
}
.list2 {
display: flex;
positition: absloute;
align items: center;
}
<section class="cards2">
<ul class="list2">
<li>
<div class="cardd2" id="card1">
<p>Sobre mim</p>
</div>
</li>
<li>
<div class="cardd2" id="card2">
<p>Projetos</p>
</div>
</li>
<li>
<div class="cardd2" id="card3">
<p>Habilidades</p>
</div>
</li>
<li>
<div class="cardd2" id="card4">
<p>Contato</p>
</div>
</li>
</ul>
</section>

Align a-tags and spans in a list item on the same hight

I try to align sub elements in a list element.
At the moment it looks like this:
If one of the tags, for e.g. the headline tag gets a row more, all other flowing elements are not aligned anymore.
My goal is to get the aligment like following example:
My code looks like this:
#posts {
display: inline-block;
}
#posts li {
list-style: none;
background-color: #ccc;
width: 32%;
float: left;
}
#posts ul {
display: flex;
justify-content: space-around;
}
#posts li a {
padding: 1.5rem;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.excerpt {
display: flex;
flex-direction: column;
align-items: center;
}
<div id="posts">
<ul>
<li>
<a class="title" href="#">Matcha-Tee?</a>
<span class="excerpt">Teezubereitung
<a class="excerpt-more" href="">Mehr</a>
</span>
</li>
<li>
<a class="title" href="#">Zitronengras?</a>
<span class="excerpt">Zitronengras ist eine besondere Pflanze
<a class="excerpt-more" href="">Mehr</a>
</span>
</li>
<li>
<a class="title" href="#">Wie man heißen Apfel-Zimt-Cider macht</a>
<span class="excerpt">Apfel-Zimt-Cider
<a class="excerpt-more" href="#">Mehr</a>
</span>
</li>
</ul>
</div>
How can I achieve this desired alignment?
Move the flex settings from excerpt to #posts li and apply margin-top: auto to excerpt in order to move everything from there on to the bottom.
(Note: I applied a min-height to your li elements in this snippet to make them higher in order to clearly see the effect.)
#posts {
display: inline-block;
}
#posts li {
display: flex;
flex-direction: column;
align-items: center;
list-style: none;
background-color: #ccc;
width: 32%;
min-height: 300px;
}
#posts ul {
display: flex;
justify-content: space-around;
}
#posts li a {
padding: 1.5rem;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.excerpt {
margin-top: auto;
}
<div id="posts">
<ul>
<li>
<a class="title" href="#">Matcha-Tee?</a>
<span class="excerpt">Teezubereitung
<a class="excerpt-more" href="">Mehr</a>
</span>
</li>
<li>
<a class="title" href="#">Zitronengras?</a>
<span class="excerpt">Zitronengras ist eine besondere Pflanze
<a class="excerpt-more" href="">Mehr</a>
</span>
</li>
<li>
<a class="title" href="#">Wie man heißen Apfel-Zimt-Cider macht</a>
<span class="excerpt">Apfel-Zimt-Cider
<a class="excerpt-more" href="#">Mehr</a>
</span>
</li>
</ul>
</div>

justify-content not creating space between items

I am trying to display these images horizontally in a flex box with justify-content: space-around.
It does not work, any ideas?
The only way that I was able to display it in a spaced manner was with padding.
Why doesn't justify-content work?
h3 {
font-weight: lighter;
font-size: 16px;
margin-top: 0;
margin-bottom: 0;
padding: 0 0 10px 0;
font-family: Proxima Nova;
letter-spacing: 1.92px;
color: #FFFFFF;
opacity: 0.7;
}
.flex-container {
flex-direction: column;
display: flex;
width: 100vw;
height: auto;
}
.trusted-by-container {
display: flex;
flex-flow: column;
align-items: center;
top: 781px;
}
<div class="trusted-by-container">
<div class=t itle>
<h3>TRUSTED BY</h3>
</div>
<ul class="trusting-companies-container">
<li class="company-item"><img src="./images/monday.svg" alt="monday" </li>
<li class="company-item"><img src="./images/intel.svg" alt="intel" </li>
<li class="company-item"><img src="./images/johnson.svg" alt="johnson" </li>
<li class="company-item"><img src="./images/handy.svg" alt="handy" </li>
<li class="company-item"><img src="./images/flexport.svg" alt="flexport" </li>
</ul>
</div>
Flex items will take the width of their content, leaving no extra space for keyword alignment properties (such as justify-content) to work.
Create some extra space; add width: 100%. (Also, close your img elements.)
h3 {
font-weight: lighter;
font-size: 16px;
margin-top: 0;
margin-bottom: 0;
padding: 0 0 10px 0;
font-family: Proxima Nova;
letter-spacing: 1.92px;
color: #FFFFFF;
opacity: 0.7;
}
.flex-container {
flex-direction: column;
display: flex;
width: 100vw;
height: auto;
}
.trusted-by-container {
display: flex;
flex-flow: column;
align-items: center;
top: 781px;
}
.trusting-companies-container {
width: 100%; /* new */
display: flex;
justify-content: space-around;
}
<div class="trusted-by-container">
<div class=t itle>
<h3>TRUSTED BY</h3>
</div>
<ul class="trusting-companies-container">
<li class="company-item"><img src="./images/monday.svg" alt="monday"></li>
<li class="company-item"><img src="./images/intel.svg" alt="intel"></li>
<li class="company-item"><img src="./images/johnson.svg" alt="johnson"></li>
<li class="company-item"><img src="./images/handy.svg" alt="handy"></li>
<li class="company-item"><img src="./images/flexport.svg" alt="flexport"></li>
</ul>
</div>
.companies-evenly {
justify-content: space-evenly;
}
.trusting {
padding: 0;
margin: 0;
list-style: none;
display: flex;
}
<div class="trusted-by-container">
<div class=title>
<h3>TRUSTED BY</h3>
</div>
<ul class="trusting companies-evenly">
<li class="company-item"><img src="./images/monday.svg" alt="monday" </li>
<li class="company-item"><img src="./images/intel.svg" alt="intel" </li>
<li class="company-item"><img src="./images/johnson.svg" alt="johnson" </li>
<li class="company-item"><img src="./images/handy.svg" alt="handy" </li>
<li class="company-item"><img src="./images/flexport.svg" alt="flexport" </li>
</ul>
</div>

h3 takes full width

I would like to make below image. However, I could not combine both display:inline and display: block together. If I use display: block, everything goes on the same line. On the other hand, if I use display block, every element goes to new line.
Here is my code
HTML
<ul>
<li class="icon">
<img src="images/how/post.png" alt="post">
<h4>1. Post</h4>
</li>
<li class="icon">
<img src="images/how/wait.png" alt="wait">
<h4>2. Wait</h4>
</li>
<li class="icon">
<img src="images/how/select.png" alt="select">
<h4>3. Select</h4>
</li>
</ul>
CSS
ul{
list-style: none;
li{
display: inline;
h4{
display:inline;
}
}
img{
width: 6rem;
}
}
Please see an image here of what I would like it to be.Image
use this way display:inline-block and display:block
ul {
list-style: none;
}
ul li {
display: inline-block;
}
ul li h4 {
display: block;
text-align: center;
}
ul img {
width: 6rem;
}
img {
width: 70px;
}
<ul>
<li class="icon">
<img src="https://www.google.co.in/logos/doodles/2018/new-years-eve-2018-4995722058399744.2-law.gif" alt="post">
<h4>1. Post</h4>
</li>
<li class="icon">
<img src="https://www.google.co.in/logos/doodles/2018/new-years-eve-2018-4995722058399744.2-law.gif" alt="wait">
<h4>2. Wait</h4>
</li>
<li class="icon">
<img src="https://www.google.co.in/logos/doodles/2018/new-years-eve-2018-4995722058399744.2-law.gif" alt="select">
<h4>3. Select</h4>
</li>
</ul>
If you remove all the features that HTML list gives, you probably don't need a list. I suggest using divs instead. Set your container with
display: flex;
justify-content: space-between;
to get the layout you want.
.container {
display: flex;
justify-content: space-between;
}
.icon {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex-basis: 200px;
flex-grow: 0;
flex-shrink: 0;
}
h4 {
font-size: 50px;
font-weight: bold;
}
img {
width: 6rem;
}
<div class="container">
<div class="icon">
<img src="https://via.placeholder.com/200" alt="post" />
<h4>1. Post</h4>
</div>
<div class="icon">
<img src="https://via.placeholder.com/200" alt="wait" />
<h4>2. Wait</h4>
</div>
<div class="icon">
<img src="https://via.placeholder.com/200" alt="select" />
<h4>3. Select</h4>
</div>
</div>
Please try this:
HTML:
<ul>
<li class="icon">
<img src="images/how/post.png" alt="post">
<h4>1. Post</h4>
</li>
<li class="icon">
<img src="images/how/wait.png" alt="wait">
<h4>2. Wait</h4>
</li>
<li class="icon">
<img src="images/how/select.png" alt="select">
<h4>3. Select</h4>
</li>
</ul>
SCSS:
ul{
padding-left: 0;
list-style: none;
li{
float: left;
display: inline-block;
width: 33.33%;
text-align: center;
h4{
display:inline-block;
width: 100%;
}
}
img{
width: 6rem;
}
}
pls try this code
<html>
<head>
<style>
ul {
list-style: none;
display: flex;
align-items: center;
justify-content: space-between;
}
ul li{
display: flex;
flex-direction: column;
}
ul li h4 {
display: inline;
}
ul li img {
width: 6rem;
}
</style>
</head>
<body>
<ul>
<li class="icon">
<img src="images/how/post.png" alt="post">
<h4>1. Post</h4>
</li>
<li class="icon">
<img src="images/how/wait.png" alt="wait">
<h4>2. Wait</h4>
</li>
<li class="icon">
<img src="images/how/select.png" alt="select">
<h4>3. Select</h4>
</li>
</ul>
</body>
</html>

How to align a flex item to the right?

I'd like to put the RED button to the right, like I would do using floats in the past
Fiddle: http://jsfiddle.net/vb61r4uL/
.container {
height: 100%;
width: 100%;
background-color: yellow;
display: flex;
align-items: center;
justify-content: center;
}
ul, li {
list-style: none;
padding: 0px;
}
#list {
width: 300px;
background: grey;
}
.item {
display: flex;
align-items: center;
justify-content: flex-start;
}
.destory-button {
background:red;
justify-content: flex-end;
}
<div class="container">
<ul id="list">
<li>
<div class="item">
<input type="checkbox">
Title
<button class="destory-button">Destroy</button>
</div>
</li>
<li>
<div class="item">
<input type="checkbox">
2nd Title
<button class="destory-button">Destroy</button>
</div>
</li>
<li>
<div class="item">
<input type="checkbox">
3rd Title
<button class="destory-button">Destroy</button>
</div>
</li>
</ul>
</div>
How do I make the button align to the right?
Add this style:
.destory-button {
margin-left: auto;
}
Reference: http://www.w3.org/TR/css3-flexbox/#auto-margins
.container {
height: 100%;
width: 100%;
background-color: yellow;
display: flex;
align-items: center;
justify-content: center;
}
ul, li {
list-style: none;
padding: 0px;
}
#list {
width: 300px;
background: grey;
}
.item {
display: flex;
align-items: center;
justify-content: flex-start;
}
.destory-button {
background:red;
justify-content: flex-end;
margin-left: auto;
}
<div class="container">
<ul id="list">
<li>
<div class="item">
<input type="checkbox">
Title
<button class="destory-button">Destroy</button>
</div>
</li>
<li>
<div class="item">
<input type="checkbox">
2nd Title
<button class="destory-button">Destroy</button>
</div>
</li>
<li>
<div class="item">
<input type="checkbox">
3rd Title
<button class="destory-button">Destroy</button>
</div>
</li>
</ul>
</div>