This question already has answers here:
How are the points in CSS specificity calculated
(7 answers)
Closed 4 years ago.
I can not for the life of me figure out what seems so simple. And on top of that, I have this simple css problem which I can not figure out. :-)
I am trying to shift the position of a background image by changing the class. This does not have to happen within a single html file, and so javaScript is not involved.
This is like the classic "cropped toggle button" where the hover state moves the image a set number of pixels. However, it does not seem to work in this case.
In step1.html, my html looks like this:
<div id="progress" class="progress1">
<p>STEP 1/3 </p>
</div>
In step2.html, my html looks like this:
<div id="progress" class="progress2">
<p>STEP 2/3 </p>
</div>
Note the sole change is class="progress1" to class="progress2".
My css looks like this:
#progress{
position:relative;
display:block;
background: url(../images/progressBar.png) 65px 0px no-repeat !important;
width:565px;
height:36px;
line-height:36px;
margin:1em 0;
}
.progress1{
background: url(../images/progressBar.png) 65px 0px no-repeat !important;
}
.progress2{
background: url(../images/progressBar.png) 65px -36px no-repeat !important;
}
.progress3a{
background: url(../images/progressBar.png) 65px -72px no-repeat !important;
}
.progress3b{
background: url(../images/progressBar.png) 65px -108px no-repeat !important;
}
I have also tried add the full background declaration in the id, and only changing the position in the classes, like so: background-position: 65px -108px.
Try this:
#progress{
position:relative;
display:block;
background: url(../images/progressBar.png) 65px 0px no-repeat !important;
width:565px;
height:36px;
line-height:36px;
margin:1em 0;
}
#progress.progress1{
background: url(../images/progressBar.png) 65px 0px no-repeat !important;
}
#progress.progress2{
background: url(../images/progressBar.png) 65px -36px no-repeat !important;
}
#progress.progress3a{
background: url(../images/progressBar.png) 65px -72px no-repeat !important;
}
#progress.progress3b{
background: url(../images/progressBar.png) 65px -108px no-repeat !important;
}
The problem was that #progress selector was always higher specificity than .progress1 or .progress2 selector even with !important. So you need to keep the specificity on same "level" to be able to overwrite it with .progress1 or .progress2
Related
I have made a jsfiddle = https://jsfiddle.net/wLomyf65/
HTML:
<div class="skeleton-6euk0cm7tfi"></div>
CSS:
.skeleton-6euk0cm7tfi:empty {height: 100px; background-color: #ffffff; border-radius: 0px 0px 0px 0px; background-image: linear-gradient( #676b6f 6px, transparent 0 );background-repeat: repeat-y;background-size: 88px 100px;background-position: left 0px bottom 0px;}
I wish to vertically bottom align the linear gradient (so that its in the bottom left corner).
I have used: background-position: left 0px bottom 0px; but this hasn't done it.
A slight problem with the way you are setting things up is that the height of the element itself and the height of the background image (before you have sized it) are the same, and its drawing the gray for 6px from the top (the default direction for a linear-gradient) and the rest is transparent.
This snippet slightly simplifies what is going on.
It 'draws'a background image in the gray color, setting its width to 88% and its height to 6px and its position to bottom left. It sets it to not repeat on either axis.
body {
background: red;
}
.skeleton-6euk0cm7tfi:empty {
height: 100px;
background-color: #ffffff;
border-radius: 0px 0px 0px 0px;
background-image: linear-gradient( #676b6f, #676b6f);
background-repeat: no-repeat;
background-size: 88px 6px;
background-position: left bottom;
}
<
<div class="skeleton-6euk0cm7tfi"></div>
Is there a way to set a background css sprites image width?
shop
a{
background-image: url(http://placehold.it/60x60/ff0000/000&text=100)!important;
background-repeat: no-repeat;
display: block;
background-position: -5px -5px;
padding: 0 0 0 30px;
}
https://jsfiddle.net/jb1prcro/
right now the above a tag is 60px width, 30px for the word 'shop', 30px padding left for the cart icon,
because I am using css sprites for the background icons, right now it is showing 60px of that background image instead of just the 30px I want to show.
I also tried background-size: 30px 30px for this A tag, but it doesn't work.
You can use the pseudo-element before:
a{
display: inline-block;
background-position: -5px -5px;
padding: 0 0 0 30px;
height:30px;
vertical-align:middle;
}
a:before {
background-image: url(http://placehold.it/60x60/ff0000/000&text=100)!important;
background-repeat: no-repeat;
width:30px;
height:30px;
display:inline-block;
content:'';
vertical-align:middle;
}
Working example: https://jsfiddle.net/mspinks/jb1prcro/2/
I am not sure what exactly you are trying to achieve, but here's a practical example:
https://jsfiddle.net/ozL0yzuy/
a {
background-image: url(http://placehold.it/60x60/ff0000/000&text=100)!important;
background-repeat: no-repeat;
display: inline-block;
width: 40px;
background-position: -10px -20px;
}
You have to set a width (and actually also a height, which I didn't do in the example) for the element itself (in this case the a tag, which can only be done if its a block or inline-block element). Then you can adjust the background position accordingly.
Fiddle link:
https://jsfiddle.net/ildaroit/evL7tn6r/
.video-wrapper {
max-width: 640px;
margin: auto;
margin-top: 20px;
}
.video1 {
border: 0px dotted black;
height: 420px;
/*height:50vw;*/
background: url("http://learn.shayhowe.com/assets/images/triangles/triangles.svg") left -3px no-repeat, url("http://learn.shayhowe.com/assets/images/triangles/triangles.svg") right -3px no-repeat;
/* background-position: left, right;*/
background-repeat: no-repeat, no-repeat;
}
How to make the image not overlapping center div content on decreasing windows size?
Like here: learn.shayhowe.com
Now, left and right image overlap .video but need to make it fixed or something else.
Thx in advance!
hello do you mean like this?
https://jsfiddle.net/evL7tn6r/6/
just add a wrapper to your video1
.page{
width:100%; /*this is not really necessary*/
overflow:hidden;
}
and a min-width to the video
you can adjust the min-width to set the minimum space between the graphics
This question already has answers here:
Can I have multiple background images using CSS?
(8 answers)
Closed 8 years ago.
I'm attempting to add three social media icons through CSS. The company logo was added to the website through CSS (images/logo.png).
I've attempted extensions by adding commas, but that causes the entire logo to disappear.
Any CSS advice here would be greatly appreciated.
Update
The "duplicate" in question didn't address the position overlap issue I was having.
The multiple images issue is now resolved. The only issue I'm running into now is applying individual links to each social media button. Any advice?
#heading h1 {
text-align: left;
font-weight: normal;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
height: 92px;
background:#396ba5 url(images/logo.png) no-repeat 495px 0px;
}
Your current background has a colour specified in addition to the background images. In this case, the colour needs to be the last background specified. Only the last background can include a background color. Something like this should work:
#heading h1 {
text-align: left;
font-weight: normal;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
height: 92px;
background: url(images/logo.png) no-repeat 495px 0px,
url(images/twitter.png) no-repeat 495px 50px,
url(images/facebook.png) no-repeat 545px 50px,
url(images/facebook.png) no-repeat 545px 50px,
#396ba5;
}
Related: https://stackoverflow.com/a/5427455/1590962
I don't know why it is not working.
compare your code with this
background:
url(images/logo.png) 496px 0px no-repeat,
url(thingy.png) 10px 10px no-repeat,
url(Paper-4.png);
or
background-image: url(images/logo.png), url(ribbon.png), url(old_paper.jpg);
background-repeat: no-repeat;
background-position: left top, right bottom, left top;
or
background: url(images/logo.png) left top no-repeat, url(ribbon.png) right bottom no-repeat, url(old_paper.jpg) left top no-repeat;
Is there any way to apply multiple background images using sprites?
something like the below code?
background-image: url("../images/button-sprite.gif"),url("../images/button-sprite.gif");
background-position: right -92px, 0px 0px ;
background-repeat: no-repeat;
font-size: 1em;
margin-right: 5px;
padding-right: 35px;
width:500px;
height:500px
You can have multiple background images
see the EXAMPLE
Here is my css:
.sprite_box
{
background:
url(http://i.imgur.com/On0lt.png) -162px -551px no-repeat,
url(http://i.imgur.com/On0lt.png) -200px -530px no-repeat,
transparent;
height: 24px;
width: 81px;
margin:5px;
}
Read about sprite here
Here you can create sprite image
Here you create css for your sprite image
Yes, you can have multiple background images, but it is limited to box items. There is some info on this at CSS3.info
Yes, you can. The shorthand method is less verbose:
.sprite {
background:
url(http://www.google.com/images/srpr/nav_logo41.png) 0 -243px no-repeat,
url(http://www.google.com/images/srpr/nav_logo41.png) 42px -93px no-repeat,
#ccc;
width: 160px;
}
Note that you can only state one background color, and you state it at the end of the declaration.
See it in aciton http://jsfiddle.net/TMHPh/