Click to See Complete Forum and Search --> : Can we give links through css?
lohumihem
10-17-2007, 12:57 PM
Hi, Can we give links through css?
like i ve an image (logo img) and which is coming through css . can i give link to that image so that when ever i click on that it ll take me to that respective link.
i dont want to java script like onclick etc.
Thanx.
scragar
10-17-2007, 01:01 PM
not through CSS. Very possible to position a link around it or whatever though.
Mr Initial Man
10-17-2007, 01:03 PM
Turning an image into a link is VERY easy.
<a href="URL"><img src="ImageURL" alt="logo"></a> It is as simple as that. If you don't want a border around your image, add this to your CSS rules:
a img{border:0;}
scragar
10-17-2007, 01:05 PM
if the image is coming through CSS I'm gonna guess it's a background image...
Mr Initial Man
10-17-2007, 01:12 PM
Ah, okay. Well, you COULD have something like <a href="URL" id="LogoLink"></a>
Then have your CSS look like this:
#LogoLink{
display:block;
height:image height;
width:image width;
background-image: url(image url);
}
Something like that.
lohumihem
10-17-2007, 01:14 PM
Turning an image into a link is VERY easy.
<a href="URL"><img src="ImageURL" alt="logo"></a> It is as simple as that. If you don't want a border around your image, add this to your CSS rules:
a img{border:0;}
NO i mean like this i ve one image which is coming throgh css. As it is coming through css then it ll be bg image and i cant nt give link to bg images( as far as i know)
so it there any property in css like below
.logo{background-image:url(../images/logo.gif)" can i write some property HERE which ll jump me to any given link"}
Or some thing like this
<div onClick="open.window(http://www.yahoo.com)" class="logo"></div>
Mr Initial Man
10-17-2007, 01:26 PM
<a href="http://www.yahoo.com" class="logo"></a>
.logo{
display:block;
height:image height;
width:image width;
background-image: url(image url);
}
That's pretty much the only way to do it.
CSS does NOT create clickable hyperlinks.
WebJoel
10-17-2007, 04:31 PM
Make the container DIV (that has the background-image) itself, be 'the clickable anchor'..
CSS:#clickable {width:125px; height:75px; background-image:url();}
HTML:<a href="#"><div id="clickable"><!-- --></div></a>
The 'empty comments' are actually required for validation, as an 'empty DIV' causes a 'warning' to appear..
Centauri
10-17-2007, 05:28 PM
<a href="#"><div id="clickable"><!-- --></div></a>
You can't have a div inside an anchor tag - block elements are not allowed inside inline elements....
The example given by Mr Initial Man is the way to do it.
WebJoel
10-17-2007, 06:10 PM
Tried that, -realized the futility and falsity. :o Yes, Mr Initial Man's method is the way to use this. :)
lohumihem
10-17-2007, 11:18 PM
Tried that, -realized the futility and falsity. :o Yes, Mr Initial Man's method is the way to use this. :)
I tried like this
<a href="http://www.yahoo.com"> <div class="logo"></div></a>
.logo{width:229px; float:left; background-image:url(../images/logo.gif); background-repeat:no-repeat; height:30px; cursor:hand;}
It is working fine, I tried CURSOR:HAND for IE. coz it doesnt show Hand on hover.
I tried INITIAL MAN's method also. for that i dint use cursor property. i guess it is a right method to do.what you suggest
I need YOUR valuable comments.thanx
Mr Initial Man
10-17-2007, 11:43 PM
You'll run into validation problems with WebJoel's method; <div> does NOT belong in <a> But you made a minor mistake in cursor: It is cursor: pointer;.
lohumihem
10-18-2007, 12:15 AM
You'll run into validation problems with WebJoel's method; <div> does NOT belong in <a> But you made a minor mistake in cursor: It is cursor:pointer;.
Hey cursor:hand; also work i got this form google it self, BUT i am not going to use it coz i m trying your method,and ie doesnt create any problem for this.
Thanx
Mr Initial Man
10-18-2007, 12:17 AM
Sorry, that should have been cursor:pointer;
WebJoel
10-18-2007, 11:02 AM
"cursor:hand;" is IE-proprietory, going back to IE5.x. If you expect to have users of IE5.x visiting your site, you can write your cursor declarations this way:
"cursor: pointer; cursor: hand;"
The order here is significant, as IE5.x will choke if "pointer" comes last... It ignores "pointer", and compliant browsers ignore "hand"..