Reputation: 4266
I'm using background image property with one image of 1px*2px. The idea is to have black color on left and white on the right (1px each), because I have a picture that is black on the left and white on the right.
The result of what I did is that there is a gradient between black and white, but I don't want to because we see the gradient (gradient is bigger than picture width)
Here is the code with inline to be quick:
<body>
<div class="header-wrapper" style=
'background-image: url("../images/background.png"); background-repeat: no-repeat; background-size: 100%; padding-bottom: 0px;'>
<div style="text-align:center;">
<div style='display:inline;'><img src="~/images/ban.png"></div>
</div>
</div>
</body>
jsfiddle: http://jsfiddle.net/8gksgtdu/2/
I don't want to use css gradient for browser compatibility, even if customer only requested compatibility untill IE9 only.
Here is the result I have:
Here is what I want
Upvotes: 1
Views: 95
Reputation: 4054
I don't know what you want to do, but if you want one image streched, then put
background-size: 100% 100%
which will make the image big and streched
--edit---
I see that you have one 100%, try to put two 100%
-- edit---
Putting X-UA-Compatible in head tag
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=8; IE=9">
Seems to be fixing the background 100% issue.
Upvotes: 0
Reputation: 8246
Alternatively you could use a pseudo class:
.header-wrapper {
text-align:center;
background-color:white;
position:relative;
}
.header-wrapper:before {
content: '';
position:absolute;
top:0;
bottom:0;
left:0;
right:50%;
background-color:black;
z-index:50;
}
.header-wrapper img {
display:inline-block;
z-index:100;
position:relative;
}
<div class="header-wrapper"><img src="http://i.imgur.com/1Nidg46.png" /></div>
Upvotes: 0
Reputation: 4266
I finally used a larger picture than the first that I made (1*2 to 4*8px), it fixed mly issue - gradient still here but minimized (less width)
Upvotes: 0
Reputation: 8246
You don't need to use a background image, you can use CSS gradient to pull it off:
.black-white {
height: 300px;
width: 300px;
border: 1px solid red;
background: #000000; /* Old browsers */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+); /* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: -moz-linear-gradient(left, #000000 0%, #000000 50%, #ffffff 50%, #ffffff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#000000), color-stop(50%,#000000), color-stop(50%,#ffffff), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #000000 0%,#000000 50%,#ffffff 50%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #000000 0%,#000000 50%,#ffffff 50%,#ffffff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #000000 0%,#000000 50%,#ffffff 50%,#ffffff 100%); /* IE10+ */
background: linear-gradient(to right, #000000 0%,#000000 50%,#ffffff 50%,#ffffff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#ffffff',GradientType=1 ); /* IE6-8 */
}
<!--[if gte IE 9]>
<style type="text/css">
.black-white {
filter: none;
}
</style>
<![endif]-->
<div class="black-white"></div>
Generated from here.
Upvotes: 0
Reputation: 4155
Can you not use a couple more breakpoints:
background: linear-gradient(to right, #000000 0%,#000000 90%,#ffffff 90%,#ffffff 90%,#ffffff 100%);
http://jsfiddle.net/8gksgtdu/1/
Upvotes: 0