I have a 26x104 px image (so vertical oriented) containing 4 logo's, each a 26x26 px.
I want to use those 4 logo's as background for 4 hyperlinks.
So I have this:
HTML (this is the sequence I want)
<div class="rightfloat">
<a class="facebook"></a>
<a class="linkedin"></a>
<a class="twitter"></a>
<a class="mail"></a>
</div>
CSS:
.facebook, .linkedin, .twitter, .mail {
display: block;
width: 26px;
height: 26px;
background-image: url('style/socialmedia.png');
background-repeat: no-repeat;
}
.facebook {
background-position: 0px 0px;
}
.linkedin {
background-position: 0px -26px;
}
.twitter {
background-position: 0px -52px;
}
.mail {
background-position: 0px -78px;
}
For some reason only the first one appears but with other testing it also happend that the last icon appeared at the second link...so appearantely I don't get the logics behind it.
I looked for some example/tutorial but I can't find one.
Can someone give me a hand?
SOLUTION: I have put the coördinates in negative values and it worked...
You have to put the values as negative:
Working demo
SOLUTION: I have put the coördinates in negative values and it worked...
Related
My problem is that it doesn't replace the logo itself, I have been trying to solve this problem for a few days now during some of my spare time (I am new, hence why it has been so long).
Not sure how to solve this problem.
Code and Image below to provide more detail:
.navbar-brand {
width:200px;
height:200px;
box-sizing:border-box;
padding-left: 200px;
/*width of the image*/
background: url(https://web.archive.org/web/20180921071933im_/https://www.rolimons.com/images/logo-56x56.png) left top no-repeat;
}
The first R logo is supposed to replace the second R logo, instead it creates a separate one
Without seeing your HTML my guess is there is a child element inside .navbar-brand. So when you add the background image and padding-left you are making room for your new logo but the old one is still there.
If you inspect the logo area I bet you have an img element, another element, or a pseudo element that you have to style or hide like one of these:
Style:
.navbar-brand .some-other-element-class {
width: 200px;
height: 200px;
box-sizing: border-box;
padding-left: 200px;
/*width of the image*/
background: url(https://web.archive.org/web/20180921071933im_/https://www.rolimons.com/images/logo-56x56.png) left top no-repeat;
}
Hide:
.navbar-brand img {
display: none;
}
.navbar-brand::after {
display: none;
}
Edit
I think you're site is https://www.rolimons.com/ based on the image url, if so then my assumption that there is an img tag as a child of .navbar-brand is correct.
If you want the "new" logo to replace the old one you can use the hide technique above, BUT replacing the img src would probably be the better path forward if you can change that.
If You want to replace the logo with CSS you can hide the old logo image and set the new logo image as a background image.
<div id="logo_outer">
<img src="Logo.png">
</div>
<Style>
#logo_outer {
width: 200px;
height: 200px;
background-image: url(img url );
background-repeat: no-repeat;
background-position: center;
background-size: auto;
}
#logo_outer img {
display: none;
}
</style>
I have one image sheet like the one in this link (http://jquerytools.org/media/img/demo-navi.jpg).
I would like to get only a component of that image.
How can we get only component of image in CSS?
The correct terminology is CSS Sprite.
You can achieve this using background positioning:
div
{
background-image:url('http://jquerytools.org/media/img/demo-navi.jpg');
background-position:-20px 80px;
width:100px;
height:80px;
}
http://jsfiddle.net/Lz46r/
You can try this: http://www.guistuff.com/css/css_imagetech1.html
Cropping X and Y
That first image was kind of a softball. All the cool kids know how to take advantage of cropping an image in both axes. There are several reasons for doing this: You may have images of different sizes and want to place all of them within one file, for example. If you only crop on one axis, you'd be saving a file with the largest possible width or height of the array of images you want to use. Also, there are compression elements that you may want to take advantage of in the PNG file format, like keeping images with the same background color in the same horizontal row, and then having several rows.
Whatever the reason, there actually isn't much more to this than what we've seen so far. Here's another example image:
.icons
{
display: block;
width: 40px;
height: 40px;
background-image: url(images/sixicons.png);
background-repeat: no-repeat;
}
You can deduce from this class that the width and height of each icon is 40 pixels, and that the image file name is sixicons.png. I didn't create a very challanging example this time for X/Y cropping in the sense that all of the sub-images are of the same size. As you'll see, however, even if they weren't, you'd still be using a simimlar (though not exact) technique.
First, let's crop the top-left icon:
.icon_1 { background-position: 0px 0px; }
The markup would be:
<span class="icons icon_1"></span>
That was, of course, the easiest one. Now let's say we want the middle-bottom icon:
.icon_5 { background-position: -40px -40px; }
Let's see the CSS for all of the icons:
.icon_1 { background-position: 0px 0px; }
.icon_2 { background-position: -40px 0px; }
.icon_3 { background-position: -80px 0px; }
.icon_4 { background-position: 0px -40px; }
.icon_5 { background-position: -40px -40px; }
.icon_6 { background-position: -80px -40px; }
This should do what you need:
http://jsfiddle.net/8Eucw/1/
CSS:
#aBit {
background-image: url('http://www.google.co.uk/images/nav_logo107.png');
background-position-x: 114px;
background-position-y: 63px;
width: 18px;
height: 18px;
}
HTML:
<img src="http://www.google.co.uk/images/nav_logo107.png" /><br />
<hr />
<img id="aBit" />
You need to use CSS Sprites. There are some very simple tutorials here.
I have some css sprites on my site in the header but when the page loads it often loads several of the 8 separate images just below where it's meant to be. Then I wait a few seconds or hover my mouse over them and it goes back to the correct positions.
Here's my CSS:
.x {
display: inline-block }
.x a {
display:block;
width:100px;
height:100px;
overflow:hidden;}
.x a:hover img {
margin-left:-100px;}
and then the HTML goes like this:
<div class='x'><a href='link' alt='y'><img src=
'image' /></a></div>
<div class='x'><a href='link' alt='y'><img
src='image' />
</a></div>
for 8 separate 100x100 squares in a row.
The way to define css sprite is a bit different then how you are doing it.
Here is an example of how this can be achieved.
/* This is how to define a main image
.sprite { background: url("../link/to/spriteimage.png") 0px 0px; width: 32px; height: 32px; }
/* Assign an image like this way, by changing the position
.sprite.icon1 { background-position: -32px -32px; }
.sprite.icon1_hover { background-position: -64px -32px; }
Demo
I'm curently workign on this page and I'm trying to make the background repeat-y from a certain height but to no avail. If you look at the link's background (bottom area); you'll see that it leaves a an ugly space there, which is ugly. The CSS is as show below
body {
font-family:Calibri;
font-size: 16px;
margin: 0px;
padding: 0px;
background-color: #000;
background-image: url(images/bg.png);
background-repeat: repeat -200px 0px;
}
There's no way I'm aware of that makes the repeat skip some pixels. If I were you I would split them so the background-image of the body would be what the majority of it is now without the top. And then I would add a div to the top with these settings:
<div id="upperpart"></div>
in css:
#upperpart{
background-image: url(whatever it is);
width:100%;
height:how high it is
background-repeat: repeat-x;
margin-bottom: minus its height; <-- this will make everything below this div get ontop the div
}
After some mathematical thinking and experiments, the line of code below did the magic. I had to also watch where to cut it off with -1530px. Make sure you use the same background you used with the body tag.
html {
background: url(images/bg.png) repeat 0px -1530px;
}
I have an image, the top 80px of which I want to use for some other purpose, and remaining image, I want to set as a full page background image.
I tried setting:
background-position: 0px -80px
but it does not work.
How to properly use css sprite (background position) and full page background image?
Either of these (link or link) will generate a sprite for you and the corresponding css.
Once you have that completed use the css classes for their corresponding areas like:
.image1Background {
background-image: url("thesprite.png"),
left: -80px;
top: 0px;
}
.image2Background {
background-image: url("thesprite.png"),
left: 0px;
top: 0px;
}
<body class="image1Background">
<div class="image2Background">
</div>
</body>
Sprites are generally used for a lot of little icons to reduce the number of requests needed to download them to the client.
i would use a div for the 80px image and the background img as body background.. something like:
body { background-image: url(background.gif) }
#imgtop { height: 100%; width: 100%; background-image: url(80px_image.gif) }