CSS table layout height with svg image in IE - html

Taking a look at the code below and the fiddle, can some please tell my why in IE (9-10-11) the height of the svg image is not matching the height of the sibling (content on right) like in chrome, FF, Safari?
In IE there is extra vertical space in the left table-cell.
Thank-you
HTML
<div class="table-layout">
<div class="table-cell fixed-width">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 180.22 150.718" enable-background="new 0 0 180.22 150.718" xml:space="preserve">
<circle fill="#E3E3E3" cx="91.5" cy="75.167" r="75.167" />
</svg>
</div>
<div class="table-cell" style="border: solid red 1px">
<div class="row">
<div class="col-xs-12">content</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="row">
<div class="col-sm-6">content</div>
<div class="col-sm-6">content</div>
</div>
</div>
<div class="col-lg-6">content</div>
</div>
</div>
CSS
.table-layout {
display: table;
width: 100%;
table-layout: fixed;
}
.table-layout .table-cell {
display: table-cell;
border: solid 1px #ccc;
vertical-align: top;
}
.fixed-width {
vertical-align: middle !important;
background-color: #a3a3a3;
width: 60px;
padding: 5px;
}
fiddle: http://jsfiddle.net/gp2nqzh0/1/

Remove width:100%; from .table-layout and it will work fine.

This is an old post but still relevant.
For those of you that don't have IE (hopefully most) or an emulator and want to see the issue, I've attached a screenshot.
Fix: set both a height and width on your svg element.
.fixed-width svg {
width: 60px;
height: 60px;
}
I tested your fiddle on IE 11 using Browserstack and can confirm it works. Setting max-width and max-height attributes also works.
WHY is this happening?
I recommend reading this article to fully understand the behavior of svgs in browsers: https://css-tricks.com/scale-svg/ BONUS: This also has solutions for many scenarios.
BUT for this case, your answer is below (from the article),
Many browsers—IE, Safari, and versions of Opera and Chrome released prior to summer 2014—will not auto-size inline SVG. If you don't specify both height and width, these browsers will apply their usual default sizes, which as mentioned previously will be different for different browsers. The image will scale to fit inside that height or width, again leaving extra whitespace around it. Again, there are also inconsistencies in what happens if you leave both height and width auto.
Internet Explorer cuts the difference, using width of 100% and height of 150px for images and inline SVG.
Because you have a fixed-width class on your div, I assume you don't need to worry about scalability and setting the fixed width and height on the svg will suffice.

Related

Parent bg shows/ child doesn't fill 100% depending on zoom factor

Sometimes the background of my parent-div is showing, and it's driving me crazy.
Setup:
Container-div with 4x4 divs inside (lets call them "outer"; blue bg).
Each of the blue "outer"-divs contains another div ("inner"; green bg).
Why I want it that way:
The green is supposed to cover the blue, because eventually the green will disappear (via jQuery - click) and the blue will show (it will have a bg-image instead of just the blue bg).
Problem:
Even though I tried different approaches (see codepen below), sometimes the blue bg will show.
screenshot of the problem
The point is -sometimes-. If the browser is zoomed to a convenient zoomfactor, it will display exactly as intended: the green covers the blue 100%. If, however, the browser thinks it's an unconvenient zoomfactor, the blue bg shows through. It also varies depending on the browser. If you view the below codepen-example in firefox rather than chrome, opera or edge, you might not even see that error (I didn't test it in safari).
Question:
How can I ensure that the green will consistently cover the blue, no matter the zoomfactor (or browser)?
css:
<style>
#outer-container {
width: 600px;
/* height: 600px; */
display: flex;
flex-flow: row wrap;
}
.outer-box {
width: 150px;
height: 150px;
background-color: blue;
border: 1px solid black;
box-sizing: border-box;
}
.inner-box {
width: 100%;
height: 100%;
background-color: green;
}
</style>
html:
<div id="outer-container">
<div class="outer-box" id="outer-box01">
<div class="inner-box"></div>
</div>
<div class="outer-box" id="outer-box02">
<div class="inner-box"></div>
</div>
<div class="outer-box" id="outer-box03">
<div class="inner-box"></div>
</div>
<!-- there are 16 outer-divs in total (see codepen) -->
</div>
codepen-link
Additional info:
If I open that codepen with firefox, it behaves as intended, not in chrome or edge. If I open my visual studio code with firefox, I get the same background-showing-display-glitch(?) (depending on the zoomfactor).
I tried floats, flexbox and grid (see codepen); I used height/width in pixels, height: 100%, stretch (flexbox); pos: rel on outer and pos: abs, top,right,bottom,left: 0 on inner; display: block won't help, because the div is a block-element already (just to be sure I assigned it manually anyways); I use box-sizing: border-box - and I'm running out of ideas.
Yes, when I assign the border to the inner-divs the outer-bg doesn't show; but it's the outer-divs that are supposed to have the border, because once the green get's clicked away the border must still be there.
Thanks in advance for any suggestions!
I found a workaround to achieve my goal by now (which was to not let the blue show through) by just putting another container-div on top of the first one.
My original question, though, remains unanswered with that solution.
But just in case anyone was trying something similar:
html:
<div id="outer-container">
<div id="inner-container">
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
<!-- 16 of those inner-divs here -->
</div>
<div class="bg"></div>
<div class="bg"></div>
<div class="bg"></div>
<!-- 16 of those bg-divs here -->
</div>
css:
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#outer-container {
width: 600px;
position: relative;
overflow: hidden;
}
#inner-container{
/* width: 600px; */
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
}
.bg, .inner{
width: 150px;
height: 150px;
border: 1px solid black;
float: left;
}
.bg{
background-color: blue;
}
.inner{
background-color: green;
}
</style>
codepen link
I had a look at this and it's puzzling. My best guess at this point is that it's a browser quirk/bug. With HTML and CSS there are so many ways to achieve the same thing so your workaround isn't necessarily bad. I managed to make it behave by putting the border on the inner-box's instead of the outer.
The reason I think it may be a bug is that it isn't consistent, as you have noticed yourself. In Chrome it happens at zoom level 125% (on a standard 1080 screen). In FireFox it doesn't happen at all on any zoomlevels and Edge has it at various zoom levels.
It looks a bit like the outer div at some levels ends up extending half a pixel wider than it's supposed to but it's hard to be sure.

Safari doesn't make a div 100% of it's parent's height

I'm working on a website, where the structure of a section is like this:
<div class="col-md-6">
<section class="right" data-type="background" data-speed="30" style="background: url(<?php echo get_field('book_image')['url']; ?>);">
</section>
</div>
The parent div in this situation has (in safari) a height 2976px. However, the child won't size itself to the same height, even though I've applied the height property to it.
I tried this in Chrome & Safari, both on macOS: Chrome worked, Safari didn't.
Is there any was to get this to work, preferably without any JS? Thanks :)
-- Edit
I'm using Bootstrap4, however, the right class only contains properties to style the div. Contents below
.right {
max-width: 50vw;
height: 100%;
background-size: 60vh !important;
background-repeat: no-repeat;
}
-- Edit #2.
Here's a snippet demonstrating the problem:
.left {
padding: 0;
background: #000; /*debugging*/
height: 200px; /*debugging*/
}
.right {
height: 100%;
background-size: 60vh !important;
background-repeat: no-repeat;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-6 left">
</div>
<div class="col-6">
<section class="right" data-type="background" data-speed="30" style="background: red;"></section>
</div>
</div>
</div>
(or in JSFiddle: Click me
As an advice you can use webpage CANIUSE
,you can check which css property does browser support . In my opnion the best solution is to use jquery or javascript to set height of div , when page will be resize or will be load. You can't find absolute perfect solution to solve crossbrowser support . If you need help with jquery do not hesitate ask when you need .
The problem is your parent div doesn't have an height property. Even though Chrome is able to resolve the containers height, Safari (and maybe some other browsers) isn't. In order to fix this you've to specify a height for the 2nd div in your .row (the parent of .right) as well.
Styling
.right-parent {
height: 200px;
}
Markup
<div class="col-6 right-parent">
<section class="right" data-type="background" data-speed="30" style="background: red;"></section>
</div>
Demo

Crop image using css

I am trying to crop 50px from the top of an image. I am following the below reference but for some reason it didn't work in FF but worked in Chrome.
https://css-tricks.com/clipping-masking-css/
Html:
<img src="https://s30.postimg.org/lkqxmrk29/about.jpg" class="rectshape">
Demo:https://jsfiddle.net/squidraj/a4j343hg/1/
Any help is highly appreciated.
Since the clip path is not supported very well, why not use overflow: hidden and a container element? Here is your updated JSFiddle demonstrating this. A negative margin can be used to hide part of the image. Cropping the image from other sides can be accomplished easily by using negative margin on the other sides. Only if you want a non-rectangular clipping path, you will have to resort to the SVG clipPath that was referred to in the comments. Example Fiddle.
.rectshape {
overflow: hidden;
margin: 5px;
border: 1px solid #000;
}
.rectshape > img {
margin-top: -50px;
border: 1px solid #00f;
}
<div class="rectshape">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a">
</div>
<div class="rectshape">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a">
</div>
<div class="rectshape">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a">
</div>

Removing white space under nested img when resizing without squeezing image

I'm making a basic header using divs and a nested img in a fluid layout. I'm a bit rusty on this and i can't for the love of me figure out how to ensure that the image nested in the div scales without scaling to the point where it becomes smaller its parent div.
EDIT: Updated the codepen link showing how using min-height won't work as it squeezes the image
HTML:
<div class="container">
<div class="item half">
<p>
Some text
</p>
</div>
<div class="item half">
<img src="http://dummyimage.com/hd1080" class="full-width">
</div>
</div>
CSS:
.container{
margin: 0 auto;
max-width: 1920px;
}
.item{
height: 300px;
float:left;
overflow: hidden;
background-color: gray;
}
.half{
width: 50%
}
.full-width{
max-width: 100%;
}
And for good measure a quick illustration of what is happening:
And an illustration of what i want to happen:
Edit: Note that the image here is not being squeezed, which is what happens if you set the image to have a min-height equal to its parent div. But rather the overflow is hidden. You can also see that i do not mind the images being cropped.
Any help appreciated.
You can add min-height equal to the div.item height to your image CSS
img {
max-width:100%;
min-height:300px;
}
I've managed to find the solution i wanted in this thread. The function i was looking for was object-fit.
I've used the following solution:
img{
min-height: 100%;
object-fit: cover;
}
Edit: quickly found out that this property is only properly supported by Firefox, Chrome and Opera. Use this polyfill to fix this on Safari and IE.

Background size 100% auto not working in IE 10

I've got some layers of divs with svg backgrounds. Set at 100% width and auto height:
<div class="group section hot-bonus">
<div class="layer layer-base clouds"></div>
<div class="layer layer-back1 clouds-1"></div>
<div class="layer layer-back2 clouds-2"></div>
<div class="layer layer-back3 clouds-3"></div>
<div class="layer layer-back5 bg"></div>
</div>
The .group has these styles:
height: 65%;
z-index: 8;
text-align: center;
All of the clouds follow this format:
.clouds {
z-index: 6;
background: url(../images/hot_bonus_clouds.svg) center bottom no-repeat;
background-size: 100% auto;
#include transform( scale(1.1) );
}
The result is this (full width browser screenshot):
However, I can't seem to get it working on IE10. This is what it's giving me (never mind the design/layout differences, just the unstretched cloud backgrounds):
And this is despite IE10 showing that they have the style background-size: 100% auto; applied.
Any ideas what's going on?
Answer found here: https://stackoverflow.com/a/22970897/1192861
Be sure that your SVG has a width and height
I generated my SVG's from illustrator, I had to open them up again and set a width/height for each one. A really quick way to set it was to pay attention to this part of the svg element:
viewBox="0 0 1428.5 521.8" where 1428.5 is the width and 521.8 is the height. So the fix makes sure the SVG element looks something like this:
<svg viewBox="0 0 1428.5 521.8" width="1428.5" height="521.8"....>/***/</svg>