I need to know how to build this layout with flex.
My vue component:
<template functional>
<div class="dashboard-wrapper">
<div id="your-parking">Parking</div>
<div id="options">
<div id="parking-menu">Options</div>
<div id="parking-contact"> Call to ...</div>
<div id="payment">Payment</div>
</div>
<div id="noticeboard">Noticeboard</div>
</div>
</template>
<style lang="scss" scoped>
.dashboard-wrapper {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-height: 100%;
}
#your-parking{
background-color: cornflowerblue;
order: 1;
width:50%;
min-height: 50%;
}
#options {
order: 2;
min-width:50%;
}
#parking-menu{
max-height: 10vh;
}
#parking-contact{
min-width:50%;
}
#payment{
order: 4;
min-width:50%;
height: 60vh;
background-color: red;
}
#noticeboard{
order: 5;
width:50%;
background-color: goldenrod;
min-height: 50%;
}
</style>
My current result:
Colors and (min|max) height I added for test.
On the phone I want to have list with divs: parking, options, contact, payment, noticeboard.
You could change the structure of your html template and apply CSS like below:
.dashboard-container {
height: 15vh;
border-bottom: 1px solid gray;
}
.content-container {
display: flex;
height: 85vh;
box-sizing: border-box;
}
.left-content, .right-content {
width: 50%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.parking, .noticeboard {
box-sizing: border-box;
flex: 1;
width: 100%;
border: 1px solid black;
}
.options, .contact {
flex: 1;
border: 1px solid black;
}
.payment {
flex: 4;
width: 90%;
margin: auto;
border: 1px solid black;
}
.parking, .noticeboard, .options, .contact, .payment {
margin-bottom: 5vh;
}
<div class="container">
<div class="dashboard-container">
<p>
DASHBOARD
</p>
</div>
<div class="content-container">
<div class="left-content">
<div class="parking">
<p>
PARKING
</p>
</div>
<div class="noticeboard">
<p>
NOTICEBOARD
</p>
</div>
</div>
<div class="right-content">
<div class="options">
<p>
OPTIONS
</p>
</div>
<div class="contact">
<p>
CONTACT
</p>
</div>
<div class="payment">
<p>
PAYMENT
</p>
</div>
</div>
</div>
</div>
You can check the JSFiddle here.
#dashboard{
width:80%;
margin:0 auto;
border:solid 1px grey;
height:10vh;
}
#container{
display:flex;
width:80%;
height:90vh;
border:solid 1px grey;
margin:0 auto;
}
#left,#right{
display:flex;
width:50%;
height:90vh;
border:solid 1px red;
flex-direction:column;
justify-content:flex-start;
align-items:center;
}
#parking,#noteboard{
width:100%;
height:35vh;
border:solid 1px green;
margin-bottom:2vh;
}
#options,#contact{
width:100%;
height:10vh;
border:solid 1px blue;
margin-bottom:2vh;
}
#payment{
width:80%;
height:46vh;
border:solid 1px pink;
}
<div id='dashboard'>Dashboard</div>
<div id='container'>
<div id='left'>
<div id='parking'>parking
</div>
<div id='noteboard'>noteboard
</div>
</div>
<div id='right'>
<div id='options'>options
</div>
<div id='contact'>contact
</div>
<div id='payment'>payment
</div>
</div>
</div>
Related
This question already has answers here:
Force flex item to span full row width
(2 answers)
Closed 2 years ago.
How do I make the top div of the full horizontal length of the main container, while keeping the next two div, .left and .right in flex to each other?
To look like this -
.main {
border: 1px solid red;
display: inline-flex;
}
.main div.top {
border: 1px solid orange;
width: auto;
display: inline-block;
}
.main div.left {
border: 1px solid blue;
}
.main div.right {
border: 1px solid green;
}
<html>
<body>
<div class="main">
<div class="top">
<h1>top</h1>
</div>
<div class="left">
<h1>left</h1>
</div>
<div class="right">
<h1>right</h1>
</div>
</div>
</body>
</html>
Another way to do this is with grid:
.main {
display: grid;
grid-template-columns: 1fr 1fr;
}
.main .top {
grid-column: 1/3;
}
.main {
border: 1px solid red;
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 4px;
padding: 4px;
}
.main .top {
border: 1px solid orange;
grid-column: 1/3;
}
.main .left {
border: 1px solid blue;
}
.main .right {
border: 1px solid green;
}
<div class="main">
<div class="top">
<h1>top</h1>
</div>
<div class="left">
<h1>left</h1>
</div>
<div class="right">
<h1>right</h1>
</div>
</div>
Use display: flex; and flex-wrap: wrap on the parent container, 100% width on the first child and flex-grow: 1 on the other children, or also use percentage widths on the second and third DIVs.
* {
box-sizing: border-box;
}
.main {
border: 1px solid red;
display: flex;
flex-wrap: wrap;
}
.main div.top {
border: 1px solid orange;
width:100%;
}
.main div.left {
border: 1px solid blue;
width: 40%;
}
.main div.right {
border: 1px solid green;
width: 60%;
}
<html>
<body>
<div class="main">
<div class="top"> <h1>top</h1>
</div>
<div class="left"> <h1>left</h1>
</div>
<div class="right"> <h1>right</h1>
</div>
</div>
</body>
</html>
Any width of .left and .right
.main {
border: 1px solid red;
display: flex;
flex-wrap: wrap;
}
.main div.top {
border: 1px solid orange;
width: auto;
display: inline-block;
flex: 1 1 100%;
}
.main div.left {
border: 1px solid blue;
flex: 1 1 auto;
}
.main div.right {
border: 1px solid green;
flex: 1 1 auto;
}
<div class="main">
<div class="top">
<h1>top</h1>
</div>
<div class="left">
<h1>left 11111111</h1>
</div>
<div class="right">
<h1>right</h1>
</div>
</div>
You can try something like this:
I just added 2 extra divs if that is not an issue?
#MainDiv {
width: 200px;
border: 1px solid red;
}
.main {
width: auto;
display: flex;
flex-direction: column;
}
#lower {
display: flex;
flex-direction: row;
}
.left,
.right {
width: 100px;
border: 1px solid black;
}
<html>
<body>
<div id="MainDiv">
<div class="main">
<div class="top">
<h1>top</h1>
</div>
<div id="lower">
<div class="left">
<h1>left</h1>
</div>
<div class="right">
<h1>right</h1>
</div>
</div>
</div>
</div>
</body>
</html>
You can two div to create additional sections.
.main {
border: 1px solid red;
display: flex;
flex-direction:column;
}
.main div.top {
border: 1px solid orange;
width:auto;
}
.main div.left {
border: 1px solid blue;
flex:1
}
.main div.right {
border: 1px solid green;
flex:1
}
.main__section2 {
display:flex
}
<html>
<body>
<div class="main">
<div class="main__section1">
<div class="top">
<h1>top</h1>
</div>
</div>
<div class="main__section2">
<div class="left">
<h1>left</h1>
</div>
<div class="right">
<h1>right</h1>
</div>
</div>
</div>
</body>
</html>
I'm quite new to web development and I would like to create this in CSS and HTML:
I am unsure how to do this as I am only 13 and still learning.
What I have tried but failed miserably with:
.grey{
height:300px;
width:700px;
background-color: #e5e5e5;
z-index: 0;
}
.pink{
height:150px;
width:100px;
background-color:#ff8a8a;
padding-top: 0px;
padding-right:0px;
z-index: 1;
}
<div class="grey">
<div class="pink"> </div>
</div>
Use CSS-grid which is built-in within CSS. See code snippet.
.wrapper {
display: grid;
grid-template-columns:
40%
1fr
1fr
;
grid-template-rows:
100px
100px
;
grid-template-areas:
"box-1 box-2 box-4"
"box-1 box-3 box-5"
;
}
.box-1 {
grid-area: box-1;
background-color: grey;
}
.box-2 {
grid-area: box-2;
background-color: orange;
}
.box-3 {
grid-area: box-3;
background-color: lightblue;
}
.box-4 {
grid-area: box-4;
background-color: red;
}
.box-5 {
grid-area: box-5;
background-color: lightgreen;
}
<div class="wrapper">
<div class="box-1"></div>
<div class="box-2"></div>
<div class="box-3"></div>
<div class="box-4"></div>
<div class="box-5"></div>
</div>
Using flex:
.container {
display: flex;
justify-content: flex-start;
background-color: #e5e5e5;
}
.box {
height:150px;
width: 50%;
display: flex;
flex-wrap: wrap;
}
.square {
height: 50%;
width: 50%;
}
.square--pink {
background-color: #fb7378;
}
.square--orange {
background-color: #fcbd8b;
}
.square--blue {
background-color: #8ce0fd;
}
.square--green {
background-color: #7cff83;
}
<div class="container">
<div class="box"></div>
<div class="box">
<div class='square square--pink'></div>
<div class='square square--orange'></div>
<div class='square square--blue'></div>
<div class='square square--green'></div>
</div>
</div>
You should look over the css box model btw, it would help you better understand how to structure your HTML for your css :).
.grey{
height:300px;
width:600px;
background-color: #e5e5e5;
z-index: 0;
}
.pink{
height:150px;
width:150px;
background-color:#ff8a8a;
padding-top: 0px;
padding-right:0px;
z-index: 1;
float:right;
}
.green{
height:150px;
width:150px;
background-color:green;
padding-top: 150px;
padding-right:0px;
z-index: 1;
float:right;
}
.skyblue{
height:150px;
width:150px;
background-color:skyblue;
padding-top: 0px;
padding-right:0px;
z-index: 1;
float:right;
}
.orange{
height:150px;
width:150px;
background-color:orange;
padding-top: 150px;
padding-right:0px;
z-index: 1;
float:right;
}
<div class="grey">
<div class="green">
<div class="pink">
</div>
</div>
<div class="orange">
<div class="skyblue">
</div>
</div>
</div>
Here's a quick example:
<div class="container">
<nav class="nav left">left</nav>
<nav class="nav right">right</nav>
<nav class="nav right1">right</nav>
</div>
CSS:
.container {
display: flex;
flex-flow: row;
min-height: 50vh;
}
.left {
flex: 5;
background-color: grey;
width: 70%;
}
.right {
flex:2;
background-color: green;
}
.right1 {
flex:2;
background-color: red;
}
here is your solution.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div { height: 102px; float:right; width: 150px;z-index: 2; }
.box{ width:600px;height:206px;background:grey;border:1px grey;z-index:0;float:left;}
.red { background: red; }
.green { background: green; }
.blue { background: blue; clear: right; }
.orange { background: orange; }
</style>
</head>
<body>
<div class="box">
<div class="red"></div>
<div class="green"></div>
<div class="blue"></div>
<div class="orange"></div>
</div>
</body>
</html>
With Flexbox, you can do something like this:
.grey {
display: flex; /* displays flex-items (children) inline */
justify-content: flex-end; /* places the flex-item (.innerFlex) to the end of the horizontal line */
height: 300px;
width: 700px;
max-width: 100%;
background: #e5e5e5;
}
.innerFlex {
display: flex;
flex-wrap: wrap; /* enables wrapping */
flex-basis: 200px; /* initial width set to 200px since its flex-items are 100px wide and you want them to wrap */
}
.pink {
flex-basis: 100px; /* initial width set to 100px */
height: 150px;
background: orange;
padding-top: 0;
padding-right: 0;
}
.pink:nth-child(2) {background: red}
.pink:nth-child(3) {background: blue}
.pink:nth-child(4) {background: green}
<div class="grey">
<div class="innerFlex"> <!-- additional wrapper -->
<div class="pink"></div>
<div class="pink"></div>
<div class="pink"></div>
<div class="pink"></div>
</div>
</div>
With the Grid:
.grey {
display: grid;
grid-template: 150px 150px / auto 100px 100px;
width: 700px;
max-width: 100%;
background: #e5e5e5;
}
.pink:nth-child(1) {grid-column: 2; background: orange}
.pink:nth-child(2) {background: red}
.pink:nth-child(3) {grid-column: 2; background: blue}
.pink:nth-child(4) {background: green}
<div class="grey">
<div class="pink"></div>
<div class="pink"></div>
<div class="pink"></div>
<div class="pink"></div>
</div>
I know that this question has already been asked several times but none of them seem to work for me or they're "too complicated" for my example.
I have three divs. Two of them are aligned vertically. The other one should be next to them and should have the same hight as the other two together.
It should look like this:
This is what I have so far:
.wrapper{
border: 1px solid red;
background-color: #fffdea;
width: 100%;
display: inline-block;
}
.icon{
border: 1px solid lightgreen;
width: 130px;
float: left;
height: 100%;
}
.info{
border: 1px solid aqua;
display: flex;
justify-content: space-between;
}
<div class="wrapper">
<div class="icon">
<p>Icon</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
</div>
Have a look at my fiddle
It's better to wrap your right side div(.info) with a parent div.
Try this one , it could help
.wrapper{
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex-direction: row;
justify-content: center;
border: 1px solid red;
background-color: #fffdea;
width: 100%;
padding: 10px;
}
.icon {
border: 1px solid lightgreen;
width: 30%;
}
.right-set {
width: 75%;
}
.info {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex-direction: row;
border: 1px solid aqua;
}
<div class="wrapper">
<div class="icon">
<p>Icon</p>
</div>
<div class="right-set">
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
</div>
</div>
try this
<div class="wrapper">
<div class="icon">
<p>Icon</p>
</div>
<div class="info-set">
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
</div>
</div>
.wrapper {
border: 1px solid red;
background-color: #fffdea;
width: 100%;
display: flex;
}
.icon {
border: 1px solid lightgreen;
width: 130px;
margin: 5px;
}
.info-set {
width: 100%;
}
.info {
border: 1px solid aqua;
display: flex;
justify-content: space-between;
margin: 5px 5px 5px 0;
}
Something needs to have a height set, either the wrapper or the icon. I also set height 50% of the info divs and changed box-sizing to border box for the contained elements.
.wrapper{
border: 1px solid red;
background-color: #fffdea;
width: 100%;
display: inline-block;
height: 130px;
}
.icon{
border: 1px solid lightgreen;
width: 130px;
float: left;
height: 100%;
box-sizing: border-box;
}
.info{
border: 1px solid aqua;
display: flex;
justify-content: space-between;
height: 50%;
box-sizing: border-box;
}
<div class="wrapper">
<div class="icon">
<p>Icon</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
</div>
Can be achieved using Flexbox and wrapping the info divs in a container.
<div class="wrapper">
<div class="icon">
<p>Icon</p>
</div>
<div class="info-container">
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
</div>
</div>
CSS :
.wrapper{
border: 1px solid red;
background-color: #fffdea;
width: 100%;
display: flex;
}
.icon{
border: 1px solid lightgreen;
width: 30%;
min-height: 100%;
box-sizing: border-box;
background: rgba(0, 0, 0, 0.2);
}
.info-container{
display: flex;
width: 70%;
box-sizing: border-box;
flex-direction: column;
}
.info{
border: 1px solid aqua;
}
You could also attempt to use css Grid.
.wrapper {
display: grid;
/*1fr unit is one fraction of the remaining space available. So I have divided the space into two tracks. One longer than the other*/
grid-template-columns: 1fr 5fr;
}
.icon {
background: #a03;
/*Run the icon div in two rows height but take one track width as the rest*/
grid-row: span 2;
}
.info {
background: #bccd03;
}
<div class="wrapper">
<div class="icon">
<p>Icon</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
<div class="info">
<p>Text</p>
<p>Number</p>
</div>
</div>
How can I make this grid without creating 2 columns?
Something like this?
* {
box-sizing: border-box;
}
.container {
width: 100%;
}
.left {
width: 66.66%;
height: 400px;
float: left;
background-color: blue;
}
.right {
width: 33.33%;
height: 200px;
float: right;
background-color: red;
border: thin solid black;
}
<div class="container">
<div class="left"></div>
<div class="right"></div>
<div class="right"></div>
</div>
Here is my flex box as you want ..
.vert_flex {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
border: 1px solid black;
}
.hor_flex {
display: flex;
flex-direction: row;
height: 100%;
width: 100%;
border: 1px solid black;
}
<div class="hor_flex">
<div style="flex : 2; height: 300px">width 66.6%</div>
<div class="vert_flex" style="flex : 1; height: 300px">
<div class="hor_flex" style="flex : 1">width 33.3%</div>
<div class="hor_flex" style="flex : 1">width 33.3%</div>
</div>
</div>
Flex makes life super easy..
.container {
display:flex;
}
.left {
flex:2;
background-color: #c1c1c1;
}
.container_right {display: flex;
flex: 1;
flex-direction:column}
.right {
flex:1;
background-color: #456456;
}
and the html..
<div class="container">
<div class="left">aaaaaaaaaaaa</div>
<div class="container_right">
<div class="right">bbbbbbbbbbbb</div>
<div class="right">cccccccccccc</div>
</div>
</div>
You just have to think of everything as a container.. everything inside that container can be flexed..
With Flex you need to avoid defining anything with px if possible. stick with units of
%
vw/vh r
rem/em
I'm stuck with wrong output.
Code:
<!DOCTYPE html>
<html>
<head>
<style>
.largebox { display: block; margin: 10px; border: 3px solid #73AD21; }
.box1 { display:inline-block; width:20%; height:200px; border:2px solid red; }
.box2 { display:inline-block; width:78%; height:100px; border:2px solid red; }
.col1 { display:inline-block; border:2px solid red; }
</style>
</head>
<body>
<div class="largebox"> <div class="box1">
<div class="leftbox"></div>
</div>
<div class="box2">
<div class="col1">float</div>
</div>
</body>
</html>
You can create this layout with Flexbox.
.largebox, .bottom, .box1 {
display: flex;
flex: 1;
}
.box2 {
flex: 3;
}
.box {
border: 1px solid black;
margin: 10px;
padding: 25px;
flex: 1;
}
<div class="largebox">
<div class="box1">
<div class="box">Div</div>
</div>
<div class="box2">
<div class="box">Div</div>
<div class="bottom">
<div class="box">Div</div>
<div class="box">Div</div>
<div class="box">Div</div>
</div>
</div>
</div>
This is how you can create same layout with inline-block, note that height on container is fixed.
* {
box-sizing: border-box;
}
.largebox {
height: 300px;
}
.bottom, .box1, .box2 {
display: inline-block;
vertical-align: top;
}
.box1 {
width: calc(30% - 10px);
height: 100%;
}
.box2 {
width: calc(70% - 10px);
height: 100%;
margin-left: 5px;
}
.box {
border: 1px solid black;
margin: 10px;
padding: 25px;
display: inline-block;
width: 100%;
height: 100%;
}
.box2 > .box {
height: 50%;
margin-bottom: 0;
width: calc(100% - 10px);
}
.bottom {
width: 100%;
height: 50%;
padding-bottom: 10px;
}
.bottom > .box {
width: calc(33.334% - 10px);
margin-right: 0;
}
<div class="largebox">
<div class="box1">
<div class="box">Div</div>
</div>
<div class="box2">
<div class="box">Div</div>
<div class="bottom">
<div class="box">Div</div><div class="box">Div</div><div class="box">Div</div>
</div>
</div>
</div>
I'd consider experiment with CSS property flex: https://developer.mozilla.org/en/docs/Web/CSS/flex
or use some grid templating system, e.g. Bootstrap https://getbootstrap.com/examples/grid/