Overflow difference between Chrome and Edge - html

I notice a difference between Chrome and Edge concerning overflow behavior.
As you can see running the following code, in Chrome this shows only the vertical scrollbar (rightly, in my opinion), while in Edge there are both scrollbars.
Is there a reason for this? How can I make Edge behave in the same way as Chrome does?
Thanks!
.container1 {
display: flex;
flex-flow: column;
align-items: flex-start;
}
.container2 {
display: flex;
flex-flow: column;
align-items: flex-start;
}
.container3 {
max-height: 150px;
overflow: auto;
}
.content {
width: 500px;
height: 200px;
background-color: blue;
}
<div class="container1">
<div class="container2">
<div class="container3">
<div class="content"></div>
</div>
</div>
</div>

Here's what I think is happening:
When the overflow is triggered (because height: 200px on the .content element is taller than the max-height: 150px on the parent), a vertical scrollbar is generated.
This scrollbar actually takes up width. The .content element is set to width: 500px. But once the scrollbar is generated, the width increases to 517px in Chrome. Note that scrollbar width varies among browsers.
Chrome appears to factor in or just ignore the vertical scrollbar width. It refrains from launching a horizontal scrollbar. Edge seems to consider the vertical scrollbar width as an overflow, and therefore launches the horizontal scrollbar.
There could be any number of reasons for this difference in behavior, including a different order of rendering elements and objects.
One thing is clear, if you move the width: 500px from the .content to the parent, the horizontal scroll problem is solved.
.container1 {
display: flex;
flex-flow: column;
align-items: flex-start;
}
.container2 {
display: flex;
flex-flow: column;
align-items: flex-start;
}
.container3 {
max-height: 150px;
overflow: auto;
width: 500px; /* new */
}
.content {
/* width: 500px; */
height: 200px;
background-color: blue;
}
<div class="container1">
<div class="container2">
<div class="container3">
<div class="content"></div>
</div>
</div>
</div>
jsFiddle demo

Try this : overflow-y: auto;
Link : https://www.w3schools.com/cssref/css3_pr_overflow-y.asp

After many attempts I have found a workaround by removing align-items: flex-start and replacing display: flex with display: inline-flex. Here's the new code:
.container1 {
display: inline-flex;
flex-flow: column;
}
.container2 {
display: inline-flex;
flex-flow: column;
}
.container3 {
max-height: 150px;
overflow: auto;
}
.content {
width: 500px;
height: 200px;
background-color: blue;
}
<div class="container1">
<div class="container2">
<div class="container3">
<div class="content"></div>
</div>
</div>
</div>
Hope it will help someone.

Related

Make img in flexbox height 100% & responsive, inconsistent flexbox rendering result

I'm trying to put 4 images in a flexbox div in a parent flexbox, with total height 100%, without stretching out of the parent flexbox. I've searched a lot, but I didn't found something useful.
I have made a minimum example:
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
display: flex;
}
main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
background-color: yellowgreen;
}
.imgs {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
.img100 {
max-width: 100%;
max-height: 100%;
vertical-align: middle;
}
<main>
<!--
Weird. Chromium (Chrome & new Edge) usually renders height 100%,
but not height-responsive; sometimes renders scroll bar.
Firefox always renders the scroll bar result.
-->
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
</main>
When opening this example, chromium-based browsers(Chrome, new Edge) usually render height 100%, the desired result, but it is not "height-responsive": the max height of the images remains fixed once the page is fully loaded.
What even worse is, sometimes they give the stretched result with scrollbar; and Firefox always give me the stretched result with scrollbar, which is not what I want.
Try opening this S.O. page in Chromium & Firefox, and run the snippet. The results are different, too.
Chromium (almost always left, rarely right):
Firefox (always):
Any way to achieve what I want? The wrapping div and parent div may be something other than flexbox. I just want the images staying in the div, with width-responsive & height-responsive.
Also, any reason why Chromium browsers' rendering results are not consistent? Is my example missing something?
I know I can use the background image technique, so I can put image in div without changing layout at all. But I want only the image part clickable, so there must be an image element there corresponding to the clickable area.
background-image example:
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
display: flex;
}
main {
flex: 1;
display: flex;
flex-direction: column;
background-color: yellowgreen;
}
a {
flex: 1;
background-image: url('https://imgur.com/ruE1EBV.jpg');
background-repeat: no-repeat;
background-size: contain;
background-position: center;
border: 5px solid red;
}
<main>
</main>
Edit:
Equal row heights in flex-direction: column is okay when the content inside doesn't contain any images. I think the tricky part is the images. They just stretch...
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
display: flex;
}
main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
background-color: yellowgreen;
}
.imgs {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
border: 5px solid red;
}
.img100 {
max-width: 100%;
max-height: 100%;
vertical-align: middle;
}
<main>
<div class="imgs">
hello
</div>
<div class="imgs">
hello
</div>
<div class="imgs">
hello
</div>
<div class="imgs">
hello
</div>
</main>
Well, I found an easy answer to fix this simple minimum example.
Just add overflow: hidden to .imgs, so images don't grow out of main.
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
display: flex;
}
main {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
background-color: yellowgreen;
}
.imgs {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.img100 {
max-width: 100%;
max-height: 100%;
vertical-align: middle;
}
<main>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
<div class="imgs">
<img class="img100" src="https://imgur.com/ruE1EBV.jpg">
</div>
</main>
Applying this to my actual, much more huge layout did fix my layout.
So all I need to do is to carefully inspect my overflows.
Why Chromium behaves differently: stackoverflow: Why do Chrome and Firefox show different flex layout results?

How to align-items: center AND align-self: stretch?

I have an element I'd like to be (cross-axis) centered but also 'grow' to a nominal size even with too-little content, BUT ALSO 'shrink' when the width of the page becomes smaller than 350px wide.
HTML
<div class="parent">
<div class="child">
Some content
</div>
</div>
SCSS
.parent {
display: flex;
flex-direction: column;
align-items: center;
.child {
max-width: 350px;
align-self: stretch;
}
}
Adding align-self: stretch; to .child does the job of making it 350px wide, but it seems to negate the align-items: center; in .parent
Is there a way to do this in CSS that I'm missing? Please note that the element can't just be 350px wide all the time - it must also respond to horizontal page resizing as it does in the example fiddle.
Fiddle: https://jsfiddle.net/1uqpxn8L/1/
UPDATED
I think you should use justify-content to h-align child to center.
Please note, when you apply display: flex property to parent, you should apply flex property to child.
.parent {
background: yellow;
display: flex;
flex-direction: column;
align-items: center;
}
.parent .child {
background: black;
color: white;
text-align: center;
flex: 1 1 auto;
width: 100%;
max-width: 350px;
}
<div class="parent">
<div class="child">
I should be 350px wide
<br> and centered in the yellow
<br> unless the page gets smaller,
<br> in which case I should have
<br> 10px padding on either side.
</div>
</div>
Please see the result here, hope this is what you mean: https://jsfiddle.net/1uqpxn8L/11/
You can do something like this.
HTML
<div class="parent">
<div class="child">
Some content
</div>
</div>
SCSS
.parent {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 10px;
.child {
width: 350px;
#media(max-width: 350px) {
width: 100%;
}
}
}
.parent {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 10px;
background-color: red;
}
.child {
width: 350px;
background-color: yellow;
}
#media(max-width: 350px) {
.child { width: 100%; }
}
<div class="parent">
<div class="child">
Some content
</div>
</div>
So whats happening is I'm using a media query to change the width of the child depending on the width of the browser.
You just need to remove the flex-direction property. Then it's working as you expected. But there will be a problem if you want to display children elements as column manner. The shrinking problem occurs with the flex-direction property or flex-flow:column values as I checked.

How to make an element scroll horizontally without using min-width or an exact fixed width?

I'm trying to create a table which will be responsive,
but to make it simple I want to make it scroll horizontally when it has too many columns.
.fixed-table-wrap {
display: flex;
flex-wrap: wrap;
overflow: hidden;
}
.fixed-column {
width: 140px;
}
.standard-column {
width: calc(100% - 140px);
overflow-x: auto;
}
.sc-content {
display: flex;
flex-wrap: wrap;
min-width: 1485px;
width: 100%;
}
<div class="fixed-table-wrap">
<div class="fixed-column">
<div class="fc-content">
</div>
</div>
<div class="standard-column">
<div class="sc-content">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</div>
</div>
In order to have the scroll effect I have to use min-width or a fixed width, but I don't want that because I want the table to be responsive, when it is not exceeding the window's width it should just be natural, and when it exceeds, it scrolls.
To get an even better idea of what my problem is:
What my table looks like:
More of what my table looks like:
What happens when I remove the min-width:
What happens when I have less content WITH min-width:
What happens when I have less content WITHOUT min-width:
Try using the CSS overflow-x property and set an element you've wrapped around your table to "scroll". So with HTML like this:
<div id="table-wrapper">
<table>
<!-- table content here -->
</table>
</div>
And CSS like this:
<style type="text/css">
#table-wrapper {
width: 100%;
x-overflow: scroll;
}
</style>
I've found my solution:
.fixed-table-wrap {
display: flex;
flex-wrap: wrap;
overflow: hidden;
width: fit-content;
}
.fixed-column {
width: 140px;
}
.standard-column {
width: calc(100% - 140px);
overflow-x: auto;
}
.sc-content {
display: flex;
flex-wrap: wrap;
width: max-content;
}
.child {
width:140px;
}

Flex column and max-height bug in Google Chrome

In Google Chrome, Safari and IE I am encountering an overflow issue with the flex content.
The issue I am sure is related to the way Chrome doesn't cascade the flex object to it's children.
I believe the correct way to handle the flex objects would be to remove all height/width and max-height/max-width attributes and to use the flex attribute to determine the size limitations. e.g:
display:
flex: 0 0 100px;
However as the flex object is orientated as a column I can't do this.
Additionally this "bug" only occurs when using an img. Replacing the img with a div causes flex to behave as expected.
EXAMPLE (View in Chrome)
span{
background:#4b0;
}
.Flx {
display: flex;
}
.Child {
display: flex;
flex:1;
align-items: center;
justify-content: center;
max-height: 100px;
flex-direction: column;
background-color: #aaa;
}
.Child img {
max-height: 100%;
background-color: #fb4a4a;
}
<div class="Flx">
<div class="Child">
<span>TEXT</span>
<img src="https://i.stack.imgur.com/440u9.png">
</div>
</div>
It appears that this occurs when using flex and percentages on img tags simply changing % to pixels resolved the issue:
max-height: 100px;
span{
background:#4b0;
}
.Flx {
display: flex;
flex:1;
}
.Child {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background-color: #aaa;
}
.Wrap{
align-items: center;
justify-content: center;
background:#00d;
}
.Wrap img {
max-height: 100px;
max-width:100%;
background-color: #fb4a4a;
}
<div class="Flx">
<div class="Child">
<span>TEXT</span>
<div class="Flx Wrap">
<img src="https://i.stack.imgur.com/440u9.png">
</div>
</div>
</div>

IE 11: Image doesn't scale down correctly within flexbox

I'm trying to use flexbox to place two images in a column. In this case, the width of the div container is smaller than the width of the image. In Chrome the image perfectly fits into the div container, but it doesn't in IE, and I don't know why.
div.outer {
width: 400px;
display: flex;
flex-direction: column;
justify-content: space-around;
}
div.inner {
width: 100%;
border: 1px solid red;
}
img {
width: 100%;
height: auto;
}
<div class="outer">
<div class="inner">
<img src="http://placehold.it/480x360">
</div>
<div class="inner">
<img src="http://placehold.it/480x360">
</div>
</div>
https://jsfiddle.net/Yifei/16cpckqk/
This is what I've got in IE 11:
IE11 seems to have some trouble with the initial value of the flex-shrink property. If you set it to zero (it is initially set to 1), it should work:
div.outer {
width: 400px;
display: flex;
flex-direction: column;
justify-content: space-around;
}
div.inner {
flex-shrink: 0;
width: 100%;
border: 1px solid red;
}
img {
width: 100%;
height: auto;
}
<div class="outer">
<div class="inner">
<img src="http://placehold.it/480x360">
</div>
<div class="inner">
<img src="http://placehold.it/480x360">
</div>
</div>
The accepted solution destroyed my sticky footers in ie. So I solved this disturbing issue with the following non satisfying "only for ie JS"... . The px value instead the "height:auto" did the trick for me.
if(fuBrowser =='ie'){
var img = $("#teaser img");
img.each(function() {
$( this ).css({height: $( this ).height()});
});
}