Set gradient background for select in chrome - html

I want to style a select and it works almost perfectly but on google chrome behvior is different and I fixed that with -webkit-appearance: none; but this delete also select arrow.
I try to set an arrow for my select but it is not visible in chrome because I use multiple backgrounds. What can I do to set that arrow on chrome.
select{
width:120px;
margin:10px;
background:url(http://s14.postimage.org/jls6v1ywt/select_background.png),
url(http://s13.postimage.org/edsg65ss3/select_arrow.jpg);
background-position: center center,100% 53%;
background-repeat: repeat-x, no-repeat;
border:1px solid #DDDBD7;
-webkit-appearance: none;
}
check my example:
http://jsfiddle.net/DCjYA/359/

Swap the order of the backgrounds, so that the "arrow" background is on top.
http://dev.w3.org/csswg/css3-background/#layering
The first image in the list is the layer closest to the user, the next one is painted behind the first, and so on. The background color, if present, is painted below all of the other layers.
See: http://jsfiddle.net/thirtydot/DCjYA/361/
background: url(http://s13.postimage.org/edsg65ss3/select_arrow.jpg), url(http://s14.postimage.org/jls6v1ywt/select_background.png);
background-position: 100% 53%, center center;
background-repeat: no-repeat, repeat-x;

select {
padding:9px;
margin: 0;
border-radius:4px;
-webkit-box-shadow:
0 0px 0 #ccc,
0 0px #fff inset;
background: url('http://i45.tinypic.com/309nb74.png') no-repeat right, -moz-linear-gradient(top, #FBFBFB 0%, #E9E9E9 100%);
background: url('http://i45.tinypic.com/309nb74.png') no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FBFBFB), color-stop(100%,#E9E9E9));
color:black;
border:none;
outline:none;
display: inline-block;
-webkit-appearance:none;
cursor:pointer;
border: 1px solid #ccc;
}
This piece of code will fix your problem. Just change the padding and use local images or color codes a/c to your need. or use this to generate the code for you.
See: JS fiddle for background gradient and down arrow

Related

how to add a color overlay to a background image [duplicate]

I have panel which I colored blue if this panel is being selected (clicked on it). Additionally, I add a small sign (.png image) to that panel, which indicates that the selected panel has been already selected before.
So if the user sees for example 10 panels and 4 of them have this small sign, he knows that he has already clicked on those panels before. This work fine so far. The problem is now that I can't display the small sign and make the panel blue at the same time.
I set the panel to blue with the css background: #6DB3F2; and the background image with background-image: url('images/checked.png'). But it seems that the background color is above the image so you cannot see the sign.
Is it therefore possible to set z-indexes for the background color and the background image?
You need to use the full property name for each:
background-color: #6DB3F2;
background-image: url('images/checked.png');
Or, you can use the background shorthand and specify it all in one line:
background: url('images/checked.png'), #6DB3F2;
For me this solution didn't work out:
background-color: #6DB3F2;
background-image: url('images/checked.png');
But instead it worked the other way:
<div class="block">
<span>
...
</span>
</div>
the css:
.block{
background-image: url('img.jpg') no-repeat;
position: relative;
}
.block::before{
background-color: rgba(0, 0, 0, 0.37);
content: '';
display: block;
height: 100%;
position: absolute;
width: 100%;
}
Based on MDN Web Docs you can set multiple background using shorthand background property or individual properties except for background-color. In your case, you can do a trick using linear-gradient like this:
background-image: url('images/checked.png'), linear-gradient(to right, #6DB3F2, #6DB3F2);
The first item (image) in the parameter will be put on top. The second item (color background) will be put underneath the first. You can also set other properties individually. For example, to set the image size and position.
background-size: 30px 30px;
background-position: bottom right;
background-repeat: no-repeat;
Benefit of this method is you can implement it for other cases easily, for example, you want to make the blue color overlaying the image with certain opacity.
background-image: linear-gradient(to right, rgba(109, 179, 242, .6), rgba(109, 179, 242, .6)), url('images/checked.png');
background-size: cover, contain;
background-position: center, right bottom;
background-repeat: no-repeat, no-repeat;
Individual property parameters are set respectively. Because the image is put underneath the color overlay, its property parameters are also placed after color overlay parameters.
And if you want Generate a Black Shadow in the background, you can use
the following:
background:linear-gradient( rgba(0, 0, 0, 0.5) 100%, rgba(0, 0, 0, 0.5)100%),url("logo/header-background.png");
You can also use short trick to use image and color both like this :-
body {
background:#000 url('images/checked.png');
}
really interesting problem, haven't seen it yet. this code works fine for me. tested it in chrome and IE9
<html>
<head>
<style>
body{
background-image: url('img.jpg');
background-color: #6DB3F2;
}
</style>
</head>
<body>
</body>
</html>
The next syntax can be used as well.
background: <background-color>
url('../assets/icons/my-icon.svg')
<background-position-x background-position-y>
<background-repeat>;
It allows you combining background-color, background-image, background-position and background-repeat properties.
Example
background: #696969 url('../assets/icons/my-icon.svg') center center no-repeat;
This actually works for me:
background-color: #6DB3F2;
background-image: url('images/checked.png');
You can also drop a solid shadow and set the background image:
background-image: url('images/checked.png');
box-shadow: inset 0 0 100% #6DB3F2;
If the first option is not working for some reason and you don't want to use the box shadow you can always use a pseudo element for the image without any extra HTML:
.btn{
position: relative;
background-color: #6DB3F2;
}
.btn:before{
content: "";
display: block;
width: 100%;
height: 100%;
position:absolute;
top:0;
left:0;
background-image: url('images/checked.png');
}
Here is how I styled my colored buttons with an icon in the background
I used "background-color" property for the color and "background" property for the image.
<style>
.btn {
display: inline-block;
line-height: 1em;
padding: .1em .3em .15em 2em
border-radius: .2em;
border: 1px solid #d8d8d8;
background-color: #cccccc;
}
.thumb-up {
background: url('/icons/thumb-up.png') no-repeat 3px center;
}
.thumb-down {
background: url('/icons/thumb-down.png') no-repeat 3px center;
}
</style>
<span class="btn thumb-up">Thumb up</span>
<span class="btn thumb-down">Thumb down</span>
Assuming you want an icon on the right (or left) then this should work best:
.show-hide-button::after {
content:"";
background-repeat: no-repeat;
background-size: contain;
display: inline-block;
background-size: 1em;
width: 1em;
height: 1em;
background-position: 0 2px;
margin-left: .5em;
}
.show-hide-button.shown::after {
background-image: url(img/eye.svg);
}
You could also do background-size: contain;, but that should be mostly the same. the background-position will depened on your image.
Then you can easily do an alternative state on hover:
.show-hide-button.shown:hover::after {
background-image: url(img/eye-no.svg);
}
You can try with box shadow: inset
.second_info_block {
background: url('imageURL');
box-shadow: inset 0 0 0 1000px rgba(0,0,0,.4);
}
<li style="background-color: #ffffff;"><img border="0" style="border-radius:5px;background: url(images/picture.jpg') 50% 50% no-repeat;width:150px;height:80px;" src="images/clearpixel.gif"/></li>
Other Sample Box Center Image and Background Color
1.First clearpixel fix image area
2.style center image area box
3.li background or div color style
body
{
background-image:url('image/img2.jpg');
margin: 0px;
padding: 0px;
}

CSS - fading gradient border from-to

I want to make my whole div section with fading border. Here is my code:
.usermanagement {
-webkit-border-image: -webkit-gradient(
linear,
left top,
left bottom,
from(#fff),
to(#afd4ec),
color-stop(0.2, #afd4ec)
)
0 0 0 0 repeat repeat;
}
The effect is exactly what I want but only for top:
Then all goes to light blue and finishes like this:
Without this fading effect. I want to make the same effect as in the top for the bottom end of the section. How it is possible?
You can try like below. make sure to correctly set the different values.
.box {
height:50px; /* this need to be a multiple of 10 for the effect to work */
border-top: 10px solid;
border-bottom:10px solid;
background:#f2f2f2;
border-image:repeating-linear-gradient(#fff 0,red 10px) 10;
}
<div class="box"></div>
You can also do it with multiple background:
.box {
height:50px;
border-top:10px solid transparent;
border-bottom:10px solid transparent;
background:
linear-gradient(#fff ,red ) top,
linear-gradient(#fff ,red ) bottom, /* use (red, #fff) here for the opposite effect */
#f2f2f2;
background-size:100% 10px;
background-origin:border-box;
background-repeat:no-repeat;
}
<div class="box"></div>

CSS h1 spotted/dotter border

I have the following code that sets a dotted/spotted bottom border on 'h1' tags.
The full code can be found at moorparksdevon.uk
h1 {
padding: 0 0 7px 0;
margin: 0 0 10px 0;
display:table;
background-image: linear-gradient(to right, black 33%, rgba(255,255,255,0) 0%);
background-position: bottom;
background-size: 3px 1px;
background-repeat: repeat-x;
}
However... I don't appear to have consistent results in the slightest. Am I missing something here?
Safari Mac - Lots of dots working (https://i.stack.imgur.com/MAHgm.jpg)
Firefox Mac - Some dots working (https://i.stack.imgur.com/mzRTM.png)
Chrome Mac - No dots at all (https://i.stack.imgur.com/5sYfL.jpg)
You can just use CSS border-bottom to set a dotted border.
jsfiddle: https://jsfiddle.net/mmkctq59/

Two different gradients in one html button

What I am trying to do is I want to keep the top 50% of the html button to have a gradient say from #FFF to #BBB and the bottom 50% should remain in one color lets say #111. I can't figure out a way to do it, any help would be largely appreciated.
The code of my button is:
<button class="Button1" type="submit">Submit</button>
The css:
.Button1 {
background-image: linear-gradient(to bottom, #fff 0%, #bbb 50%, #111 50%);
}
This should do the trick in latest browsers. It's up to you to make it cross-browser compatible. (I personally like the Photoshop-esque interface of http://www.colorzilla.com/gradient-editor/)
Here is a sample from Bootstrap that should help you out with button gradients. This also covers most modern browsers.
.btn-info {
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0,0,0,0.25);
background-color: #49afcd;
background-image: -moz-linear-gradient(top,#5bc0de,#2f96b4);
background-image: -webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#2f96b4));
background-image: -webkit-linear-gradient(top,#5bc0de,#2f96b4);
background-image: -o-linear-gradient(top,#5bc0de,#2f96b4);
background-image: linear-gradient(to bottom,#5bc0de,#2f96b4);
background-repeat: repeat-x;
border-color: #2f96b4 #2f96b4 #1f6377;
border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de',endColorstr='#ff2f96b4',GradientType=0);
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
}
Hope that helps.(these are sort of teal, so you'll have to change that part)

Styling a button using CSS and mutiple images from a spritesheet

I have the following image in a sprite sheet and want to use it to style a button:
I have tried everything I can think of (even going as far as pseudo elements) but I can't get it to work. I had thought something like this should work:
.ui-button {
height:45px;
background-image: url(../button.png), url(../button.png), url(../media/button.png);
background-size: 8px 45px, 8px 45px, 3px 45px !important;
background-position: -63px -1px, -77px -1px, -73px -1px;
background-repeat: no-repeat, no-repeat, repeat;
}
but it doesn't. The background-size bits are the size of each chunk from the sprite sheet that I am using and the position is the top left coordinates of each part in the sprite sheet. Clearly I am doing something wrong. What?
Edit: here's the whole image:
Here is what I have tried with JSFiddle:
http://jsfiddle.net/Kpusc/
.ui-button {
height:45px;
width:18px;
background: url(http://i.stack.imgur.com/ipKrd.png);
background-position: -72px -1px;
background-repeat: no-repeat;
position:relative;
border:0;
}
.ui-button:before {
content:"";
display:block;
height:45px;
width:8px;
background: url(http://i.stack.imgur.com/ipKrd.png);
background-position: -64px -1px;
background-repeat: no-repeat;
position:absolute;left:0;top:0;
}
.ui-button:after {
content:"";
display:block;
height:45px;
width:8px;
background: url(http://i.stack.imgur.com/ipKrd.png);
background-position: -78px -1px;
background-repeat: no-repeat;
position:absolute;right:0;top:0;
}
​
Unfortunately I only could make it as wide as 34px. Since I can't make the center content to repeat itself.
I suppose you need to make the center part wider than at least 60px so that it could be applied as the .ui-button background-image (or perhaps make it as a separate file altogether, so it would be possible to repeat).
I'd like to know if there's another workaround though.