Overflow with a flex div not working in FF - html

I have a simple demo of an error I found. There is a flex div and a few images inside.
The sizes of the div and the images are unknown, I put some fixed values just to represent the problem.
The problem is that the images are not overflowing the div's width in FF, but they do in Chrome (the expected and desired behavior).
The main goal is to make only 3 images to be visible (33.3333% of the div's width for each image), even if there are more than 3 images.
Demo: http://codepen.io/alexandernst/pen/mPoeLP
HTML:
<div class="wrapper">
<img class="box" src="http://placehold.it/150x150">
<img class="box" src="http://placehold.it/150x150">
<img class="box" src="http://placehold.it/150x150">
<img class="box" src="http://placehold.it/150x150">
<img class="box" src="http://placehold.it/150x150">
</div>
CSS:
.wrapper {
border: 1px solid red;
width: 400px;
height: 200px;
display: flex;
overflow: hidden;
}
.box {
border: 1px solid green;
max-width: 33.33333%;
position: relative;
padding-right: 10px;
align-self: center;
}

I'd suggest wrapping each of the images in a div and use the .box class on that instead.
Seems to work in Chrome 51 + FF 46
* {
box-sizing: border-box;
}
.wrapper {
border: 1px solid red;
width: 400px;
height: 200px;
display: flex;
align-items: center;
overflow: hidden;
}
.box {
border: 1px solid green;
flex: 0 0 33.33333%;
position: relative;
padding-right: 10px;
}
.box img {
width: 100%;
height: auto;
display: block;
}
<div class="wrapper">
<div class="box">
<img src="http://placehold.it/150x150">
</div>
<div class="box">
<img src="http://placehold.it/150x150">
</div>
<div class="box">
<img src="http://placehold.it/150x150">
</div>
<div class="box">
<img src="http://placehold.it/150x150">
</div>
<div class="box">
<img src="http://placehold.it/150x150">
</div>
</div>

It is because you have padding-right. Try adding box-sizing: border-box;:
.box {
border: 1px solid green;
max-width: 33.33333%;
box-sizing: border-box;
position: relative;
padding-right: 10px;
align-self: center;
}
box-sizing will take padding in its calculations.
Updated codepen.

Related

Flexbox square items independent of item count

I use some inline styling in the HTML Doc. I would like to achieve a flexbox with n divisions where divs are squared. Within these divs I want to add certain images (here a placeholder)
I was looking up some other threads where there was padding used as a measure to adjust the box "height" since it is calculated upon width. However this solution only expands the current box in height (outlined with the blue border).
Has anyone a tip on how to avoid this?
EDIT: Apparently the padding solution works while using units like vh and vw instead of percentage and as long as I do not insert an image
.container {
position: relative;
width: 90%;
max-height: 35%;
display: flex;
margin: 5%;
border: 5px solid black;
justify-content: space-around;
}
.box {
position: relative;
width: 100%;
margin: 2.5%;
border: 5px solid blue;
overflow: hidden;
}
.image {
position: relative;
width: 100%;
}
<div class="container">
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80">
</div>
</div>
We now have access to aspect-ratio in CSS although it is poorly supported at the time of writing.
The aspect-ratio CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.
.container {
width: 90%;
max-height: 35%;
display: flex;
margin: 5%;
border: 5px solid black;
justify-content: space-around;
}
.box {
margin: 2.5%;
flex: 1;
aspect-ratio: 1;
border: 5px solid blue;
overflow: hidden;
}
.image {
max-width: 100%;
display: block;
}
<div class="container">
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80">
</div>
</div>
To manage this, there is a little known trick (tbh I didn't know you could do this) with setting an aspect ratio on divs of unknown/dynamic widths. See this article.
I ended up adding position: absolute for the images to not mess with the height of the divs after applying this 1:1 ratio for your scenario:
.box:before {
content: "";
float: left;
padding-top: 100%; /* initial ratio of 1:1*/
}
This might be what you are trying to do:
.container {
position: relative;
width: 90%;
max-height: 35%;
display: flex;
margin: 5%;
border: 5px solid black;
justify-content: space-around;
}
.box {
position: relative;
width: 100%;
margin: 2.5%;
border: 5px solid blue;
overflow: hidden;
}
.box:before {
content: "";
float: left;
padding-top: 100%; /* initial ratio of 1:1*/
}
.image {
position: absolute;
width: 100%;
}
<div class="container">
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" />
</div>
<div class="box">
<img class="image" src="https://images.unsplash.com/photo-1611817757571-75fe5c08ffd9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80">
</div>
</div>

CSS position float

I try to display a left and right area but it's not working actually with the cotes "right" and "left"
I tried the position :absolute but it's display me something strange
Maybe I'm doing something wrong with my conteneur div or my div element1
Someone knows how I can achieve that?
#conteneur {
padding-top: -25px;
display: flex;
border: 2px solid black;
padding-bottom: 10px;
}
#element1 {
display: block;
width: 350px;
border: 1px solid black;
}
.right {
float: left;
width: 100%;
}
.left {
float: right;
width: 100%;
}
<div id="conteneur">
<div id="element1">
<img src="{{ public_path('../public/uploads/logo-FFRXIII-2017-01.png')}}" style="max-width: 300px;">
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
</div>
</div>
you are using flexbox, so stick with flexbox and forget floats
#conteneur {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
border: 1px solid black;
padding-bottom: 10px;
}
.img {
flex: 0 100%;
}
img {
max-width: 300px;
}
<div id="conteneur">
<div class="img">
<img src="http://placehold.it/300x200">
</div>
<div class="right">
adresse_right
</div>
<div class="left">
adresse_left
</div>
</div>
First of all your
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
Won't react to your CSS since these are ID's and in your CSS you are trying to find classes with the . selector. So change the . to a # or change your ID tags to Classes.
Secondly i've created a jsfiddle and edited your code hope this helps!

How do I center 3 horizontally-arranged images on a page?

I have a very simple HTML/CSS webpage.
I have three images arranged horizontally on the page, like so:
I'd like to center them on the page, like so:
What's the fix?
Here's the (not-working) code I'm currently using:
.sketches {
align-content: center;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="sketches">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
Since <div> by default is a block element and <img> is an inline-block element, if you wanna center images horizontally, it's enough to set text-align: center; to div container:
.sketches {
text-align: center;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="sketches">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
Here's the solution:
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.sketches {
align-content: center;
margin-left: auto;
margin-right: auto;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="outer">
<div class="middle">
<div class="sketches" align=center>
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
</div>
</div>
Used technique to center vertically from here.
CSS
a) .sketches selector
1) Insert display: flex; declaration
2) Instead of the CSS property: align-content add justify-content
.sketches {
display : flex;
justify-content : center;
/* can be removed */
min-width : 350px;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="sketches">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>

How to make multiple divs to scroll horizontally?

I want my tiles to be in the same row, and the container to scroll horizontally, if the tiles go beyond the width of the container. Looking at the following demo, the tiles get added to the next row, so I have to scroll vertically to access them. How can I make horizontal scroll work, and keep all tiles in the same row?
.container {
width: 600px;
max-height: 140px;
border: 1px solid green;
overflow-x: scroll;
overflow-y: scroll;
white-space: nowrap;
}
.tile {
width: 200px;
height: 92px;
float: left;
margin: 10px 10px 50px 10px;
background: cornflowerblue;
}
<div class="container">
<div><img class="tile"></div>
<div><img class="tile"></div>
<div><img class="tile"></div>
</div>
You need to set overflow-x:scroll; and overflow-y: hidden; on parent, and white-space:nowrap; on inner div and also display: inline-block; on floatLeft
.container {
width: 480px;
height: 140px;
border: 1px solid green;
overflow-x: scroll;
overflow-y: hidden;
}
.inner {
height: 100%;
white-space:nowrap;
}
.floatLeft {
width: 200px;
height: 92px;
margin:10px 10px 50px 10px;
display: inline-block;
}
img {
height: 100%;
}
<div class="container">
<div class="inner">
<div class="floatLeft">
<img src="http://placehold.it/350x150" class="tile">
</div>
<div class="floatLeft">
<img src="http://placehold.it/350x150" class="tile">
</div>
<div class="floatLeft">
<img src="http://placehold.it/350x150" class="tile">
</div>
</div>
</div>
Add display: inline-block to your containing divs css:
.floatleft{
display: inline-block;
}
or alternatively you can add it as a style attribute on each div:
<body>
<div class="container">
<div style="display: inline-block" class="floatLeft">
<img class="tile">
</div>
<div style="display: inline-block" class="floatLeft">
<img class="tile">
</div>
<div style="display: inline-block" class="floatLeft">
<img class="tile">
</div>
</div>
</body>
Heres the working fiddle:
https://jsfiddle.net/edencorbin/rq0L7x7v/
HTML:
<div class="container" id="content">
<div >
<img src="img" height="190">
<img src="img" height="190">
</div>
CSS:
html, body {margin: 0; padding: 0;}
#content{
width: auto;
height:210px;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
#contentimg {
border: 0;
display: inline-block;
vertical-align: middle;
}
I want my tiles to be in the same row, and the container to scroll horizontally, if the tiles go beyond the width of the container.
Your .container class has a fixed with of 480px. If this is intentional then all you need to do is add display: inline-block to your .floatLeft class like so:
.container > .float-left {
display: inline-block;
}
Otherwise, you can make your .container class have a flexible width. If you like the suggestion, you can change the width to min-width: 480px that way your width will expand with your content.
.container {
min-width: 480px; /* changes occurred here */
max-height: 140px;
border: 1px solid green;
overflow-x: scroll;
overflow-y: scroll;
white-space: nowrap;
}
However, if your screen width is too small to hold many tiles, then they will align vertically in a new row, which is normal expected behavior. Or better yet, you could do both. The choice is yours.

Float left div inside center container

All...
I want to ask very basic CSS. Please see here http://jsfiddle.net/fzJ8X/5/
HTML:
<div class="container">
<div class="item">
<div class="overlay">
<img src="http://placehold.it/200x200" />
</div>
</div>
<div class="item">
<div class="overlay">
<img src="http://placehold.it/200x200" />
</div>
</div>
<div class="item">
<div class="overlay">
<img src="http://placehold.it/200x200" />
</div>
</div>
CSS:
.container {
width: 500px;
margin: 0 auto;
text-align: center;
border: #000 1px solid;
}
.item {
display: inline-block;
border: #F00 5px solid;
width: 200px;
height: 200px;
text-align: left;
}
.overlay {
border: #00F 5px solid;
width: auto;
height: auto;
}
.item img{
max-width: 100%;
height: auto;
display: block;
}
I have three boxes inside container with style text-align:center. Now all boxes centered like I want, but how to all boxes in float left? like screenshot below :
Screenshot here
Thank you very much :)
Try this:
JS iddle: http://jsfiddle.net/xZst7/3/
CSS:
.container {
width: 500px;
margin: 0 auto;
text-align: center;
border: #000 1px solid;
display: inline-block;
}
.item {
display: inline-block;
border: #F00 5px solid;
width: 200px;
height: 200px;
text-align: left;
float: left;
margin-right: 5px;
margin-bottom: 5px;
}
.overlay {
border: #00F 5px solid;
width: auto;
height: auto;
}
.item img{
max-width: 100%;
height: auto;
display: block;
}
HTML:
<div style="text-align: center;">
<div class="container">
<div style="display: inline-block; width: 430px;">
<div class="item">
<div class="overlay">
<img src="http://placehold.it/200x200" />
</div>
</div>
<div class="item">
<div class="overlay">
<img src="http://placehold.it/200x200" />
</div>
</div>
<div class="item">
<div class="overlay">
<img src="http://placehold.it/200x200" />
</div>
</div>
</div>
</div>
</div>
add float:left; to the code
.item {
display: inline-block;
border: #F00 5px solid;
width: 200px;
height: 200px;
text-align: left;
float:left;
}
jsfiddle:http://jsfiddle.net/fzJ8X/12/
Nothing much to do.
Add float:left; to .item{} as below.
.item {
display: inline-block;
border: #F00 5px solid;
width: 200px;
height: 200px;
text-align: left;
float:left;
}
Check the fiddle
Fiddle