How to fix height: auto with flexbox in Firefox? [duplicate] - css

This question already has answers here:
Why doesn't percentage padding / margin work on flex items in Firefox and Edge?
(2 answers)
Closed 5 years ago.
I have a problem with flexbox and height: auto in Firefox:
.portfolio {
width: 100%;
position: relative;
overflow: visible;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
background-color: red;
}
.portfolio a {
display: block;
background-color: black;
width: 30%;
height: auto;
padding-top: 30%;
/* 1:1 Aspect Ratio */
position: relative;
/* If you want text inside of it */
margin-bottom: 5%;
}
<div class="portfolio">
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
</div>
When div .portfolio have height: auto, in Firefox this div is not visible. Chrome, Safari and others works fine... I really don't have idea how to make this working... anyone?

.portfolio has no height by default. Setting the height to auto will do nothing in this case.
Setting height: 30%; to .portfolio's children will do nothing, because the logic of that goes: take up 30% of the parent's height, which is 0. Again, if you set .portfolio a's height to 30vh (30% of the viewport height) That would work, or if you could give it a pixel value
In the example below, I've set the height to 100px but obviously you can change it to whatever you want.
.portfolio {
width: 100%;
height: 100px;
position: relative;
overflow: visible;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
background-color: red;
}
.portfolio a {
display: block;
background-color: black;
width: 30%;
height: auto;
padding-top: 30%;
/* 1:1 Aspect Ratio */
position: relative;
/* If you want text inside of it */
margin-bottom: 5%;
}
<div class="portfolio">
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
<a href="#">
<div class="portfolio_item">
</div>
</a>
</div>

Related

I need centering flexbox columns in conteiner

My 3 images need to be in screen center. I use flexbox. After adding size to images all of them go to left. Also I can't throw off margin
This is what I need
This is what I have
My cod:
.collection {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
}
<ul class="collection">
<li><img class="col-img" src="images/bouquets.jpeg" alt=""><p class="col-text">Букети</p></li>
<li><img class="col-img" src="images/natural_flowers.jpeg" alt=""><p class="col-text">Живі квіти</p></li>
<li><img class="col-img" src="images/own_bouquet.png" alt=""><p class="col-text">"Свій" букет</p></li>
</ul>
This can be solved by absolutely positioning your p tag on top of your image. Use translate and top/left rules to move it to the center. Also make the a tag as display:block so it effectively covers the image. See below.
Edited:
There were a few small tweaks, the a tag had a 3 pixels below it which are space for descenders. This has been removed using line-height and means that images stack directly on top of each other. In the comments it was also stated that the images needed to be cropped and centered. This was done with display: flex on the anchor tag and then using align-self: center to prevent it from shrinking to the size of the parent div. Finally they were cropped using overflow:hidden. Now that the anchor tag is using flexbox the need to use inset and translate isn't needed as they center anyway.
Hope this helps
.collection {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
padding-left: 0;
}
a {
display: flex;
align-items: center;
justify-content: center;
position: relative;
color: white;
line-height:1;
height: 200px;
overflow: hidden;
box-shadow: 0px 0px 20px 2px #757575;
}
a p {
position: absolute;
background-color: #A6BFEA;
padding: 1rem 2rem;
margin: 0;
box-shadow: 0px 0px 20px 2px #757575;
line-height:normal;
}
img {
align-self:center;
translate: auto -50%;
}
<ul class="collection">
<li>
<a href="#">
<img class="col-img" src="https://placekitten.com/500/300" alt="">
<p class="col-text">Букети</p>
</a>
</li>
<li>
<a href="#">
<img class="col-img" src="https://www.fillmurray.com/500/300" alt="">
<p class="col-text">"Свій" букет</p>
</a>
</li>
<li>
<a href="#">
<img class="col-img" src="https://www.placecage.com/500/300" alt="">
<p class="col-text">"Свій" букет</p>
</a>
</li>
</ul>
.collection {
list-style: none;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
Something like this?
li {
margin-bottom: 3rem;
}
.collection {
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.container p {
position: absolute;
background: green;
color: white;
}
<ul class="collection">
<li>
<a href="#">
<div class="container">
<img class="col-img" src="https://dummyimage.com/300x150/000/fff" alt="">
<p class="col-text">Букети</p>
</div>
</a>
</li>
<li>
<a href="#">
<div class="container">
<img class="col-img" src="https://dummyimage.com/300x150/000/fff" alt="">
<p class="col-text">Букети</p>
</div>
</a>
</li>
<li>
<a href="#">
<div class="container">
<img class="col-img" src="https://dummyimage.com/300x150/000/fff" alt="">
<p class="col-text">Живі квіти</p>
</div>
</a>
</li>
</ul>

css flex - make gap between divs

When in a landscape mode, I need to separate/make a gap (around 10-20px) between the two columns without using a border or anything like that. I tried everything and it still doesn't work, what am i missing? I tried putting margins, but it doesn't help, what's the best way to solve this?
#media screen and (min-width: 567px) {
.container {
display: flex;
flex-flow: row wrap;
}
.container li {
flex-basis: 50%;
max-width: 50%;
}
}
.item {
display: flex;
align-items: center;
padding-top: 5px;
}
.title {
font-weight: 500;
font-size: 22px;
padding-bottom: 18px;
}
.item-image {
flex-basis: 85px;
min-width: 85px;
padding-bottom: 30px;
}
.item .item-image img {
display: inline-block;
vertical-align: middle;
border-radius: 20px;
width: 100%;
}
.item .item-info {
border-bottom: 1px solid rgb(207, 206, 206);
padding-bottom: 20px;
flex-basis: 100%;
margin-left: 15px;
}
<ul class="container">
<li>
<div class="item">
<div class="item-image">
<a href="">
<img src="root-icon.png" alt="">
</a>
</div>
<div class="item-info">
<div class="item-title">Something</div>
<div class="item-subtitle">Something</div>
<div class="item-button-container">
<a class="button" href="#">GET</a>
</div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="item-image">
<a href="">
<img src="root-icon.png" alt="">
</a>
</div>
<div class="item-info">
<div class="item-title">Something</div>
<div class="item-subtitle">Something</div>
<div class="item-button-container">
<a class="button" href="#">GET</a>
</div>
</div>
</div>
</li>
</ul>
Just add something like gap: 5px to your container with flex layout
Thanks to #AbsoluteBeginner this feature is supported not everywhere. See here: https://caniuse.com/flexbox-gap
Add margin-right to the element if you want to stick to flexbox.
Otherwise - try out css grid, super easy with grid-gap to add the gap you need.
https://www.w3schools.com/css/css_grid.asp
You can add this CSS rule:
ul.container > *:nth-child(odd) .item-info {
margin-right: 50px;
}
It adds a right marging to every odd .item-info (or more precisely: to every .item-info inside every odd direct child element of the .container element)
#media screen and (min-width: 567px) {
.container {
display: flex;
flex-flow: row wrap;
}
.container li {
flex-basis: 50%;
max-width: 50%;
}
}
.item {
display: flex;
align-items: center;
padding-top: 5px;
}
.title {
font-weight: 500;
font-size: 22px;
padding-bottom: 18px;
}
.item-image {
flex-basis: 85px;
min-width: 85px;
padding-bottom: 30px;
}
.item .item-image img {
display: inline-block;
vertical-align: middle;
border-radius: 20px;
width: 100%;
}
.item .item-info {
border-bottom: 1px solid rgb(207, 206, 206);
padding-bottom: 20px;
flex-basis: 100%;
margin-left: 15px;
}
ul.container > *:nth-child(odd) .item-info {
margin-right: 50px;
}
<ul class="container">
<li>
<div class="item">
<div class="item-image">
<a href="">
<img src="root-icon.png" alt="">
</a>
</div>
<div class="item-info">
<div class="item-title">Something</div>
<div class="item-subtitle">Something</div>
<div class="item-button-container">
<a class="button" href="#">GET</a>
</div>
</div>
</div>
</li>
<li>
<div class="item">
<div class="item-image">
<a href="">
<img src="root-icon.png" alt="">
</a>
</div>
<div class="item-info">
<div class="item-title">Something</div>
<div class="item-subtitle">Something</div>
<div class="item-button-container">
<a class="button" href="#">GET</a>
</div>
</div>
</div>
</li>
</ul>

Is it possible to set the width of siblings elements based from the longest element in css

I have a request to set the width of buttons to the longest sibling in a row of buttons.
Rules:
Buttons sit in columns of a row
Button content dictate the width of button.
The longest button should set other sibling button's width
I've tried using flex: 1 with max/min-width however this will break rule 2. And I can easily do this in js I'm wondering if possible in css alone?
https://codepen.io/matthewharwood/pen/JvoVzE?editors=1100
.link {
height: 49px;
padding: 0 24px;
margin-right: 20px;
background: pink;
a {
display: flex;
align-items: center;
line-height: 49px;
justify-content: center;
}
}
.container {
width: 70%;
margin: 0 auto;
background: papayawhip;
padding: 30px;
display: flex;
}
.container2 {
width: 70%;
margin: 0 auto;
background: orange;
padding: 30px;
display: flex;
flex-wrap: wrap;
}
.container3 {
width: 70%;
margin: 0 auto;
background: honeydew;
padding: 30px;
display: flex;
flex-wrap: wrap;
}
<div class="container">
<div class="link">
<span> 1 button</span>
</div>
<div class="link">
<span> secondary button</span>
</div>
</div>
<div class="container2">
<div class="link">
<span> 1 button</span>
</div>
<div class="link">
<span> secondary button</span>
</div>
<div class="link">
<span> third button</span>
</div>
</div>
<div class="container3">
<div class="link">
<span> 1 button</span>
</div>
<div class="link">
<span> 2 button</span>
</div>
</div>
Important Notice: the solution below is a hack.
The idea here is to rely on direction column and inline-flex to have all element equal width (the longest one) then I use transformation in order to revert back the row direction.
I know it's a bad hack
.link {
height: 49px;
padding: 0 24px;
background: pink;
border:1px solid;
}
.container {
padding: 30px;
display: inline-flex;
flex-wrap:wrap;
flex-direction:column;
}
.link:nth-child(2) {
transform:translate(100%,-100%);
}
.link:nth-child(3) {
transform:translate(200%,-200%);
}
.link:nth-child(4) {
transform:translate(300%,-200%);
}
<div class="container">
<div class="link">
<span> 1 button</span>
</div>
<div class="link">
<span> secondary button</span>
</div>
</div>
<br>
<div class="container">
<div class="link">
<span> 1 button</span>
</div>
<div class="link">
<span> secondary button</span>
</div>
<div class="link">
<span> third button</span>
</div>
</div>
<br>
<div class="container">
<div class="link">
<span> 1 button</span>
</div>
<div class="link">
<span> 2 button</span>
</div>
</div>

footer div elements overlapping

Im having a problem with my footer ( started learning css two days ago).this is the bottom of my page:
https://gyazo.com/b681e5ca06f7f89bac727ea20a1ff3dd
now i want the links to stick to the bottom without manipulating margins seperately for each div. So i tried to make the parent div have position:relative and the insider element have position:absolute.
what happens is this:
https://gyazo.com/0031cbb528e4c80600f1533f4b60993d
the relevant code for CSS:
.footer {
width: 100%;
height: 200px;
float: left;
position: relative;
display: inline-block;
}
.infotype {
float: left;
display: inline-block;
color: black;
width: 30%;
margin-left: 30px;
bottom: 0 auto;
position: absolute;
}
relevant code for HTML:
<section class="row">
<div class="footer">
<div class="infotype data">
<h3>Rockets and spacecraft</h3>
Falcon 9<br>
<a class="info" href="#">Falcon Heavy</a><br>
<a class="info" href="#">Dragon</a>
</div>
<div class="infotype updates">
<h3>Updates</h3>
<a class="info" href="#">News</a><br>
<a class="info" href="#">Launch Manifest</a>
</div>
<div class="infotype about">
<h3>About SpaceX</h3>
<a class="info" href="#">Company</a><br>
<a class="info" href="#">Careers</a><br>
<a class="info" href="#">Gallery</a><br>
<a class="info" href="#">Shop</a>
</div>
</div>
</section>
sorry for my poor formatting skills, like i mentioned im new here.
I have removed the floats and absolute positioning, using flexboxes for the layout instead. You can read about flexboxes here. I also removed the line breaks in the HTML.
.footer {
width: 100%;
height: 200px;
position: relative;
display: flex;
justify-content: space-around;
}
.infotype {
display: flex;
flex-flow: column;
justify-content: flex-start;
}
h3 {
font-size: 1em;
}
<section class="row">
<div class="footer">
<div class="infotype data">
<h3>Rockets and spacecraft</h3>
Falcon 9
<a class="info" href="#">Falcon Heavy</a>
<a class="info" href="#">Dragon</a>
</div>
<div class="infotype updates">
<h3>Updates</h3>
<a class="info" href="#">News</a>
<a class="info" href="#">Launch Manifest</a>
</div>
<div class="infotype about">
<h3>About SpaceX</h3>
<a class="info" href="#">Company</a>
<a class="info" href="#">Careers</a>
<a class="info" href="#">Gallery</a>
<a class="info" href="#">Shop</a>
</div>
</div>
</section>
Try this html and css. Just create an inner div for .infotype to make position: absolute work correctly.
.footer {
width: 100%;
height: 200px;
float: left;
position: relative;
display: inline-block;
}
.infotype {
float: left;
display: inline-block;
color: black;
width: 30%;
margin-left: 30px;
position: relative;
}
.infotype-inner{
position: absolute;
right: 0;
bottom: 0;
left: 0;
}
<section class="row">
<div class="footer">
<div class="infotype data">
<div class="infotype-inner">
<h3>Rockets and spacecraft</h3>
Falcon 9<br>
<a class="info" href="#">Falcon Heavy</a><br>
<a class="info" href="#">Dragon</a>
</div>
</div>
<div class="infotype updates">
<div class="infotype-inner">
<h3>Updates</h3>
<a class="info" href="#">News</a><br>
<a class="info" href="#">Launch Manifest</a>
</div>
</div>
<div class="infotype about">
<div class="infotype-inner">
<h3>About SpaceX</h3>
<a class="info" href="#">Company</a><br>
<a class="info" href="#">Careers</a><br>
<a class="info" href="#">Gallery</a><br>
<a class="info" href="#">Shop</a>
</div>
</div>
</div>
</section>
If you aren't worried about supporting old browsers, you can replace all of your css with:
.footer {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
More on flex: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
You need something like this.
Try this code..
.footer {
width: 100%;
height: 200px;
position: relative;
}
.infotype {
float:left;
color: black;
width: 30%;
margin-left: 30px;
}

How to fix that Firefox renders Bootstrap Thumbnail differently than Google Chrome?

Why does the latest Firefox browser render Bootstrap thumbnails differently than Google Chrome? I stuck with getting all thumbnails equal height but can't figure out how.
Setting the max-width attribute to none fixes the height, but lets the image overflow its parent container. Can you tell me why and how to fix so that it appears in all Browsers like it appears in Google Chrome?
Here is my fiddle.
EDIT: added screenshots (right-click -> 'open in new tab' to see fullsize)
Chrome: max-width = 100% (default) - fitting nicely
Chrome: max-width = none - overflowing parent
Firefox: max-width = 100% (default) - downscaled by BS
Firefox: max-width = none - overflowing parent
If your images height is fixed to 240px, than one of the solutions is to wrap them in absolute positioned span and use this css:
.thumbnails {
margin: 0 0 10px 0;
padding: 0;
}
.thumbnail {
position: relative;
height: 250px;
}
.thumbnail span {
margin: 0 auto;
display: block;
position: absolute;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
overflow: hidden;
}
.thumbnail span img {
margin: 0 auto;
display: block;
}
Check it in this Fiddle, or run the snippet below:
.thumbnails {
margin: 0 0 10px 0;
padding: 0;
}
.thumbnail {
position: relative;
height: 250px;
}
.thumbnail span {
margin: 0 auto;
display: block;
position: absolute;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
overflow: hidden;
}
.thumbnail span img {
margin: 0 auto;
display: block;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<div id="slideshow">
<div>
<div>
<div data-index="1">
<ul class="thumbnails list-unstyled">
<li class="slide col-xs-4">
<a href="#" class="thumbnail" title="This is ok">
<span>
<img src="http://i.imgur.com/DONm5Ih.jpg" class="shot landscape" width="auto" height="auto" alt="image" />
</span>
</a>
</li>
<li class="slide col-xs-4">
<a href="#" class="thumbnail" title="This is ok">
<span>
<img src="http://i.imgur.com/TFEAQTJ.jpg" class="shot portrait" width="auto" height="auto" alt="image" />
</span>
</a>
</li>
<li class="slide col-xs-4">
<a href="#" class="thumbnail" title="This is ok">
<span>
<img src="http://i.imgur.com/WZbs0wI.jpg" class="shot landscape" width="auto" height="auto" alt="image" />
</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Resources