I have an HTML code :
<li class="bath-icon">bath</li>
Where class="bath-icon" is defined in CSS as :
.bath-icon a {
background: url('images/room_bath.png');
background-size: auto 40%;
background-repeat: no-repeat;
background-position: 50% 20px;
background-color: #7E7C14;
opacity: 0.8;
}
Now I want to replace background image room_bath.png with an image from a sprite image with values as:
.room_bath {
width: 107px;
height: 64px;
background: url('images/sprite.png') -0 -952px;
}
Can anyone help me how both CSS can be cascaded and background image from sprite is inserted in .bath-icon class?
You can create variable in css and refer the variable in your css declaration.
:root {
--room-bath-bg: url('images/sprite.png') -0 -952px;
}
.bath-icon a {
background: var(--room-bath-bg);
background-size: auto 40%;
background-repeat: no-repeat;
background-position: 50% 20px;
background-color: #7E7C14;
opacity: 0.8;
}
Like above you can create your variable and refer in any places. The variable declaration should start with -- to identify the system.
NOTE: This mehtod is supported by only modern browsers.
Refer this W3 Schools CSS3 Variables to learn more details about this.
Related
Hi I have the following CSS class and dom element
<button [ngClass]="{ 'filter-icon-open': open, 'filter-icon-close': !open }">
</button>
css
.open-filter {
cursor: pointer;
float: right;
button {
width: 40px;
height: 40px;
background-repeat: no-repeat;
background-position: center;
background-size: initial;
}
button:hover {
background-image: url("./../../../../assets/images/ico_filter_over.png");
background-color: $dbsred;
border: none;
}
button:focus {
outline:none;
}
}
.filter-icon-open {
background-image: url("./../../../../assets/images/ico_filter_over.png");
background-color: red;
}
.filter-icon-close {
background-image: url("./../../../../assets/images/ico_filter.png");
border: solid #B3B3B3 1px;
}
It's working perfectly for chrome. But for IE the icon is big. How to solve this. newbie to CSS. can someone help. Thanks in advance.
Tried:
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='./../../../../assets/images/ico_filter.png', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='./../../../../assets/images/ico_filter.png', sizingMethod='scale')";
but i see this part been commented out in chrome and it didnt worked as well.
initial is not supported on IE. For IE the permitted values for background-size
as per documentation are :
background-size: [ <length> | <percentage> | auto ] {1,2} | cover | contain [ , [ <length> | <percentage> | auto ] {1,2} | cover | contain ]*
Additionally, initial just sets the property to the default value of the property and for background-size the default value is auto. So you can use that directly or use any of the above values.
If the problem is that the open and close images are different sizes, You can use CSS to resize the images in the browser:
.filter-icon-open {
background-image: url("./../../../../assets/images/ico_filter_over.png");
background-color: red;
height : 100px;
width : 100px;
}
.filter-icon-close {
background-image: url("./../../../../assets/images/ico_filter.png");
border: solid #B3B3B3 1px;
height : 100px;
width : 100px;
}
This will force both the open and close image to be the same size, however, I personally recommend against that approach, since it could cause skewing or pixelation of the image.
A better solution is to resize the images using an image editing tool of your choice, such as Photoshop.
I've recently encountered some problems with CSS Sprites.
I want them to switch pictures every function call, function itself is OK since it only removes and adds css class.
I have following CSS:
#slider_arrow {
padding-left: 200px;
position: relative;
top: -1px;
}
.red_arrow_sprite {
background: url(/Images/onex/arrows.png) 0 0 no-repeat;
width: 25px;
height: 12px;
}
.yellow_arrow_sprite {
width: 25px;
height: 12px;
background: url(/Images/onex/arrows.png) -26px 0 no-repeat;
}
.black_arrow_sprite {
width: 25px;
height: 12px;
background: url(/Images/onex/arrows.png) -51px 0 no-repeat;
}
Slider_arrow is:
<span id="slider_arrow" class="red_arrow_sprite"></span>
the element in which I change class.
And the problem is that my Sprite file has 75px width and 25px height.
(3x 25px/25px)
With the CSS I Presented I get the result where I see all 3 pictures at the time with red_arrow_sprite class, 2 pictures with yellow_arrow_class and 1 picture which is desired with black_arrow_class.
What have I done wrong with CSS?
Thanks in advance.
http://jsfiddle.net/9b57pb50/
Check out this solution
I've removed padding and add some display properties.
Here is my css
.nav_arrow {
position: absolute; top: 50%; z-index: 15;
background-image: url(../img/arrow-navpage.png) !important;
width: 34px; height: 136px;
margin-top: -68px; }
.nav_arrow.next { right: -34px; background-position: 0 0; }
.nav_arrow.next:hover { background-position: 0 -186px; }
.nav_arrow.prev { left: -34px; background-position: 0 -372px; display: none; }
.nav_arrow.prev:hover { background-position: 0 -558px; }
Image is for next / previous button background
But its not loading in. can any one help me
Use Elements inspector (press F12) to see if the images are being loaded.
In Elements Tab you can see if your CSS rule is correct, or by right
clicking over the element itself
Under Resources Tab you can see if the Image Path is correct and if
the image are being loaded.
If those chechs are correct, probably you have a visualization problem with your CSS rule, probably position related.
Try it and tell us the result.
Hope it helps.
It's hard to see the problem without a fiddle. But first check if the sprites image is loaded, then check background-position for every piece of the image. Also check if the .nav-arrow container has position:relative
maybe try this:
.nav_arrow.next { right: -34px; background-position: 0px 0px; }
.nav_arrow.next:hover { background-position: -186px 0px; }
.nav_arrow.prev { left: -34px; background-position: -372px 0px; display: none; }
.nav_arrow.prev:hover { background-position: -558px 0px; }
I don't know why you use left:-34px right:-34px; if this answer not help you show us your code
So I've got a series of clickable images in my page. I've tried to optimise this by generating a single image containing all the images I need and I intend to use sprites to select the one I want. I'm having trouble figuring out the best way to add anchor tags to the sprites though?
So I'm after a clickable HTML element that supports sprites, preferably without using JavaScript. I can do it using JavaScript but I'd prefer to avoid it.
OK, here's my code, what there is:
.touringEscorted {
height:125px;
width: 214px;
background-image: url('/Images/Travel2New/ToursImages/ToursBanners.jpg');
background-position: 0 0;
}
.touringNew {
height:125px;
width: 214px;
background-image: url('/Images/Travel2New/ToursImages/ToursBanners.jpg');
background-position: -10px 0;
}
I've tried
<div class="touringEscorted">
and
and several others. Seems there's no way to use sprites/background images and anchor tags at the same time. Am I right?
Any suggestions?
Ok then :
Should work, but adding display:block; to the CSS :
.touringEscorted {
height:125px;
width: 214px;
background-image: url('/Images/Travel2New/ToursImages/ToursBanners.jpg');
background-position: 0 0;
display:block;
}
Like this?
<a class="sprite sprite1" href="javascript:;">Link Text</a>
sprite {
display: block;
background: url(path/to/image/file.ext);
text-indent: -9999px;
}
sprite1 {
width: WWpx;
height: HHpx;
background-position: -NNpx - MMpx;
}
Doesn't Google consider off screen text as spammy? I came up with a modification. I put the link in another element, in this case a table. I added the background image class in the element and in the link like this:
CSS code:
.sprite{
background: url('images/sprite.png') no-repeat top left;
}
.sprite.termite {
background-position: 0px -499px;
width: 150px; height: 113px;
display: block;
}
HTML code:
<td class="td sprite termite">
</td>
It renders the image in the table perfectly and clicks!
I am currently working on an HTML5 form and using CSS3 for the styling. I have added CSS for input:required and input:valid and input:invalid to make an image get shown inside the text box.
Both the required and invalid CSS work fine but for some reason input:valid gets ignored and is just replaced with the same image as input:required.
Below is the CSS that I have used
input:required.fields, textarea:required.fields, select:required.fields
{
background:url("images/asterix.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
}
input:focus:required:invalid.fields, textarea:focus:invalid.fields, select:focus:invalid.fields
{
background:url("images/error.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
Both CSS sections above work fine without any problems but its the CSS below that for some reason is not working.
input:valid.fields, textarea:required:valid.fields, select:value.fields
{
background:url("images/tick.png");
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
In case it was to do with the image not being found I made the invalid image be the tick.png image and this worked fine but the valid section never seems to get called.
Thanks for any help you can provide.
I just used the following on my form:
input[required]:invalid {
background: #efdee0 url(../images/invalid.png) no-repeat center right;
}
input[required]:valid {
background: #f3f8ed url(../images/valid.png) no-repeat center right;
}
but then my fields are all required (http://www.paul-ellis.co.uk/contact.htm)