display flex - keeping last element in full width - html

I am trying to keep my 3d element with full width of the flex container. but not getting the reuslt. any one suggest me the right way for ie11 here?
.parent{
border:1px solid red;
display:flex;
justify-content:space-between;
padding:0 40px;
}
.child{
flex:0 0 30%;
border:1px dashed green;
}
.child.last{
/* not working */
width:100%;
}
<div class="parent">
<div class="child">one</div>
<div class="child">two</div>
<div class="child last">three</div>
</div>

To enable for the last child to wrap and be 100% wide, add flex-wrap: wrap to parent and use flex-basis on last child.
.parent{
border:1px solid red;
display:flex;
flex-wrap: wrap;
justify-content:space-between;
padding:0 40px;
}
.child{
flex:0 0 30%;
border:1px dashed green;
}
.child.last{
flex-basis: 100%;
}
<div class="parent">
<div class="child">one</div>
<div class="child">two</div>
<div class="child last">three</div>
</div>

To make the last child 100%-width only after wrapping...
Use flex: 1:
The flex property specifies the length of the item, relative to the rest of the flexible items inside the same container. It makes the flex item flexible and sets the flex basis to zero, resulting in an item that receives the specified proportion of the remaining space.
.parent{
border:1px solid red;
display:flex;
justify-content:space-between;
padding:0 40px;
}
.child{
flex:0 0 30%;
border:1px dashed green;
}
.child.last{
width:100%;
/* SOLUTION */
flex: 1;
}
<div class="parent">
<div class="child">one</div>
<div class="child">two</div>
<div class="child last">three</div>
</div>

Related

align-items : what is the difference between flex-start and Stretch?

can you please tell me align-items : what is the difference between flex-start and Stretch?
.container {
height: 500px;
padding: 10px;
margin: 50px auto;
background: #eee;
display: flex;
align-items: flex-end
}
.container .box {
padding: 10px;
width: 200px;
height: 200px;
background-color: #fff;
}
<div class="container">
<div class="box"></div>
</div>
You will see no difference if you set a height to your element.
stretch
Flex items are stretched such that the cross-size of the item's margin box is the same as the line while respecting width and height constraints.ref
In your case, nothing will happen with stretch because of the height you set.
flex-start
The cross-start margin edges of the flex items are flushed with the cross-start edge of the line. ref
This is simply align the item on the top. Again, nothing will happen visually since it's somehow the default behavior (not the default value).
.container {
display:inline-flex;
width:200px;
height:200px;
border:2px solid;
}
.container > span {
width:100px;
height:100px;
background:red;
}
<div class="container" style="align-items:flex-start">
<span></span>
</div>
<div class="container" style="align-items:stretch">
<span></span>
</div>
Now remove the height constraint and you will see the difference:
.container {
display:inline-flex;
width:200px;
height:200px;
border:2px solid;
vertical-align:top;
}
.container > span {
width:100px;
min-height:100px;
background:red;
}
<div class="container" style="align-items:flex-start">
<span></span>
</div>
<div class="container" style="align-items:stretch">
<span></span>
</div>

Overflow with flex-basis and min and max-width

My goal is to use flexbox to implement a slider that has a given width and can grow as items(images) are added into it, until a specific width is reached. After that width is reached i want to show a scrollbar on the x axis. I also want the slider not to shrink bellow the min-width.
This is what i tried:
HTML:
<div class="wrapper">
<div class="thisDivAllowsSliderToGrowToMaxWidth">
<div class="slider">
<div class="image"></div>
...
</div>
</div>
</div>
CSS:
.wrapper {
height: 400px;
display: flex;
justify-content: center;
align-items:center
}
.slider {
display:flex;
justify-content:flex-start;
height:100px;
flex-basis: 250px;
min-width:200px;
max-width:350px;
overflow-x:auto;
}
.image {
flex-shrink:0;
height:100px;
width:50px;
}
The issue that pops out is that as soon as overflow-x is added to the slider, it does not grow anymore but shows the scrollbar as soon as flex-basis width is reached.
Interestingly, adding a simple wrapping div (.thisDivAllowsSliderToGrowToMaxWidth) around the slider somehow fixes the issue. You can find the example here.
Can anyone answer why is this happening and am I using the flex properties as intended?
To make the flex container grow based on the width of the flex items, you can set the flex-basis to content
content will automatically size based on the flex item's content
$(".add-slide").on("click",function(){
$(".slider").append('<div class="image"></div>');
});
.wrapper {
height: 300px;
border :1px solid red;
display: flex;
justify-content: center;
align-items:center
}
.slider {
display:flex;
border: 1px solid black;
height:100px;
flex-basis: content;
min-width:200px;
max-width:350px;
overflow-x:auto;
overflow-y:hidden;
}
.image {
flex-shrink: 0;
border: 1px solid green;
height:100px;
width:50px;
}
button {
margin-bottom: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="add-slide">add slide</button>
<div class="wrapper">
<div class="slider">
<div class="image"></div>
</div>
</div>

Flexbox + overflow:hiddden works only in Chrome

I am having problem with contents of my left sidebar not respecting overflow:hidden anywhere other than Chrome browser.
In Firefox, IE and Edge sidebar is extended instead of being limited to 300 pixels of .container div. Does anyone know how to fix this behavior?
https://jsfiddle.net/o1uu1d0L/2/
Try to change
.flex-fill {
display:flex;
flex:1 1 auto;
}
to
.flex-fill {
display:flex;
min-height: 0;
flex:1 1 0%;
}
I think there are two reasons why this problem occurs:
The first problem is that IE does not accept unitless flex-basis. That's why you have to use flex: 1 1 0% or flex: 1 1 0px but not flex: 1 1 0. And flex: 1 1 auto did not work in this case as well.
The second problem is different interpretation of display: flex in Chrome and Firefox. Firefox, by default, sets min-height: auto; min-width: auto; on display: flex elements and Chrome sets it as min-height: 0; min-width: 0. And what you need is second option.
I'm not sure if that simple change will solve all your problems (but it looked ok when i tested it on IE and Firefox). If not, please think about what I wrote and make similar changes in other classes. I hope it will help!
your codes with a few changes :
<div class="container">
<div class="flex-col flex-fill">
<div class="flex-row flex-fill">
<div class="flex-col flex-50 dragscroll default-box" style="margin-right:5px;">
<div class="button selected">1</div>
<div class="button">2</div>
<div class="button selected">3</div>
<div class="button">4</div>
<div class="button">5</div>
<div class="button selected">6</div>
<div class="button selected">7</div>
<div class="button">8</div>
<div class="button">9</div>
<div class="button">10</div>
</div>
<div class="flex-fill default-box">
center
</div>
<div class="flex-250 default-box" style="margin-left:5px;">
side
</div>
</div>
<div class="default-box flex-50" style="margin-top:5px;">
bottom
</div>
</div>
</div>
.container {
width:500px;
height:300px;
display:flex;
flex-flow:column;
background:lightblue;
}
.buttons-container {
min-height:1px;
height:100%;
flex:0 1 50px;
border:1px solid #CCC;
background:#FFF;
margin-right:5px;
overflow:hidden;
display:flex;
flex-flow:column;
}
.flex-col {
display:flex;
flex-flow:column;
overflow:hidden;
}
.flex-row {
display:flex;
flex-flow:row;
overflow:hidden;
}
.flex-fill {
display:flex;
flex:1 1 auto;
}
.flex-50 {
display:flex;
flex:0 0 50px;
}
.flex-250 {
display:flex;
flex:0 0 250px;
}
.default-box {
background:#FFF;
border:1px solid #CCC;
}
.plot-area {
display:block;
position:relative;
flex:1 1 auto;
background:#FFF;
border:1px solid #CCC;
box-shadow:1px 1px 4px rgba(0,0,0,0.1);
}
.button {
background:#cfeceb;
vertical-align:middle;
margin-bottom:5px;
text-align:center;
color:#56b6b2;
cursor:pointer;
font-size:26px;
flex:1 1 auto;
display:flex;
flex-direction:column;
justify-content:center;
min-height:50px;
}
.button.selected {
background:#56b6b2;
color:#FFF;
}
.button:last-child {
margin:0 !important;
}

align content-div element inside of wrapper-div

I have struggled to align content-div elements of a wrapper-div using only CSS with the following restriction.
The wrapper div can have a row which allows multiple content-div elements be on the row
At most 4 content-div elements can exist on a row of the wrapper div.
Content-div elements of the last row must expand to fill the row. (e.g if 3 content-div elements exist on the last row, then the width of each content-div should be 33.3%)
One and only one content-element always is selected, and the selected element should be bottom-left conner of the wrapper-div element.
To handle this, I have tried the following css.
.wrapper{
width:100%;
}
.content{
max-width:100%;
min-width:25%;
background-color:white;
float:right;
}
.content.selected{
position:absolute;
top:100%;
left:0;
float:left;
background-color:yellow;
}
I thought that the "float:right; float:left position:absolute; top:100%; left:0;" option can handle the restriction 1 and restriction 4, the "min-width:25%" option can handle the restriction 2 and the "max-width:100%" option can handle the restriction 3. However, only a few restriction were satisfied through the CSS.
I have setup jsFiddle example:
https://jsfiddle.net/6qyc5kLw/2/
I would help in this regard.
This image is what I want to do.
ever considered display:flex? its HUGE!
.wrapper{
width:100%;
position:relative;
display: flex;
flex-flow:row wrap;
align-items: stretch;
}
.content{
min-width:25%;
background-color:white;
//float:right;
flex:1;
order:1;
}
.content.selected{
//position:absolute;
//top:100%;
//left:0;
//float:left;
background-color:yellow;
order:-1;
}
The new flexbox possibilities are most certainly what you are looking for. See below snippet or https://jsfiddle.net/6qyc5kLw/3/ for an updated demo with some basic flexbox properties. An additional one would be
flex-order (to reverse the order of elements in first row)
.wrapper{
width:100%;
position:relative;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.content{
flex-basis: 25%;
background-color:white;
border: 1px solid #ccc;
flex-grow: 1;
box-sizing: border-box;
}
.content.selected{
align-self: flex-end;
background-color:yellow;
}
<body>
<div class="wrapper">
<div class="content">
1
</div>
<div class="content">
2
</div>
<div class="content">
3
</div>
<div class="content">
4
</div>
<div class="content selected">
5
</div>
<div class="content">
6
</div>
<div class="content">
7
</div>
</div>
</body>
You can use display: flex
.wrapper{
width:100%;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.content{
background:#fff;
box-flex: 1;
min-width:25%;
flex: 1;
margin: auto;
}
.content.selected{
background-color:yellow;
}
<div class="wrapper">
<div class="content">1</div>
<div class="content">2</div>
<div class="content">3</div>
<div class="content">4</div>
<div class="content selected">5</div>
<div class="content">6</div>
<div class="content">7</div>
</div>
Here is exactly what you want in example picture:
.wrapper{
width:100%;
position:relative;
}
.content{
max-width:100%;
min-width:25%;
background-color:white;
float:right;
border: 1px solid black;
box-sizing: border-box;
}
.content.selected{
background-color:yellow;
float: left;
width: 33.33%;
}
.content:nth-child(6) {
float: right;
width: 33.33%;
}
.content:nth-child(7) {
float: left;
width: 33.33%;
}
<body>
<div class="wrapper">
<div class="content">
1
</div>
<div class="content">
2
</div>
<div class="content">
3
</div>
<div class="content">
4
</div>
<div class="content selected">
5
</div>
<div class="content">
6
</div>
<div class="content">
7
</div>
</div>
</body>

flexbox size not the same for all items

In the fiddle below the first 2 items display next to each other in a row, but as there's only 3 items the 3rd displays with 100%.
I would like this to keep the same width as the other 2 items leaving a blank space where there is no item.
I have also set the width of these items to 40% and it is displays as 50% each with a 10px margin which is fine but I was under the impression you needed flex: 1 auto; to set the width in this way. however doing that would mean all boxes would display with 100% when pulling from a DB.
https://jsfiddle.net/ffr9rhrw/
html
<div class="container">
<div class="main">
<div class="rev-col">
<div class="reviews-main-wrap">
<div class="reviews-main-img"><img class="u-full-width" src="../../images/reviews/{{ $review->img }}" ></div>
<div class="reviews-main-header"><h6>{!! $review->header !!}</h6></div>
<div class="reviews-main-price">Price £££</div>
<div class="reviews-main-content">{!! str_limit($review->content, $limit = 100) !!}</div>
<div class="reviews-readmore">Read More</div></a>
</div>
</div>
<div class="rev-col">
<div class="reviews-main-wrap">
<div class="reviews-main-img"><img class="u-full-width" src="../../images/reviews/{{ $review->img }}" ></div>
<div class="reviews-main-header"><h6>{!! $review->header !!}</h6></div>
<div class="reviews-main-price">Price £££</div>
<div class="reviews-main-content">{!! str_limit($review->content, $limit = 100) !!}</div>
<div class="reviews-readmore">Read More</div></a>
</div>
</div>
<div class="rev-col">
<div class="reviews-main-wrap">
<div class="reviews-main-img"><img class="u-full-width" src="../../images/reviews/{{ $review->img }}" ></div>
<div class="reviews-main-header"><h6>{!! $review->header !!}</h6></div>
<div class="reviews-main-price">Price £££</div>
<div class="reviews-main-content">{!! str_limit($review->content, $limit = 100) !!}</div>
<div class="reviews-readmore">Read More</div></a>
</div>
</div>
</div>
<!-- sidebar content -->
<div class="sidebar">
#yield('sidebar')
</div>
</div>
css
.container { display:flex; flex-flow: row wrap; max-width:1200px; margin:0 auto; padding: 0 10px;}
.header { flex: 1 100%; height:50px; background-color:#ff00ff;}
.main {display:flex; flex-flow: row wrap; flex:1; background-color:; }
.sidebar { flex: 0 250px; margin-left:10px;background-color:#ec2350; }
.center { -webkit-justify-content: center; justify-content: center; }
.rev-wrap{ display:flex; flex-flow: row wrap; background-color:#ececec;}
.rev-col:first-child{flex:1 40%; margin-left:0px; background-color:#ff00ff;}
.rev-col{flex:1 40%; margin-left:10px; background-color:#ff00ff;}
.rev-column:nth-child(odd){ flex:1 40%; margin-left:0px; background-color:#ff00ff;}
.rev-header{flex:1 auto; height:auto; padding:10px;background-color:#ff0000;}
.reviewscontainer { width: 100%; height:auto; margin: 0 auto; background-color:#f9f9f9; color:#2c3e50; }
.reviews-main-wrap{border:0px solid #ccc;height:auto; margin-bottom:2%; ov
Regarding '.rev-column:nth-child(odd)' not removing margin. That is because your element has a class name 'rev-col'.
This means the CSS should be
.rev-col:nth-child(odd){ ... }
I don't get what exactly you want to do,
First thing i don't think this style [flex:1 250px] is correct, you should use [flex:1 Auto; max-width:250px] other incorrect styles you'r using are [flex:1 40%], the correct way to go is [flex:1] or [flex:1 1 Auto] or [flex:1 1 0]... so on (You get the picture!).
Now, Since the container is [display:felx] then this div container should be filled with it's contained element.So, one way to go is simply to add another div in order to fill the blank space,Another way to go is to set the container to [display:inline-flex] this will cause the container div to align to the left and set its size according to its content.
Another way which i think will answer your needs the best is just to set max-width for both left columns and their container, this will prevent them from growing more then expected.
.main {display:flex; max-width:600px; flex-flow: row wrap; flex:1; background-color:; }
.rev-col:first-child{flex:1; max-width:300px; margin-left:0px; background-
color:#ff00ff;}
.rev-col{flex:1; max-width:300px; margin-left:10px; background-color:#ff00ff;}
.rev-col:nth-child(odd){ flex:1; max-width:300px; margin-left:0px; background-color:#ff00ff;}
https://jsfiddle.net/wtesnrp7/