I am trying to setup background images using CSS but I can't seem to get the images to populate correctly.
Here is the CSS for what I want to do
a.fb {
background-image: url('img/Facebook.png');
}
a.fb:hover {
background-image: url('img/FacebookHover.png');
}
Here is the html code that I am using, I have tried a couple of different ways to populate the images with no luck
<div class="footer">
<a class="fb" href="http://www.facebook.com" target="_blank"></a>
</div>
Any help would be greatly appreciated
Okay added the following and still not go any other thoughts
a.fb {
display:block;
width: 33px;
height: 33px
background-image: url('img/Facebook.png');
}
EDIT: Yup got it working now forgot the ; after height, but no I get a white border around it and tried setting border: none; no luck
a.fb {
border: none;
display:block;
width: 33px;
height: 33px;
background-image: url('img/Facebook.png');
}
An anchor tag by default shows as an inline elements, so it depends on its content in order to get a height and width. To do what you want, you should add some styles: display:block; width: 20px; height: 20px.
You could also change the aproach completely and use html + mouseover and mouseout events:
<div class="footer">
<a class="fb" href="http://www.facebook.com" target="_blank">
<img src="http://www.facebook.com/images/fb_icon_325x325.png" alt="fb" name="fb" width="33px" height="33px" name="image_name" onmouseover="fb.src='http://goo.gl/cxiR7'; fb.width='38'; fb.height='38';" onmouseout="fb.src='http://www.facebook.com/images/fb_icon_325x325.png'; fb.width='33'; fb.height='33';" />
</a>
</div>
Here is a jsBin: http://jsbin.com/onehuw/1/edit
background-image only draws in the space that the element occupies. Your a tag has no content, and therefore it's width is 0. You'll not see any content (and background) until you give it at least some width (and height if needed).
You need to add padding to the <a> tag otherwise it has a width and height of 0 for example:
a.fb {
padding: 20px;
background-image: url('img/Facebook.png');
}
a.fb:hover {
background-image: url('img/FacebookHover.png');
}
You could also just set the width and height of the anchor
Related
<div class="profile">
<img src="image/JaeHeadShot.jpg" alt="Head Shot"/>
<h1> Jae Hong </h1>
</div>
.profile{
border: 2px solid rgba(0,0,0,0.3);
text-align:center;
padding: 30px;
}
img.profile{
width:423;
height:281;
}
Here are my HTML and CSS. I am not sure what I'm doing wrong, but the image won't get smaller. However, if I do
<img src="image/JaeHeadShot.jpg" alt="headshot" width="423" height="281"/>
the image seems to change. I just want to know why it's not working when I work on the CSS.
Appreciate your help!
The img.profile wont select the image since the image doesn't have a profile class, and the numbers are missing the units.
Do it like this:
img {
width : 423px;
height : 281px;
}
profile is the class for the div element, not for the image.
img.profile{
width:423;
height:281;
}
if you want to use special css for the image you can define a class for it.
.myImage{ width: 423px; height: 281px}
and use it in image tag.
<img src="image/JaeHeadShot.jpg" alt="headshot" class=".myImage"/>
The image doesn't have a class attribute in your code.So,accessing it with class profile won't fetch you image.
So,as there is only image,you can just give
img {
width:423;
height:281;
}
I have basic code with bootstrap and a svg sprit in a header / menu.. and there is a thin gray background line in the icons.
http://codepen.io/anon/pen/dpzKoQ?editors=1100
can you please help. I have tried setting
border-* etc to 0 - and I can fix. I set the colors / background - but some place I am missing something.
some place it is getting the below value from normalize.less
border-image-width: 1 ;
code: please see codepen.
.icon {
display: inline-block;
background-repeat: no-repeat;
background-image: url(https://cdn.rawgit.com/srisitar/test/master/sprite.svg);
}
.icon-facebook {
width: 96px;
height: 96px;
background-position: 0 0;
}
.icon-twitter {
width: 96px;
height: 96px;
background-position: -128px 0;
}
<
div id="home">
<a href=" ">
<img class="icon icon-twitter"></a>
</div>
how do remove the gray line.
thanks
It's because you are using an img tag with no src attribute. Chrome is essentially indicating the size of the container with nothing in it.
If you don't want to place an image between the anchor tags, then don't use an image tag. It's not necessary to place anything between the tags.
Demo here.
You can use div tag with background-image in css instead of using img tag.
When I use an img tag inside of an a tag, these little lines at the bottom show up. I've tried several css properties to remove them and couldn't find one that did the trick.
Relevant html:
<a href='https://github.com/'>
<img class='ContactLink' src='Images/Icons/GitHub.png' alt='GitHub'>
</a>
<a href='https://twitter.com/'>
<img class='ContactLink' src='Images/Icons/Twitter.png' alt='Twitter'>
</a>
<img class='ContactLink' src='Images/Icons/Gmail.png' alt='Email'>
CSS:
.ContactLink{
height: 50px;
width: 50px;
border: 0;
}
///Add this code in CSS file
a {
text-decoration:none;
}
use normalize css or try this
a,a:focus,a:hover,a:active{
text-decoration:none;
outline-width: 0;
}
img {
display:inline-block;
}
I will suggest to check the image files using any tool like photoshop and see if there is any transparent pixel there for that icon. Also try to keep the dimensions of all the three icon exactly same. If required edit the image accordingly.
I would like the top half of this image to display by default, and then use some CSS to make the image shift upward so that the bottom half shows when the mouse hovers over it. Here is the code and what I've tried, but it is not working. Can anyone help me make this code work?
HTML:
<div id="next">
<img src="images/next3.png" alt="next page">
</div>
CSS:
#next a:hover{background: url('images/next3.png') 0 -45px;}
EDIT:
HTML:
<div id="next">
</div>
CSS:
#next {
height:40px;
width:160px;
background-image:url('images/next3.png');
}
#next:hover{background-position: 100% 100%;}
I think you need to use background-position attribute to achieve this.
CSS
div
{
height:40px;
width:160px;
background-image:url('http://i.stack.imgur.com/OOGtn.png');
}
div:hover
{
background-position:100% 100%;
}
JS Fiddle Example
You can also look into CSS Sprites.
You need to use it as a background in the first place. The <img> is covering the background.
Get rid of the image HTML and just use some CSS like this
a {
display: inline-block;
height: 40px;
width: 160px;
background: transparent url(img.jpg) 0 0 no-repeat;
}
a:hover {
background-position: 0 40px;
}
In this case you will need to remove your <img> tag and consistently use the CSS background attribute for both cases. Also define your height and width width of your a tag with CSS too.
I have this code:
HTML:
<img class="d" src="i3.jpg" alt=""/><img class="d" src="i4.jpg" alt=""/>
CSS:
img.d{margin-top:10px;margin-left:20px;}
however, I want to put the i3.jpg in the CSS, not the html to further separate the structure from the presentation...how do I go about doing this.
Thanks.
Found this
link here
You can set the image as a background image of an element.
HTML:
<div class="d"></div>
CSS:
div.d{width:20px; height:20px; margin-top:10px; margin-left:20px; background:url('i3.jpg') 0 0 no-repeat;}
One option would be to use e.g. a div-element and attach a background image to it using CSS.
An img tag should be used when the image is content, like a cat wearing a fun costume. Moving image references to CSS can make sense when they're stylistic/UI and not content.
That said, the answer is to remove your img tags and replace them with divs. You can then set a background-image for the div, and just give it some basic properties to size/position it.
HTML:
<div class="d"></div>
CSS:
div.d {
display: block;
background-image: url('i3.jpg');
width: 100px; /* or whatever it should be */
height: 100px; /* or whatever it should be */
margin-top: 10px;
margin-left: 20px;
}