IE: Background Image does not display. Browser repaints on hover? - html

So this is one of the strangest IE bugs I have come across, and it's happening in IE11!
I have a simple element that looks as follows:
<div class="article">
<div class="wrapper">
<header><h1>Hello World</h1></header>
<div class="image" style='background-image: url("http://upload.wikimedia.org/wikipedia/commons/4/41/Left_side_of_Flying_Pigeon.jpg");'> </div>
</div>
</div>
with the following CSS:
*{margin:0;padding:0;}
.article {
height:200px;
background:aliceblue;
}
.wrapper {
height:100%;
display:table;
width:100%;
}
header, .image {
display:table-row;
width:100%;
}
header {
background:red;
height:10px;
}
.article:hover .image {
opacity:0.5;
}
For a JSFiddle click here (you might need to click Run to see the bug appear)
The issue is that when starting the page we do not see the background-image. When you hover over .article then the image suddenly appears! When hovering out the image remains (as expected).
It is as if the browser only repaints the background-image when the user hovers?
The image does not display on initial page load
The image displays on a mouse hover, the image will remain afterwards
How can we display the background-image by default?
Fiddle > http://jsfiddle.net/ykrbe4zy/

The key problem with image is that you're applying the display: table-row; for the image which seems not supported by IE properly.
Use display: inline-block; instead:
.image{
display: inline-block;
height: 100%;
}
here's the working demo

Change below code
from :
header, .image {
display: table-row;
width: 100%;
}
header {
background: red;
height: 10px;
}
TO
header, .image {
display: block;
width: 100%;
height: 100%;
}
header {
background: red;
height: 40px;
}
Updated Fiddle : http://jsfiddle.net/ts8ahznd/7/
Updated Code:
CSS
* {
margin: 0;
padding: 0;
}
.article {
height: 200px;
background: aliceblue;
}
.wrapper {
height: 100%;
display: table;
width: 100%;
}
header, .image {
display: block;
width: 100%;
height: 100%;
}
header {
background: red;
height: 40px;
}
.article:hover .image {
opacity: 0.5;
}
HTML
<div class="article">
<div class="wrapper">
<header>
<h1>Hello World</h1>
</header>
<div class="image" style='background-image: url("http://upload.wikimedia.org/wikipedia/commons/4/41/Left_side_of_Flying_Pigeon.jpg");'> </div>
</div>
</div>
Hope this will help!!!

Related

Background image is not showing in IE

Background image is not showing in IE. Whereas its showing well in Chrome.
Here is the CSS:
.banner1 {
background-image: url(/assets/images/banner-1.jpg)!important;
height: 100%;
display: block;
}
.banner2 {
background-image: url(/assets/images/banner-2.jpg);
height: 100%;
display: block;
}
.banner3 {
background-image: url(/assets/images/banner-3.jpg)!important;
height: 100%;
display: block;
}
.banner4 {
background-image: url(/assets/images/banner-4.jpg)!important;
height: 100%;
display: block;
}
html:
<div class="right_bx">
<span class="banner1"></span>
</div>
<div class="right_bx">
<span class="banner2"> </span>
</div>
<div class="right_bx">
<span class="banner3"></span>
</div>
<div class="right_bx">
<span class="banner4"></span>
</div>
When I refresh the page I see banner 1 image appearing. The image in fisrt div is apperaing in IE..For example if I give banner 2 in first div I am able to see banner 2 image. But subsequent div images are not showing up in IE
Not sure this will work but try this
.banner1 {
background-image: "assets/images/banner-1.jpg"!important;
height: 100%;
display: block;
}
.banner2 {
background-image: "assets/images/banner-2.jpg";
height: 100%;
display: block;
}
.banner3 {
background-image: "assets/images/banner-3.jpg"!important;
height: 100%;
display: block;
}
.banner4 {
background-image: "assets/images/banner-4.jpg"!important;
height: 100%;
display: block;
}
use background: url("..."); or
background-image: url("..."); also don't use / at the beginning of the file path.
Change /assets/images/banner-1.jpg to this: assets/images/banner-1.jpg etc.
.banner1 {
background: url("assets/images/banner-1.jpg");
height: 100%;
display: block;
}
.banner2 {
background: url("assets/images/banner-2.jpg");
height: 100%;
display: block;
}
.banner3 {
background: url("assets/images/banner-3.jpg");
height: 100%;
display: block;
}
.banner4 {
background: url("assets/images/banner-4.jpg");
height: 100%;
display: block;
}
Try to use F12 developer tools to check the related elements (whether the image load success or not, and the CSS style). I suppose perhaps the issue is related the div container is empty, so the image not display. you could try to fill content to the div, or refer to the following code to set the fix height property:
.right_bx{
height: 200px;
}

how to avoid vertical scrollbar in horizontal slider layout

I will try to create a slider(move to left or right), but when I set outer Container(.wrapper) width over 100vw and set the height to 100vh with every child div, It will overflow on vertical, how can I avoid it?
Open the detailed description of the picture
body{
padding : 0;
margin:0;
}
.wrapper {
width : 200vw;
}
.section {
width : 100vw;
height : 100vh;
position:relative;
float:left;
}
.section1 {
background-color : red;
}
.section2{
background-color : yellow;
}
<div class="wrapper">
<div class="section section1">1</div>
<div class="section section2">2</div>
</div>
if you want to edit with online editor, you can try it
and I don't know why if When I only have one child div(.section), the height doesn't vertical overflow(move up and down)
body{
padding : 0;
margin:0;
}
.wrapper {
width : 100vw;
}
.section {
width : 100vw;
height : 100vh;
position:relative;
float:left;
}
.section1 {
background-color : red;
}
/*
.section2 {
background-color : yellow;
}
*/
<div class="wrapper">
<div class="section section1">1</div>
<!--<div class="section section1">1</div>-->
</div>
Although your question says you're looking to hide the horizontal scrollbar (left and right), your image indicates that you're actually looking to hide the vertical scrollbar (up and down).
You're looking to add overflow-y: hidden to body in order to hide the vertical scrollbar:
body {
padding: 0;
margin: 0;
overflow-y: hidden;
}
.wrapper {
width: 200vw;
}
.section {
width: 100vw;
height: 100vh;
position: relative;
float: left;
}
.section1 {
background-color: red;
}
.section2 {
background-color: yellow;
}
<div class="wrapper">
<div class="section section1">1</div>
<div class="section section2">2</div>
</div>
Alternatively, if you are indeed looking to hide the horizontal scrollbar, this can be done with overflow-x: hidden, though note that your content won't actually be too tall to escape the bounds vertically with the horizontal scrollbar removed. Setting a height of 110vh demonstrates this working:
body {
padding: 0;
margin: 0;
overflow-x: hidden;
}
.wrapper {
width: 200vw;
}
.section {
width: 100vw;
height: 110vh;
position: relative;
float: left;
}
.section1 {
background-color: red;
}
.section2 {
background-color: yellow;
}
<div class="wrapper">
<div class="section section1">1</div>
<div class="section section2">2</div>
</div>
Hope this helps! :)

how to set one image to the center bottom on another background image

hello i'm trying to set one image to the center bottom on another background image.
image contain one (ktm)Bike background image and on that another image of car which is at center bottom).
i have also tried background-position property as center bottom but still not working. i don't know how to do that. i have provided image in the comment box that what i'm exactly trying to make please refer that image don't ignore. and also provided my code what i have tried yet. please can anyone give show me example that how i do sorry but i'm really new to cascading style sheets. and do i need use to absolute property for that?
JSFiddle: jsfiddle.net/vr50vza2/1
.f4-pos {
position: absolute;
background-position: center bottom;
}
.footer {
background-image: url("../images/footer.png");
}
.foot4 {
background-image: url("../images/iauro-footer-logo.png");
}
.ban {
height: 800px;
background-size: 100% 100%;
}
.im3 {
height: 100px;
width: 300px;
}
.norep {
background-repeat: no-repeat;
}
<div class="footer ban norep">
<div class="foot4 f4-pos im3 norep"></div>
</div>
Like this? I removed some unnecessary css and the image, but you can return them later.
.footer {
position: relative;
border: 1px solid red;
}
.foot4 {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 0);
}
.ban {
height: 500px;
}
.im3 {
height: 100px;
width: 200px;
background-color: blue;
}
<div class="footer ban norep">
<div class="foot4 f4-pos im3 norep"></div>
</div>
Please Check out the FIDDLE : https://jsfiddle.net/NayanaDas/jw3dqb71/
.f4-pos
{
position: absolute;
background-position:center bottom;
}
.footer1
{
background-image: url("http://pre09.deviantart.net/49b5/th/pre/i/2015/160/1/9/skies__backround_practice__by_darklatias61-d8wm1wr.png");
}
.foot4
{
text-align: center;
position:fixed;
bottom:0;
width: 100%;
height:50px;
background-image: url("http://backgrounds.mysitemyway.com/wp-content/uploads/2009/03/watercolor-grunge-000100-glossy-rust.jpg");
background-size:100%;
}
.ban
{
height: 800px;
background-size:100% 100%;
}
.im3
{
height: 100px;
width : 300px;
}
.norep
{
background-repeat: no-repeat;
}
.footerWrap {
width:100%;
position:fixed;
bottom: 0px;
}
.footer {
width:400px;
margin:auto;
}
.footerContent {
float:left;
width:100%;
padding:20px 0;
}
.footer p {float:left; width:100%; text-align:center; }
You can do this with CSS Flexboxes. Please see my code below. Note that the magic is in the CSS for #img2Container. Also, see the JSFiddle.
<!doctype html>
<html>
<head>
<style type="text/css">
html, body {
margin: 0px;
padding: 0px;
height: 100%;
}
#img1 {
width: 100%;
height: 100%;
}
#img2Container {
position: absolute;
bottom: 0px;
height: 100px;
width: 100%;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-justify-content: center;
justify-content: center;
}
#img2 {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<img id="img1" src="http://lorempixel.com/600/600/" />
<div id="img2Container">
<img id="img2" src="http://lorempixel.com/100/100/" />
</div>
</body>
</html>
It's reasonable to believe that you could also wrap the image in another element and use margin: 0 auto. However, I like this method better because of the flexibility of CSS Flexboxes, allowing you to center more than one image and have them all centred evenly.
Please note that the img2Container has position absolute, which means that it scrolls with the page. If you would prefer, you could set it to sticky so that the remains in the viewing pane and positions it to the viewpane rather than the document.

How to vertically center a image in a div?

I have the following image in a div
<div id="left-control">
<img src="img/icons/ic_next_3x_re.png" />
</div>
Here is the css
#left-control {
height: 100%;
float: left;
}
#left-control > img {
display: block;
margin: 250px 0;
z-index: 1;
}
But for some reason I can't seem to vertically center the image no matter what CSS I try. Any suggestions?
There isn't an amazing way to accomplish this, but what is below should do the trick.
#left-control {
float: left;
height: 100%;
}
#left-control:before {
content: "";
display: inline-block;
vertical-align: middle;
height: 100%;
}
#left-control img {
vertical-align: middle;
z-index: 1;
}
Here is a simple fiddle. Keep in mind that I manually set the height for the #left-control element in this example since fiddle wasn't allowing for 100%.
You can use CSS tables to accomplish this.
.wrapper {
display: table;
height: 300px;
border: 1px solid black;
}
#left-control {
height: 100%;
display: table-cell;
vertical-align: middle;
}
#left-control > .img {
display: inline-block;
width: 100px;
height: 100px;
z-index: 1;
background: red;
}
<div class="wrapper">
<div id="left-control">
<div class="img"></div>
</div>
</div>
you could wrap the img, inside another div like so..
<div id="left-control">
<div class="vert-align">
<img src="img/icons/ic_next_3x_re.png" />
</div>
</div>
then, in the css do something like this...
#left-control {
height: 100%;
position:relative;
}
#left-control > img {
display: block;
margin: 250px 0;
z-index: 1;
}
.vert-align{
position: absolute:
margin: auto:
top:0; left:0; right:0; bottom:0;
height: 100px;
}
you can play with top left right and bottom properties to set it to the desired position.

Adjust height to floated element

<div class="view">
<img src="http://media-cache-ec2.pinterest.com/550x/cf/4f/36/cf4f36b3f25df6f6af27ca54012dedf1.jpg">
<div class="details">
Lorem....</div>
</div>
html, body {
height: 100%;
}
.view {
width: 500px;
}
img, .details {
width: 50%;
}
img {
float: left;
}
.details {
padding: 10px;
box-sizing: border-box;
overflow: hidden;
background: pink;
height: 100%;
}
Is there a way to make .details adjust to the height of img? Right now height: 100% does not seem to do the trick.
http://codepen.io/anon/pen/GbfJE
Simple workaround:
.view {
background:pink;
overflow:hidden;
}
You would have to use javascript (most easily jQuery), which would be quite easy...
Check out this solution:
http://codepen.io/anon/pen/sKtIb
Notice I have included the jQuery Javascript library