I have got a list of eight items and I would like to center it in three columns as well as its content so that the words are aligned with respect first and second line. What's the best way to achieve it? I've tried with percent but the content still disaligned.
body{
margin: 0;
padding: 0;
}
.wk_search-resume-list {
width: 100%;
overflow: auto;
}
.wk_search-resume-list li {
margin-bottom: 16px;
font-size: 14px;
position: relative;
width: 33%;
display: inline-block;
vertical-align: top;
text-align: center;
}
.wk_search-resume {
background-color: white;
border: 1px solid #bfbfbf;
margin: 32px 16px;
padding: 24px 24px 8px 24px;
font-size: 0;
position: relative;
}
.wk_search-resume-list strong {
display: block;
}
.wk_search-resume-list.wk-interval {
margin-top: 32px;
border: 1px solid red;
padding: 0;
}
<ul class="wk_search-resume-list wk-interval">
<li class="wk_search-resume-list--procedure">Tipo de procedimiento <strong>Procedimiento ordinario</strong></li>
<li class="wk_search-resume-list--subvoice">Subvoz <strong>Extinción y suspensión del arrendamiento</strong></li>
<li class="wk_search-resume-list--favor">A favor <strong>Arrendador</strong></li>
<li class="wk_search-resume-list--year">Año <strong>1992</strong></li>
<li class="wk_search-resume-list--resource">Tipo de recurso <strong>Procedimiento</strong></li>
<li class="wk_search-resume-list--against">En contra <strong>Arrendatario</strong></li>
<li class="wk_search-resume-list--judgment">Sentido del fallo <strong>Arrendador</strong></li>
<li class="wk_search-resume-list--judgment">Argumentos legales <strong>Crédito bancario</strong></li>
</ul>
Notes:
This information is dinamic and in case of having only one item, this one should be centered on screen.
If a item is deleted, this one must be replaced by the next one on the list.
I am still unclear on how you want to divide up the 8 items, but here is a rudimentary example showing what is possible with CSS Grid and Flexbox.
JS BIN example
ul{
display: grid;
grid-template-rows: 100px 100px 100px;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
li{
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
Finally, I achieved solve this with flexbox.
Container:
display: flex;
justify-content: space-around;
flex-wrap: wrap;
Content:
flex-grow: 1;
width: 33%;
Last-child of content (in order to position it on the left):
flex-grow: 80;
Related
Basically, in a container, I have tabs (with ul.li) and another div (search box) next to these tabs which are displayed in a row using flex.
I want it responsive following this workflow:
if the width increases, the search section increases to fit the available space. I manage to do using the property flex-basis: 100%
if the width decreases, the search section decreases as well with the property flex-basis: 100%. However, I would like the search section to decrease until 100px and then tabs will decrease displaying ellipsis. I tried using flex-shrink or flex-grow without success since I am not an expert with flexbox.
I reproduced the simplest example in order to illustrate what I am saying.
body {
padding: 50px;
font-family: sans-serif;
}
.container {
resize: horizontal;
overflow: auto;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
border: 1px solid black;
}
.tabs__list {
align-items: flex-start;
display: flex;
list-style: none;
margin: 0;
padding: 0;
border-bottom: 0;
margin-right: 28px;
width: unset;
}
button {
height: 34px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.search {
flex-basis: 100%;
height: 34px;
align-self: end;
min-width: 100px;
background-color: blue;
}
<div class="container">
<ul class="tabs__list">
<li>
<button type="button">Tab Item Number One</button>
</li>
<li>
<button type="button">Tab Item Number Two</button>
</li>
</ul>
<div class="search"></div>
</div>
You need to make use of the power of flex-grow, flex-shrink and flex-basis properties on the children of your flex container.
This is very handy youtube tutorial from Kevin Powell explaining these properties and other important flex-box concepts.
Anyway, here's a solution to your problem with comments explaining what has been added and why.
body {
padding: 50px;
font-family: sans-serif;
}
.container {
resize: horizontal;
display: flex;
overflow: auto;
align-items: center;
flex-wrap: nowrap;
/* don't allow items to go to a new line on shrink */
border: 1px solid black;
min-width: 138px;
/* 100px for the div.search width + 10px inline padding for div.search + 28px margin-rigt from ul.tabs__list */
}
.tabs__list {
flex-grow: 0;
/* this forbids ul from growing, so only div.search can take the remaining space */
flex-shrink: 1;
/* this allows ul to shrink */
flex-basis: content;
list-style: none;
margin: 0;
padding: 0;
border-bottom: 0;
margin-right: 28px;
overflow: hidden;
/* styling the ul with nowrap so that the li's do not go on the next line on shrink */
display: flex;
flex-wrap: nowrap;
}
.search {
flex-grow: 1;
/* this allows div.search to grow and take up the remaining space */
flex-shrink: 0;
/* this forbids div.search to shrink below 100px */
flex-basis: 100px;
/* this works quite like min-width: 100px; but not exactly the same */
align-self: end;
height: 45px;
background-color: blue;
/* more suggested styling to div.search */
color: white;
display: flex;
align-items: center;
padding: 5px;
}
.tabs__list li {
/* display: inline; */
margin: 5px;
padding: 5px;
flex: auto;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
/* the following styling is applied to give li's the look of a button */
border: black 1px solid;
text-align: center;
background-color: lightgray;
cursor: pointer;
}
.tabs__list li:hover {
background-color: gray;
color: white;
}
<div class="container">
<ul class="tabs__list">
<li> Tab Item Number One</li>
<li>Tab Item Number Two</li>
</ul>
<div class="search">Search</div>
</div>
The most important thing an element needs for ellipsis to work is width. Without a width, the browser won't know when the text is actually being cut from its predefined width. I set a width on your container to 100%. Then set each child element (tabs__list and search) to 50%. I also set the li to 50% so each item would take half of that space. However, I still have flex-basis: 100%; so search fills any remaining space.
With this set, you can now just set width: 100%; to your button, which is the defined width it needs so it knows the text is being cut off and it needs to show ellipsis.
Side note: you can still add your min-width: 100px; to search and it will still show ellipsis, but I removed it because it shows a vertical scrollbar.
body {
padding: 50px;
font-family: sans-serif;
}
.container {
resize: horizontal;
overflow: auto;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
border: 1px solid black;
width: 100%;
}
.tabs__list {
align-items: flex-start;
display: flex;
list-style: none;
margin: 0;
padding: 0;
border-bottom: 0;
margin-right: 28px;
width: 25%;
}
li {
width: 50%;
}
button {
height: 34px;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.search {
flex-grow: 1;
flex-basis: 100%;
width: 75%;
min-width: 100px;
height: 34px;
align-self: end;
background-color: blue;
}
<div class="container">
<ul class="tabs__list">
<li>
<button type="button">Tab Item Number One</button>
</li>
<li>
<button type="button">Tab Item Number Two</button>
</li>
</ul>
<div class="search"></div>
</div>
I want to place a text inline and between two arrows. at first it seems easy but I can't place everything in their right place:
html, body {
height: 100%;
}
body {
background: #fafafc;
margin: 0;
}
.flex-container {
height: 100%;
padding: 0;
margin: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
.grid-container {
width: 50%;
display: grid;
grid-template-columns: 40px auto 40px;
}
.referenceText {
font-family: Arial;
display: inline-block;
font-size: 3vw;
color: #4287f5;
/*outline: 0.1vw dashed red;*/
}
.link {
font-size: 200px;
color: #a7a4bf;
text-decoration: none;
width: 100px;
height: 100px;
outline: 0.1vw dashed orange;
}
.link:hover {
color: #636175;
}
<div class="flex-container">
<div class="grid-container">
<a class="link" href="">‹</a>
<div class="referenceText">This is the reference</div>
<a class="link" href="">›</a>
</div>
</div>
Please note that we want the arrows to be at the edges of the screen and the text at the center...
Make these changes in .grid-container and .link
.grid-container {
width: 80%;
display: grid;
grid-template-columns: 100px auto 100px;
align-items: center;
justify-items: center;
}
.link {
font-size: 200px;
color: #a7a4bf;
text-decoration: none;
width: 100px;
/* height: 100px; remove height*/
outline: 0.1vw dashed orange;
}
check codepen
Add display: flex;, align-items: center; and justify-content: space-between; to .grid-container and change the width to 100%.
Heeey friends,
I'm trying to do this, I want to change positions of every second post, from left to right.
Here is an example:
I used for the "main-content" the nth-child(even) and it works fine, but for the other div its just doesn't work at all.
CSS:
.archive-cc {
position: relative;
padding-right: 5%;
padding-left: 5%;
width: 100%;
height: 300px;
z-index: 80;
background-color: floralwhite;
border-bottom: pink 10px solid;
}
.archive-content {
position: relative;
float: right;
margin: 0 auto;
width: 80%;
z-index: 50;
background-color: dodgerblue;
}
.archive-cc:nth-child(even)>div {
position: relative;
float: left;
margin: 0 auto;
width: 80%;
z-index: 50;
}
.meta {
float: left;
background-color: yellow;
width: 20%;
}
.meta-text {
width: 100%;
background-color: yellow;
}
.meta:nth-child(even)>div {
float: right;
width: 100%;
background-color: hotpink;
}
HTML:
<div class="archive-cc">
<div class="meta">
<div class="meta-text">PLS WOOOORK</div>
</div>
<div class="archive-content">
<h2 class="entry-title">testtest</h2>
<div class="entry-summary">test</div>
</div>
</div>
I literally tried everything already, I hope someone can help me! It looks like this right now: http://helga-fruehauf-koehler.de/wordpress/fotografie/
I suggest not to use any floating layout here, but flexbox to reach your goal. This is supported by modern browsers and easier to work with.
Found a very good resource on how to split flexbox items into multiple rows at tobiasahlin's blog.
Found a very good explanation on flex-direction on css-tricks. This also includes an Codepen example using different CSS classes per flex-direction.
Here is my solution using the nth-child pseudo class which abstracts away the .row and .row-reverse CSS classes from example above.
Demo: https://jsfiddle.net/vp8xbqus/1/
Code:
HTML
<div class="wrapper">
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
</ul>
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
</ul>
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
</ul>
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
</ul>
<!-- add more boxes as above -->
</div>
CSS
.wrapper {
background: blue;
margin: 20px;
}
.flex-container {
padding: 0;
margin: 0;
list-style: none;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
}
.flex-item {
background: tomato;
padding: 5px;
width: 50%;
height: 50px;
margin: 5px;
line-height: 50px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}
// Abstraction for .row and .row-reverse styles based on nth-child
.wrapper :nth-child(odd) {
-webkit-flex-direction: row;
flex-direction: row;
}
.wrapper :nth-child(odd) :first-child {
flex-basis: 100px;
background: green;
}
.wrapper :nth-child(even) {
-webkit-flex-direction: row-reverse;
flex-direction: row-reverse;
}
.wrapper :nth-child(even) :first-child {
flex-basis: 100px;
background: gold;
}
here's what I have Fiddle
ul {
display: flex;
justify-content: flex-start;
flex-direction: row;
align-items: center;
width: 100%;
height: 100px;
background: #333;
padding: 15px;
}
ul li {
padding: 15px;
margin: 5px;
background: #efefef;
border: 1px solid #ccc;
display: inline-block;
list-style: none;
}
#item-1 {
height: 50px;
}
#item-2 {
height: 70px;
}
<ul>
<li id="item-1">Home</li>
<li id="item-2">Menu</li>
<li>More</li>
<li>Stuff</li>
<li>Settings</li>
</ul>
I want the last item inside the flex-box to be pulled to the right ("Settings" in my fiddle) while keeping all other items the way they are. The "Settings"-item should also be centered vertically and everything.
align-self: flex-end pushes the item to the bottom (I want it on the right).
I would very much prefer a solution using flex-box because my items have variable heights and should always be centered vertically.
What is the cleanest way to achieve this?
Thanks for your help!
Simple fix, use an auto-adjusting margin:
ul li:last-child {
margin-left: auto;
}
You may also want to not use width: 100% so that the element stays inside the visible area:
ul {
display: flex;
justify-content: flex-start;
flex-direction: row;
align-items: center;
/* width: 100%; */
height: 100px;
background: #333;
padding: 15px;
}
http://jsfiddle.net/dwLHE/
See also https://www.w3.org/TR/css-flexbox-1/#auto-margins
I have container with fixed height and display: flex. I want it's children to be laid in a column-first manner by setting -webkit-flex-flow: column wrap;.
http://jsfiddle.net/wNtqF/1/
Can anyone explain me how chrome calculates the resulting width of the container div (div with green border) and why is leaves so much free space on the right of each red item. What I want is to have the container to have width just to fit all children, without the additional empty space.
If it's not possible with pure css can you provide me an alternative to achive this?
I'm using Chrome v 29.0.1547.76
The code to reproduce it is:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
position: fixed;
height: 90%;
padding: 0;
margin: 0;
list-style: none;
border: 6px solid green;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: column wrap;
justify-content: flex-start
align-content: flex-start;
align-items: flex-start
}
/** Just to show the elements */
body {
margin: 0;
padding: 0;
}
.flex-item {
background: tomato;
padding: 5px;
width: 100px;
height: 100px;
margin-top: 10px;
line-height: 150px;
color: white;
font-weight: bold;
font-size: 3em;
text-align: center;
}
</style>
</head>
<body>
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
</ul>
</body>
Chrome automatically puts the space between the div and the border top, to fix this, you can just use:
margin-bottom: 100%;
Why this? margin-bottom: 100% reset the element and move the item up.
You've tried with:
body {
margin: 0;
padding: 0;
}
But this didn't work because body sposte the page html and not single element.
The complete code will are here:
.flex-container {
position: fixed;
height: 90%;
padding: 0;
margin: 0;
list-style: none;
border: 6px solid green;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: column wrap;
justify-content: flex-start
align-content: flex-start;
align-items: flex-start
}
/** Just to show the elements */
body {
margin: 0;
padding: 0;
}
.flex-item {
background: tomato;
padding: 5px;
width: 100px;
height: 100px;
margin-bottom: 100%;
line-height: 150px;
color: white;
font-weight: bold;
font-size: 3em;
text-align: center;
}
<ul class="flex-container">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
</ul>