I want to make a three columns layout for my website using flexboxes.
However, my 'commentCaMarche' div does not seem to follow the flex order, it is located at the top of the 'details-index' column. Do you know how to solve this problem?
#credits {
font-family: 'Roboto Condensed', sans-serif;
color: #FFFFFF;
height: 100vh;
background-color: #FB3D00;
margin-bottom: 0;
}
#columns {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
#details-index {
font-size: 1.6vmin;
text-align: center;
flex: 1;
order: 1;
display: flex; /*Note : Each of my columns is also a flex container for other contents I omitted*/
flex-direction: column;
justify-content: space-around;
}
(...)
#commentCaMarche {
font-size: 2vmin;
text-align: center;
flex: 1;
order: 2;
display: flex;
flex-direction: column;
justify-content: space-around;
}
(...)
#sources {
font-size: 1.4vmin;
text-align: center;
flex: 1;
order: 3;
display: flex;
flex-direction: column;
justify-content: space-around;
}
<div id='credits'>
<div id='columns'>
<div id='commentCaMarche'>
<h2>Comment ça marche</h2> (...)
</div>
<div id='details-index'>
<h2>Le détail</h2> (...)
</div>
<div id='sources'>
<h2>Sources des données</h2> (...)
</div>
</div>
</div>
Here is the css for making it responsive 3 column
#columns{width:100%; float:left;}
#commentCaMarche{width:33.33%; float:left}
#details-index{width:33.33%; float:left}
#sources{width:33.33%; float:left}
You need to change order property for your flex columns. JSfiddle
#details-index {
font-size: 1.6vmin;
text-align: center;
flex: 1;
order: 2;
display: flex; /*Note : Each of my columns is also a flex container for other contents I omitted*/
flex-direction: column;
justify-content: space-around;
}
#commentCaMarche {
font-size: 2vmin;
text-align: center;
flex: 1;
order: 1;
display: flex;
flex-direction: column;
justify-content: space-around;
}
The flex-wrap: wrap will make your columns break line when they doesn't fit the width available, so by removing it from the columns rule, you'll have 3 proper columns at any width.
I also temporarily removed the order from the flex items, so they show up in the same order they are placed in the markup, but if you need to change them like in your sample, please add it back, or why not simply swap them in the markup
#credits {
font-family: 'Roboto Condensed', sans-serif;
color: #FFFFFF;
height: 100vh;
background-color: #FB3D00;
margin-bottom: 0;
}
#columns {
display: flex;
justify-content: space-between;
}
#details-index {
font-size: 1.6vmin;
text-align: center;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-around;
}
#commentCaMarche {
font-size: 2vmin;
text-align: center;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-around;
}
#sources {
font-size: 1.4vmin;
text-align: center;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-around;
}
<div id='credits'>
<div id='columns'>
<div id='commentCaMarche'>
<h2>Comment ça marche</h2>
(...)
</div>
<div id='details-index'>
<h2>Le détail</h2>
(...)
</div>
<div id='sources'>
<h2>Sources des données</h2>
(...)
</div>
</div>
</div>
Related
I'm learning how to utilize flex and just started running into issues for after the flexbox is completed...
#initial {
display: flex;
flex: 1;
justify-content: space-evenly;
align-items: center;
width: 1200px;
margin-left: auto;
margin-right: auto;
border: 1px solid white;
}
#initial .menu {
display: flex;
flex: 1;
justify-content: space-evenly;
align-items: center;
margin: 15px auto 15px auto;
width: 1100px;
border: 1px solid rgba(245, 245, 245, 0.699);
border-radius: 50px;
line-height: 2rem;
font-size: 1.1rem;
overflow: hidden;
}
#initial .menu .menuItem {
display: flex;
flex: 1;
padding-top: 10px;
padding-bottom: 10px;
width: 100%;
text-align: center;
flex-direction: column;
flex-wrap: wrap;
align-content: space-around;
justify-content: space-evenly;
}
#initial .menu .menuItem:hover {
background-color: #FDB000;
color: black;
cursor: pointer;
display: flex;
flex: 1;
text-align: center;
flex-direction: column;
flex-wrap: wrap;
align-content: space-around;
justify-content: space-evenly;
}
<div id="initial">
<div class="menu">
<div id="initialMenuHeader" class="menuItem" onclick="menuCollapsable(this)">Δ</div>
<div id="initialMenuHVQ" class="menuItem" onclick="initialHVQ()">Hivecoin</div>
<div id="initialMenuRVN" class="menuItem" onclick="initialRVN()">Ravencoin</div>
<div id="initialMenuAVN" class="menuItem" onclick="initialAVN()">Avian</div>
</div>
<div class="body">
<h1>NAME OF POOL GOES HERE</h1>
<p class="intro">¡Intro crap will go here!</p>
</div>
</div>
As it stands, my .menu looks like this. Please note that the image is uncensored and includes expletives
Everything I could find online suggests that when the flex-box is completed, it should go back to the normal flow (e.g. not floating).
Please let me know what I'm doing wrong and/or missing.
JSFiddle of my code (added some things that I didn't include above like body for background-color and color
Since you make #initial as flex, and by default flex-direction set to row your menu align with with your body. If your want menu & body in 2 lines add below css:
#initial{
flex-direction: column;
}
I have divs that contain each individual arrow (one for the greater than text and another for the less than text). However, when I hover over the less than arrow, it pushes all the other elements to the right a bit. How can I have the hover effect not push any other elements away?
This is my HTML:
<div className="datepicker-wrapper">
<div className="dates">
<div className="arrows prev-month"><</div>
<div className="months">
<div className="start-month">February</div>
<div className="end-month">March</div>
</div>
<div className="days"></div>
<div className="arrows next-month">></div>
</div>
<div className="selected-dates">
<div className="check-in-date">02/13/2020</div>
</div>
</div>
And this is my CSS:
#import 'variables.css';
.datepicker-wrapper {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: flex-start;
width: 100%;
height: 50px;
background: transparent;
}
.datepicker-wrapper .dates {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
width: 60%;
height: 100%;
}
.datepicker-wrapper .selected-dates {
display: flex;
flex-direction: column;
cursor: default;
width: 40%;
height: 100%;
}
.datepicker-wrapper .dates .arrows .previous-month {
}
.datepicker-wrapper .dates .arrows:hover {
width: 15px;
height: 15px;
background: var(--light-gray);
border-radius: 50%;
cursor: pointer;
}
.datepicker-wrapper .dates .months {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
NOTE
I've tried giving the arrows prev-month div a set width, but that doesn't seem to have any effect.
You give the width and height only on hover.. try to give the styles to the arrows anyway, and on hover only change the background-color
.datepicker-wrapper {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: flex-start;
width: 100%;
height: 50px;
background: transparent;
}
.datepicker-wrapper .dates {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
width: 60%;
height: 100%;
}
.datepicker-wrapper .selected-dates {
display: flex;
flex-direction: column;
cursor: default;
width: 40%;
height: 100%;
}
.datepicker-wrapper .dates .arrows {
width: 15px;
height: 15px;
border-radius: 50%;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.datepicker-wrapper .dates .arrows:hover {
background: #c1c1c1;
}
.datepicker-wrapper .dates .months {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
<div class="datepicker-wrapper">
<div class="dates">
<div class="arrows prev-month"><</div>
<div class="months">
<div class="start-month">February</div>
<div class="end-month">March</div>
</div>
<div class="days"></div>
<div class="arrows next-month">></div>
</div>
<div class="selected-dates">
<div class="check-in-date">02/13/2020</div>
</div>
</div>
Setting the styles on :hover impacts the CSS box model for the .arrows element:
All four of those impact the overall space an element takes.
I would like to align the content in the 2nd column to look like this:
Currently, it is looking like this:
I believed it has got to do with my flex-grow, flex-shrink and flex-basis. but I am not sure. Here is the JSFiddle. https://jsfiddle.net/onestaryx/c70yg2t9/2/
.work-meta-row{
display: flex;
flex-direction: row;
align-items: flex-start;
align-self: flex-start;
justify-content: flex-start;
line-height: 22px;
flex-wrap: nowrap;
.work-meta-label{
font-weight: bold;
flex-basis: 200px;
}
.work-meta-value{
flex-grow:1;
}
}
This will do the trick:
.work-meta-row{
display: flex;
flex-direction: row;
align-items: flex-start;
align-self: flex-start;
justify-content: flex-start;
line-height: 22px;
flex-wrap: nowrap;
.work-meta-label{
font-weight: bold;
flex: 0 0 200px;
}
}
flex grow and flex shrink are ON i.e. 1 by default. You need to disable it to match the UI you require. This is how you can do it:
`.work-meta-row {
display: flex;
line-height: 22px;
.work-meta-label {
font-weight: bold;
flex-grow: 0;
flex-shrink: 0;
flex-basis: 100px;
}
}`
OR use with the flex shorthand like:
`.work-meta-row {
display: flex;
line-height: 22px;
.work-meta-label {
font-weight: bold;
flex: 0 0 100px;
}
}`
I am trying to make a moviepage using flexbox. I have three images in one flexbox, but I can't get them to come on top of each other, they will only place next to each other. Any tips? And btw, I am not making the page responsive yet.
CSS
/*FLEXBOKS*/
.flex-container{
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
align-items: center;
align-content: center;
margin: 100px;
}
.flex-item1{
order: <integer>;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
align-self: stretch;
background-color: #B0B0B0;
}
.flex-item2{
order: <integer>;
flex-grow: 2;
flex-shrink: 1;
flex-basis: auto;
align-self: baseline;
background-color: #B0B0B0;
}
.flex-item3{
order: <integer>;
flex-grow: 2;
flex-shrink: 1;
flex-basis: auto;
align-self: baseline;
background-color: #B0B0B0;
}
.flex-item4{
order: <integer>;
flex-grow: 2;
flex-shrink: 1;
flex-basis: auto;
align-self: baseline;
background-color: orange;
}
HTML
<div class="flex-container">
<div class="flex-item1">
<h2>NEW MOVIES</h2>
<img src="The_Intouchables_3.jpg" width="200" height="250">
<img src="The_Lunchbox_1.jpg" width="200" height="250">
<img src="montypythonandtheholygrail_1.jpg" width="200" height="250">
</div>
<div class="flex-item2">LAST RENTED</div>
<div class="flex-item3">RECOMMENDATIONS</div>
<div class="flex-item4">RULES</div>
</div>
Set to the flex container the css rule
flex-direction: column;
You can use following CSS
.flex-container{
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: center;
align-items: center;
align-content: center;
margin: 100px;
}
I am using flex for making a searchbar/input element stay centered and change width as the screen size changes.
This is my html:
<div class="flex-container">
<div class="flex-row">
<h1 class="brandname">Hello</h1>
</div>
<div class="flex-row">
<form>
<!-- <div class="search centered"> -->
<div class="search">
<div class="input-container">
<input type="text" name="query" class="searchbar" />
<button type="submit" class="search-button">Search</button>
</div>
</div>
</form>
</div>
</div>
and this is my css:
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
.flex-container{
display: flex;
display: -webkit-flex;
align-items: center;
-webkit-align-items: center;
justify-content: center;
-webkit-justify-content: center;
-webkit-flex-direction: row;
flex-direction: row;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
}
.flex-row {
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 1;
}
form{
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 1;
}
.search{
display: flex;
display: -webkit-flex;
flex: 0 1 455px;
-webkit-flex: 0 1 455px;
}
.input-container{
display: flex;
display: -webkit-flex;
flex: 1;
-webkit-flex: 1;
min-width: 0;
}
.searchbar{
flex: 1;
-webkit-flex: 1;
min-width: 0;
}
.flex-container > .flex-row:first-child{
flex: 0 1 100%;
-webkit-flex: 0 1 100%;
}
.brandname {
position: relative;
font-size: 500%;
font-family: 'Lato', sans-serif;
color: #1f0e3e;
text-align: center;
margin-bottom: 30px;
margin-top: 5%;
}
body {
margin: 10px;
}
.input-container{
/*float: left;*/
/*display: block;*/
flex: 1;
-webkit-flex: 1;
outline-style: solid;
outline-color: #e3e3e3;
outline-width: 1px;
}
.searchbar{
margin-left: 5px;
}
.search button {
background-color: rgba(152,111,165,0.38);
background-repeat:no-repeat;
border: none;
cursor:pointer;
border-radius: 0px;
/*overflow: hidden;*/
outline-width: 1px;
outline-style: solid;
outline-color: #e3e3e3;
color: white;
}
.search input{
outline-width: 0px;
outline-style: none;
border-width: 0px;
}
and it works in chrome, ie edge and in this fiddle, but not in safari.
In Safari the searchbar goes above the .brandname element and to the right of it and takes a width of 150px.
any ideas on how to make this work in safari?
One thing that is not working is the the first flex row width of 100% is not working. In safari it is making the two felx-row elements be right next to each other and both of them together are taking 100% of the width.
I changed .flex-row css rules to:
.flex-row {
display: flex;
display: -webkit-flex;
justify-content: center;
-webkit-justify-content: center;
flex: 1;
-webkit-flex: 0 1 100%;
}
and changed the flex-row first child css rules to:
.flex-container > .flex-row:first-child{
flex: 0 1 100%;
-webkit-flex: 0 1 auto;
}
and then it works.
I thought about doing this after reading that flex-wrap is buggy in safari from this SO question which suggests that setting flex-wrap in safari is buggy
Always use the non-prefixed setting last in your CSS rules. In your first rule that would be:
.flex-container{
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
similar for all other rules.