I have two images in the same directory. When I try to use one as a background image using css it does not show but when I use the other it does. What in the world is going on here?
Just for reference here is my css code.
This one does not work
a:hover {
background-image: url("images/menu-ident.png");
background-size: 110px;
background-repeat: no-repeat;
background-color: transparent;
background-position: bottom center;
color: rgba(255, 255, 255, 1);
}
This one does work
a:hover {
background-image: url("images/logo.png");
background-size: 110px;
background-repeat: no-repeat;
background-color: transparent;
background-position: bottom center;
color: rgba(255, 255, 255, 1);
}
of course this doesn't work - the second one overwrites the first one (same elements selected). if you want to have multiple background-images on the same element look here: https://w3schools.com/css/css3_backgrounds.asp
a:hover {
background-image: url("images/menu-ident.png"), url("images/logo.png");
background-size: 110px;
background-repeat: no-repeat;
background-color: transparent;
background-position: bottom center;
color: rgba(255, 255, 255, 1);
}
if you need two differents backgrounds for two different elements you need different css selectors like classes or ids:
a.bg-1:hover {
background-image: url("images/menu-ident.png");
background-size: 110px;
background-repeat: no-repeat;
background-color: transparent;
background-position: bottom center;
color: rgba(255, 255, 255, 1);
}
a.bg-2:hover {
background-image: url("images/logo.png");
background-size: 110px;
background-repeat: no-repeat;
background-color: transparent;
background-position: bottom center;
color: rgba(255, 255, 255, 1);
}
Related
I am applying this CSS rule to some divs on a web application. Basically I need to display a border around the div, but without using the border property.
It works on every browser but Firefox. Can anyone help me understand what I'm doing wrong?
div {
margin: 20px;
width: 100px;
height: 100px;
background-color: #F8F9FA;
background-image: radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px);
background-image: -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px), -moz-radial-gradient(#dedede 1px, rgba(255, 255, 255, 0) 1px);
background-position: top, right, bottom, left;
background-size: 1px 1px, 1px 1px;
background-repeat: repeat-x, repeat-y;
}
<div></div>
https://jsfiddle.net/za74L1st/1/
Many thanks!
This a job for linear-gradient not radial-gradient.
.box {
margin: 20px;
width: 100px;
height: 100px;
background-color: #F8F9FA;
background-image:
linear-gradient(#dedede,#dedede),
linear-gradient(#dedede,#dedede),
linear-gradient(#dedede,#dedede),
linear-gradient(#dedede,#dedede);
background-position: top, right, bottom, left;
background-size: 100% 1px,1px 100%;
background-repeat: no-repeat;
}
<div class="box"></div>
You are for sure facing subpixel rendring issue since you are defining very small circles having less than 1px radius. If you increase the values you will see something on Firefox:
.box {
margin: 20px;
width: 100px;
height: 100px;
background-color: #F8F9FA;
background-image:
/* doesn't matter what you put here as value since the background-size is already small */
radial-gradient(#dedede 51px, transparent 51px),
radial-gradient(#dedede 50px, transparent 50px),
radial-gradient(#dedede 99px, transparent 5px),
radial-gradient(#dedede 54px, transparent 54px);
background-position: top, right, bottom, left;
background-size: 1px 1px;
background-repeat: repeat-x, repeat-y;
}
<div class="box"></div>
I liked this book design in iBooks and have been wondering can it be easily made with css?
Original photo
have you tried gradients and shadows ?
.cover {
background: linear-gradient(to right, rgb(60, 13, 20) 3px, rgba(255, 255, 255, 0.5) 5px, rgba(255, 255, 255, 0.25) 7px, rgba(255, 255, 255, 0.25) 10px, transparent 12px, transparent 16px, rgba(255, 255, 255, 0.25) 17px, transparent 22px), url(https://images-na.ssl-images-amazon.com/images/I/51pnouuPO5L.jpg);
box-shadow: 0 0 5px -1px black, inset -1px 1px 2px rgba(255, 255, 255, 0.5);
margin: auto;
border-radius: 5px;
width: 389px;
height: 500px;
}
body {
min-height: 100vh;
display: flex;
}
<div title=" Don't make me think " class="cover"></div>
I think this could be pretty easily done with gradients in CSS. Here's a (very rough) example fiddle: https://jsfiddle.net/6yok9c4w/
HTML:
<div class="overlay">
</div>
<img src="https://images-na.ssl-images-amazon.com/images/I/51pnouuPO5L.jpg" />
CSS:
.overlay {
width: 400px;
height: 500px;
position: fixed;
top: 0;
left: 0;
background: linear-gradient(90deg, rgba(2,0,36,.5) 0%, rgba(0,0,0,.5) 2%, rgba(255,255,255,.5) 3%, rgba(247,254,255,.5) 5%, rgba(0,0,0,.5) 7%, rgba(255,255,255,.5) 13%, rgba(255,255,255,.2) 100%);
}
img {
position: fixed;
top: 0;
left: 0;
z-index: -1;
}
I used this tool to generate the gradient: https://cssgradient.io/
With more effort and tweaking, I think you can get really close to the original.
Is there a way to set the size of the image independent from the general size of the background with css?
With following code I set the size of the of the background, so the gradient and the image have the width of 30px.
background(url("../images/icons/double_arrow_37px.svg"), linear-gradient(to top bottom, rgb(171, 129, 85), rgb(148, 112, 74)));
background-size: 30px 37px;
What I need is to set the width of the image to 30px and the gradient to a width of 100% of the button.
I already know the workaround to create a extra image with the correct dimensions, but maybe there is a smarter way with css?
Full Example:
body {
background-color: #000;
}
.button-custom {
color: #fff;
font-family: $font-centennial;
background-image: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg");
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
margin-top: 70px;
padding: 15px 45px;
border-radius: 0;
border: 0;
text-transform: uppercase;
overflow: hidden;
}
.button-custom.bronze {
background-color: #ab8155;
}
.button-custom.bronze:hover {
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), -moz-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), -webkit-linear-gradient(bottom, #ab8155, #94704a);
background: url("http://metk.de/kunden/stackoverflow/double_arrow_37px.svg"), linear-gradient(to top bottom, #ab8155, #94704a);
background-position: center left;
background-size: 30px 37px;
background-position: center left;
background-repeat: no-repeat;
color: #fff;
}
Contact
In CSS3, you can use multiple images background. linear-background is interpreted as an image not a color. Known that, you can write something like that :
body {
height: 600px; /* not relevant for your problem */
width: 600px;
}
div {
height: 500px; /* not relevant for your problem */
width: 500px; /* not relevant for your problem */
border: 3px dashed green; /* not relevant for your problem */
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -moz-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -webkit-gradient(linear, left top, left bottom, color-stop(0%, red), color-stop(100%, blue));
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -webkit-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -o-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), -ms-linear-gradient(top, red 0%, blue 100%);
background: url("http://i436.photobucket.com/albums/qq90/KatDJZ/Forums/18556-Robot_Unicorn_Attack.jpg"), linear-gradient(to bottom, red 0%, blue 100%);
background-position: 50% 50%, 50% 50%;
background-repeat: no-repeat, no-repeat;
background-size: 150px, 300px;
}
<div>Yo!</div>
I have a solid background color on a button, and I'm looking for some CSS(3?) that would overlay a semi-transparent white on top of the color, but only on the top 50% of it. I'm looking for a non-gradient, non-image-based shine effect.
How can this be accomplished without using an image? It's ok if the solution doesn't support older browsers.
EDIT: bookcasey's answer below seems to work except the font is also made transparent...
<!DOCTYPE html>
<html>
<head>
<style>
a
{
display: inline-block;
padding:30px;
background: salmon;
position: relative;
text-align: center;
text-decoration:none;
color:#000;
font-size:20pt;
font-weight:bold;
}
a:before
{
content: '';
width: 100%;
height: 50%;
background: rgba(255,255,255,0.5);
position: absolute;
top: 0;
left:0;
}
</style>
</html>
<body>
<div>
Test Link
</div>
</body>
</html>
Thanks,
Andy
Use an absolutely positioned pseudo element on a relative parent.
Demo
a {display: block; width: 100px; height: 50px; background: salmon; position: relative;}
a:before {
content: '';
width: 100%;
height: 50%;
background: rgba(255,255,255,.5);
position: absolute;
top: 0;
left:0;
}
Another, completely different technique (mentioned, but not explained in the comments) is the use of CSS3 gradients with a hard color stop.
a {display: block; width: 100px; height: 50px; position: relative;
background: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(50%, rgba(255, 255, 255, 0)), color-stop(50%, rgba(255, 255, 255, 0.5))), salmon;
background: -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
background: -moz-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
background: -o-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
background: linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;}
Demo
For some reason my full page background in css is not working. I did this once before and it worked great, but now I get nothing but a white background. This is a section of my relevant css code:
* {
margin: 0;
padding: 0;
}
/* render html5 elements as block */
header, footer, section, aside, nav, article {
display: block;
}
html {
line-height: 1;
color: #555;
font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
background-image: url(file:///HD/Users/Barbra/Sites/HSMAI/images/vbcc_background.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
- moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* layout */
#wrapper {
width: 960px;
margin: 0 auto;
background-image: linear-gradient(bottom, #86D1C7 5%, #A8BCFA 53%);
background-image: -o-linear-gradient(bottom, #86D1C7 5%, #A8BCFA 53%);
background-image: -moz-linear-gradient(bottom, #86D1C7 5%, #A8BCFA 53%);
background-image: -webkit-linear-gradient(bottom, #86D1C7 5%, #A8BCFA 53%);
background-image: -ms-linear-gradient(bottom, #86D1C7 5%, #A8BCFA 53%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.05, #86D1C7),
color-stop(0.53, #A8BCFA)
);
border: 2px solid #333;
/* curved border radius */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
padding: 10px;
margin-top: 10px;
margin-bottom: 10px;
}
I am certain all files are in the proper place and all links are specified correctly.
The value for background-image is only the URL to the image.
If you put any other value, the declaration is invalid.
Change:
background-image: url(file:///HD/Users/Barbra/Sites/HSMAI/images/vbcc_background.jpg) no-repeat center center fixed;
to
background-image: url(file:///HD/Users/Barbra/Sites/HSMAI/images/vbcc_background.jpg)
or
background: url(file:///HD/Users/Barbra/Sites/HSMAI/images/vbcc_background.jpg) no-repeat center center fixed;
Give the background to the body element and it should work.
background-image: url(file:///HD/Users/Barbra/Sites/HSMAI/images/vbcc_background.jpg) no-repeat center center fixed;
should be
background: url('///HD/Users/Barbra/Sites/HSMAI/images/vbcc_background.jpg') no-repeat center fixed;