I'm trying to make a table with flexbox but, I have some problems getting it to behave like a table. I can not get it to take only the space required, but still be aligned vertically. As you can see if you run the attached code all column's are taking up the same space. Any suggestions for how I can fix this?
.table {
display: flex;
flex-flow: column;
border-top: 1px solid #000;
border-left: 1px solid #000;
max-width: 100%;
}
.table__row {
display: flex;
max-width: 100%;
border-bottom: 1px solid #000;
}
.table__row:nth-of-type(even) {
background-color: #fff;
}
.table__row:nth-of-type(odd) {
background-color: #efefef;
}
.table__column {
display: flex;
text-align: left;
flex-grow: 1;
flex-basis: 0;
padding: 0 1rem;
border-right: 1px solid #000;
word-break: break-word;
}
.table__header {
background-color: blue;
color: #fff;
}
<div class="table">
<div class="table__row">
<div class="table__column table__header">
ID
</div>
<div class="table__column table__header">
TAG
</div>
<div class="table__column table__header">
USED
</div>
<div class="table__column table__header">
USER
</div>
<div class="table__column table__header">
IP
</div>
<div class="table__column table__header">
DATE
</div>
</div>
<div class="table__row">
<div class="table__column">
1
</div>
<div class="table__column">
newpage
</div>
<div class="table__column">
0
</div>
<div class="table__column">
1
</div>
<div class="table__column">
0
</div>
<div class="table__column">
05.02.2018
</div>
</div>
<div class="table__row">
<div class="table__column">
2
</div>
<div class="table__column">
news
</div>
<div class="table__column">
0
</div>
<div class="table__column">
1
</div>
<div class="table__column">
0
</div>
<div class="table__column">
05.02.2018
</div>
</div>
<div class="table__row">
<div class="table__column">
3
</div>
<div class="table__column">
rajohan
</div>
<div class="table__column">
0
</div>
<div class="table__column">
1
</div>
<div class="table__column">
0
</div>
<div class="table__column">
05.02.2018
</div>
</div>
<div class="table__row">
<div class="table__column">
4
</div>
<div class="table__column">
website
</div>
<div class="table__column">
0
</div>
<div class="table__column">
1
</div>
<div class="table__column">
0
</div>
<div class="table__column">
05.02.2018
</div>
</div>
<div class="table__row">
<div class="table__column">
5
</div>
<div class="table__column">
testtesttesttesttest test test
</div>
<div class="table__column">
0
</div>
<div class="table__column">
1
</div>
<div class="table__column">
0
</div>
<div class="table__column">
05.02.2018
</div>
</div>
</div>
Related
Have something seemlier like this. items has a tooltip it show on hover. but see the bellow example it hide the badge when I put the items in scroll div. basically I want to make a scroll items section and when user hover over it the badge /tooltip display absolute position.
it also has a dropdown menu bottom of the item when hover over it. it work without scroll div, but when I put it into scroll carousal div it not display.
.list {
display: flex;
border:1px solid red;
}
.item {
width: 100px;
height: 100px;
background: red;
margin: 0px 4px;
position: relative;
flex: 0 0 100px;
}
.badge {
position: absolute;
top: -10px;
left: 8px;
width: 40px;
height: 20px;
background: blue;
z-index: 99;
}
.scroll-x {
width: 500px;
overflow-x: auto;
margin: 40px;
}
<div class="list">
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
</div>
<div class="scroll-x">
<div class="list">
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
</div>
</div>
Best I could come up with was this:
I added static height to .list and positioned .item to the bottom
Maybe not the best answer but I hope it helps :)
.list {
display: flex;
height: 110px; //-----
}
.item {
width: 100px;
height: 100px;
background: red;
margin: 0px 4px;
position: relative;
flex: 0 0 100px;
align-self: flex-end; //-----
}
.badge {
position: absolute;
top: -10px;
left: 8px;
width: 40px;
height: 20px;
background: blue;
z-index: 99;
}
.scroll-x {
width: 500px;
overflow-x: auto;
margin: 40px;
}
<div class="list">
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
</div>
<div class="scroll-x">
<div class="list">
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
<div class="item">
<div class="badge"></div>
</div>
</div>
</div>
I'm struggling to make equal flex-box flex-direction column rows. Most of the code is added below. I am trying to deal with it through a long time already and I certainly would appreciate a help.
My code:
.table__cell {
flex: 1;
padding: 10px 20px;
border: 1px solid black;
margin: 3px;
}
.table--params {
width: auto;
flex: 1;
display: flex;
}
.table--params>.table__cell {
padding: 0;
display: flex;
flex-direction: column;
flex-grow: 1;
}
.table--params>.table__cell .table__row {
flex: 1;
}
<div class="table--params">
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Jan Kowalski
</div>
</div>
<div class="table__row">
<div class="table__cell">
John Kowalsky
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
email#example.com
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Tester
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
Grafik
</div>
</div>
</div>
</div>
The problem is visualized in jsfiddle:
https://jsfiddle.net/xp7cs5ag/
The question is - how to make equal height of every row in each column?
You could achieve this with display: grid (instead of flex) for the outer .table__cell. With grid-template-rows: 1fr 1fr 1fr; you define that each row should have an equal height. You could also define fixed values like px.
Working example:
.table__cell {
flex: 1;
padding: 10px 20px;
border: 1px solid black;
margin: 3px;
}
.table--params {
width: auto;
flex: 1;
display: flex;
}
.table--params>.table__cell {
padding: 0;
display: grid;
grid-template-rows: 1fr 1fr 1fr;
}
.table--params>.table__cell .table__row {
flex: 1;
}
<div class="table--params">
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Mariusz Bocz
</div>
</div>
<div class="table__row">
<div class="table__cell">
Feliks Michalski
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
programista#tech-studio.pl
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Programista
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
Grafik
</div>
</div>
</div>
</div>
If you want the grid-items to be centered you could use align-items: center.
Working example:
.table__cell {
flex: 1;
padding: 10px 20px;
border: 1px solid black;
margin: 3px;
}
.table--params {
width: auto;
flex: 1;
display: flex;
}
.table--params>.table__cell {
padding: 0;
display: grid;
grid-template-rows: 1fr 1fr 1fr;
align-items: center;
}
.table--params>.table__cell .table__row {
flex: 1;
}
<div class="table--params">
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Mariusz Bocz
</div>
</div>
<div class="table__row">
<div class="table__cell">
Feliks Michalski
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
programista#tech-studio.pl
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Programista
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
Grafik
</div>
</div>
</div>
</div>
I have the same problem once and I got this code and it worked for me
The HTML :-
<div class="cont">
<div class="col">
<h2>Column 1</h2>
<p>Hello World</p>
</div>
<div class="col">
<h2>Column 2</h2>
<p>Hello World!</p>
<p>Hello World!</p>
<p>Hello World!</p>
<p>Hello World!</p>
</div>
<div class="col">
<h2>Column 3</h2>
<p>Some other text..</p>
<p>Some other text..</p>
</div>
</div>
The CSS :-
.cont {
display: table;
width: 100%;
}
.col {
display: table-cell;
}
I'm building a board with cards inside, just like Trello board.
The JSFiddle is here
Here is the code:
<div class="board-container">
<div class="board-top-menu">
<div class="board-top-menu-item">TOP MENU ITEM 1</div>
<div class="board-top-menu-item">TOP MENU ITEM 2</div>
</div>
<div class="board-content">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 1</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 2</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 3</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 4</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And stylesheet:
.board-container {
padding: 0px;
margin: 0px;
display: flex;
flex-direction: column;
}
.board-top-menu {
width: 100%;
background-color: grey;
display: flex;
flex-direction: row;
padding: 5px;
}
.board-top-menu-item {
padding: 5px;
}
.board-top-menu-item:hover {
background-color: #fefefe;
}
.board-content {
overflow-x: auto;
overflow-y: hidden;
padding: 5px;
background-color: white;
white-space: nowrap;
height: 100%;
width: 100%;
}
.cards {
height: 100%;
overflow-y: auto;
padding-bottom: 20px;
}
.cards-container {
width: 270px;
display: inline-block;
height: 100%;
overflow: hidden;
min-height: 100px;
background-color: #e2e4e6;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-bottom: 20px;
margin-right: 10px;
vertical-align: top;
}
.cards-container-head {
position: relative;
padding: 10px 15px;
margin-bottom: 5px;
}
.cards-container-title {
font-weight: bold;
white-space: normal;
width: 100%;
}
.card-container {
width: 100%;
margin: 0 auto 10px;
background-color: #fff;
min-height: 100px;
border-radius: 5px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
transition: 0.15s;
}
.card-header {
padding: 5px 10px;
border-bottom: 1px solid #dbdbdb;
white-space: normal;
word-break: break-all;
word-wrap: break-world;
display: flex;
flex-direction: row;
justify-content: space-between;
}
I cannot make my board scroll horizontally to see all card containers and vertically inside a card container.
Sometimes, as shown in fiddle, the containers get stucked one above another, and sometimes they scroll the whole page, not only the container.
.board-container {
padding: 0px;
margin: 0px;
display: flex;
flex-direction: column;
}
.board-top-menu {
width: 100%;
background-color: grey;
display: flex;
flex-direction: row;
padding: 5px;
}
.board-top-menu-item {
padding: 5px;
}
.board-top-menu-item:hover {
background-color: #fefefe;
}
.board-content {
overflow-x: auto;
overflow-y: hidden;
padding: 5px;
background-color: white;
white-space: nowrap;
height: 100%;
width: 100%;
}
.cards {
height: 100%;
overflow-y: auto;
padding-bottom: 20px;
}
.cards-container {
width: 270px;
display: inline-block;
height: 100%;
overflow: auto;
min-height: 100px;
background-color: #e2e4e6;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-bottom: 20px;
vertical-align: top;
}
.cards-container-head {
position: relative;
padding: 10px 15px;
margin-bottom: 5px;
}
.cards-container-title {
font-weight: bold;
white-space: normal;
width: 100%;
}
.card-container {
width: 100%;
margin: 0 auto 10px;
background-color: #fff;
min-height: 100px;
border-radius: 5px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
transition: 0.15s;
}
.card-header {
padding: 5px 10px;
border-bottom: 1px solid #dbdbdb;
white-space: normal;
word-break: break-all;
word-wrap: break-world;
display: flex;
flex-direction: row;
justify-content: space-between;
}
<div class="board-container">
<div class="board-top-menu">
<div class="board-top-menu-item">TOP MENU ITEM 1</div>
<div class="board-top-menu-item">TOP MENU ITEM 2</div>
</div>
<div class="board-content">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 1</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 2</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 3</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 4</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 02</div>
<div />
</div>
<div class="card-container">
<div class="card-header">Material 1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I think you have an issue with how your elements are nested. Elements with the class cards-container seem to be nested within other elements with the same class. See the fiddle.
.board-container {
padding: 0px;
margin: 0px;
display: flex;
flex-direction: column;
}
.board-top-menu {
width: 100%;
background-color: grey;
display: flex;
flex-direction: row;
padding: 5px;
}
.board-top-menu-item {
padding: 5px;
}
.board-top-menu-item:hover {
background-color: #fefefe;
}
.board-content {
overflow-x: auto;
overflow-y: hidden;
padding: 5px;
background-color: white;
white-space: nowrap;
height: 100%;
width: 100%;
}
.cards {
height: 100%;
overflow-y: auto;
padding-bottom: 20px;
}
.cards-container {
width: 270px;
display: inline-block;
height: 100%;
overflow: hidden;
min-height: 100px;
background-color: #e2e4e6;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-bottom: 20px;
margin-right: 10px;
vertical-align: top;
}
.cards-container-head {
position: relative;
padding: 10px 15px;
margin-bottom: 5px;
}
.cards-container-title {
font-weight: bold;
white-space: normal;
width: 100%;
}
.card-container {
width: 100%;
margin: 0 auto 10px;
background-color: #fff;
min-height: 100px;
border-radius: 5px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
transition: 0.15s;
}
.card-header {
padding: 5px 10px;
border-bottom: 1px solid #dbdbdb;
white-space: normal;
word-break: break-all;
word-wrap: break-world;
display: flex;
flex-direction: row;
justify-content: space-between;
}
/*Get rid of scrollbar from html */
html {
overflow-x: hidden;
}
/* Add vertical scroll to card container */
.card-container{
height: 50px;
overflow-y: scroll;
}
<div class="board-container">
<div class="board-top-menu">
<div class="board-top-menu-item">TOP MENU ITEM 1</div>
<div class="board-top-menu-item">TOP MENU ITEM 2</div>
</div>
<div class="board-content">
<div>
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 1</div>
</div>
<div class="cards">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
<div class="card-header">Material 1</div>
<div class="card-header">Material 1</div>
<div class="card-header">Material 1</div>
<div class="card-header">Material 1</div>
<div class="card-header">Material 1</div>
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
</div>
</div>
</div>
the html provided is a little messy but i think you need something like this :
<div class="board-top-menu">
<div class="board-top-menu-item">TOP MENU ITEM 1</div>
<div class="board-top-menu-item">TOP MENU ITEM 2</div>
</div>
<div class="board-container">
<div class="cards-container">
<div class="cards-container-head">
<div class="cards-container-title">Test Panel 1</div>
</div>
<div class="cards">
<div class="card-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="card-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
<div class="card-container">
<div class="cards-container-head">
<div class="cards-container-title">ITEM 01</div>
</div>
<div class="card-container">
<div class="card-header">Material 1</div>
</div>
</div>
</div>
</div>
<div class="board-content">content</div>
i didn't do much on css but it should be something like this :
body { overflow:hidden; }
.board-container {
padding: 0px;
margin: 0px;
}
.board-top-menu {
width: 100%;
background-color: grey;
display: flex;
flex-direction: row;
padding: 5px;
}
.board-top-menu-item {
padding: 5px;
}
.board-top-menu-item:hover {
background-color: #fefefe;
}
.board-content {
display: inline-block;
float: left;
padding: 5px;
background-color: white;
white-space: nowrap;
height: 100%;
width: calc(100% - 300px);
}
.cards {
height: 100vh;
overflow-y: scroll;
padding-bottom: 20px;
}
.cards-container {
width: 270px;
float: left;
display: inline-block;
height: 100%;
min-height: 100px;
background-color: #e2e4e6;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-bottom: 20px;
margin-right: 10px;
vertical-align: top;
}
.cards-container-head {
position: relative;
padding: 10px 15px;
margin-bottom: 5px;
}
.cards-container-title {
font-weight: bold;
white-space: normal;
width: 100%;
}
.card-container {
width: 100%;
margin: 0 auto 10px;
background-color: #fff;
min-height: 100px;
border-radius: 5px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
transition: 0.15s;
}
.card-header {
padding: 5px 10px;
border-bottom: 1px solid #dbdbdb;
white-space: normal;
word-break: break-all;
word-wrap: break-world;
display: flex;
flex-direction: row;
justify-content: space-between;
}
See this pen
I have div to look like table, this is my code:
.cell {
border: 1px solid red;
display: table-cell
}
.tableLike {
padding-bottom: 30px;
display: table
}
.rowLike {
display: table-row
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
Now all the the columns are in different width, and I don't know why. I want that div get different width but synchronize.
using display:table like this
.tableLike{width:100%;display:table;}
.cell{border:1px solid red;display:table-cell;}
.tableLike {display:table;}
.rowLike{display:table-row;}
.cell{border:1px solid red;display:table-cell;}
.tableLike{padding-bottom: 30px;}
.rowLike .cell:nth-child(1),.rowLike .cell:nth-child(3){ width: 15%;}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
Add the correct display styles:
.cell {
border: 1px solid red;
display: table-cell;
}
.tableLike {
padding-bottom: 30px;
display: table;
}
.rowLike {
display: table-row;
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
.tableLike {display:table;}
.rowLike{display:table-row;}
.cell{border:1px solid red;display:table-cell;}
.tableLike{padding-bottom: 30px;}
.rowLike .cell:nth-child(1),.rowLike .cell:nth-child(3){ width: 33%;}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
I will do like this.
You can try, but it may not be the best answer.
.cell {
border-right:1px solid red;
border-bottom:1px solid red;
display: table-cell
}
.tableLike {
padding-bottom: 30px;
display: table
}
.rowLike {
display: table-row
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
.rowLike:nth-child(1) .cell:nth-child(1),
.rowLike:nth-child(1) .cell:nth-child(2),
.rowLike:nth-child(1) .cell:nth-child(3){
border-top:1px solid red;
}
.rowLike:nth-child(1) .cell:nth-child(1),
.icon-close{
border-left:1px solid red;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
I'm currently trying to design a Mendeleiev table using only HTML and CSS (CSS3, including Flexbox).
Basically I need each of the boxes to be 1/18 ~= 5.55% of the window width to be responsive.
However, CSS seems to highly miscalculate this value.
Here is a sample of my code
body {
size: 15px;
background: #ff9999;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
}
.line {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
.box {
border: 1px solid #000000;
padding: 10px;
position: relative;
width: 5.56%;
}
.box:before {
content: "";
display: block;
padding-top: 100%;
}
.content {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.weight {
font-size: 10px;
text-align: right;
}
.el {
font-size: 25px;
text-align: center;
font-weight: bold;
}
.no {
font-size: 10px;
text-align: left;
}
.right {
justify-content: flex-end;
}
.wrap {
flex-wrap: wrap;
}
<div class="container">
<!-- Debut 4e ligne -->
<div class="line wrap">
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
4.00
</div>
<div class="el">
He
</div>
<div class="no">
2
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
</div>
<!-- Fin 4e ligne -->
<div class="line">
</div>
<div class="line">
</div>
<div class="line">
</div>
</div>
It is very repetitive (18 columns), but as you should see when pasting it, there are 4 boxes that will not fit on the line (proven with flex-wrap) even when the total of 18*5.55% = 99.9%.
Why such a difference?
Width, in this context, is in addition to padding and border. Try starting with:
.box { box-sizing: border-box; }
and you should see a difference. Combined with 5.55% (not 5.56%) width, that fits perfectly for me.
This is simply because your boxes have width and padding. Padding is additive, meaning if you do width: 500px; padding: 10px;, the result is an element that's 520px wide.
What you can do is apply box-sizing: border-box; to your .box element to make the padding apply inward instead of outward, thus maintaining its set width.
.box {
border: 1px solid #000000;
padding: 10px;
position: relative;
width: 5.56%;
box-sizing: border-box;
}
Working snippet:
body {
size: 15px;
background: #ff9999;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
}
.line {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
.box {
border: 1px solid #000000;
padding: 10px;
position: relative;
width: 5.55%;
box-sizing: border-box;
}
.box:before {
content: "";
display: block;
padding-top: 100%;
}
.content {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.weight {
font-size: 10px;
text-align: right;
}
.el {
font-size: 25px;
text-align: center;
font-weight: bold;
}
.no {
font-size: 10px;
text-align: left;
}
.right {
justify-content: flex-end;
}
.wrap {
flex-wrap: wrap;
}
<div class="container">
<!-- Debut 4e ligne -->
<div class="line wrap">
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
4.00
</div>
<div class="el">
He
</div>
<div class="no">
2
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
<div class="box">
<div class="content">
<div class="weight">
1.00
</div>
<div class="el">
H
</div>
<div class="no">
1
</div>
</div>
</div>
</div>
<!-- Fin 4e ligne -->
<div class="line">
</div>
<div class="line">
</div>
<div class="line">
</div>
</div>