Forum Moderators: not2easy
Need some help with stylesheet issue :
We need to change the style for all hyperlinked content under a div tag except for hyperlinked graphics under the tag.
For example we need to add a dotted line underneath the hyperlinked text but the image should not have the dotted line.
<code>
#mydivname p a {
color: #0087BF;
border-bottom: 1px dotted #0087BF;
}
</code>
I tried putting following but that doesn't work.
<code>
#mydivname p a img {
text-decoraton: none;
}
</code>
Any ideas ?
I am new to this forum and stylesheets, so please let me know if I should post more details to clarify the issue.
Thanks for your help,
Meg
<html>
<head>
<style>
#mydivname p a {
color: #0087bf;
text-decoration: none;
}
#mydivname p span {
border-bottom: 1px dotted #0087bf;
}
#mydivname p a img {
border: none;
}
</style>
</head>
<body>
<div id="mydivname">
<p>
<a href="www.example.com">
<img src="aaa.jpg" style="width: 50px; height: 50px;"/>
<br />
<span class="border-bottom">
Link text.
</span>
</a>
</p>
</div>
</body>
</html>
CSS:
#myDiv p {
clear: left; /* This clears contents to flow under the floated image */
}
#myDiv p a{
color: #0087BF;
border-bottom: 1px dotted #0087BF;
text-decoration: none; /* Removes the standard underline from anchors */
width: 60px; /* Gives element enough room for the image */
height: 1.2em; /*This sets the border at the bottom of 1 line of text */
}
#myDiv p a img {
border: none; /* removes image borders */
float: left;
padding-top: 10px; /*gives image breathing room */
}
HTML:
<div id="myDiv">
<p><a href="#">A Link<img src="img.jpg" width="60" height="30" alt="" /></a></p>
<p> More Stuff</p>
</div>
rolandsea,
Thanks for your reply as well. Your suggestion sounds promising but didn't work for me.
Here's the html, did I miss something ?
<code>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<style type="text/css">
#myDiv p {
clear: left; /* This clears contents to flow under the floated image */
}
#myDiv p a{
color: #0087BF;
border-bottom: 1px dotted #0087BF;
text-decoration: none; /* Removes the standard underline from anchors */
width: 60px; /* Gives element enough room for the image */
height: 1.2em; /*This sets the border at the bottom of 1 line of text */
}
#myDiv p a img {
border: none; /* removes image borders */
float: left;
padding-top: 10px; /*gives image breathing room */
}
</style>
</HEAD>
<BODY>
<div id="myDiv">
<p><a href="#">A Link<img src="img.gif" alt="" /></a></p>
<p> More Stuff
<a href="http://www.abc.com" > <img src="img.gif"></a>
</p>
</div>
</BODY>
</HTML>
</code>
DOCTYPE has a huge implications on how this works (especially IE!)
Try this:
<code>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
.clear {
clear: left;
}
#myDiv p a {
color: #0087BF;
border-bottom: 1px dotted #0087BF;
text-decoration: none;
width: 100%;
/*height: 1em;*/
}
#myDiv p a img {
border:none;
float: left;
margin-top: .4em;
}
-->
</style>
</head>
<body>
<div id="myDiv">
<p><a href="http://www.abc.com/link1.html">The First Link<img src="img.jpg" width="200" height="200" alt=""></a></p>
<p class="clear"> <a href="http://www.abc.com/link2.html">The Second Link<img src="img.jpg" width="200" height="200" alt="" /></a></p>
<br class="clear" />
</div>
</body>
</html>
<code>
I am also assuming you have several images you are linking in such a way. I would suggest instead of a <p> tag to use an an unordered list, then wrap the the link in an header tag and follow the image with a <p> tag for a description. this can give you some nice display options also (vertical or horizontal).
Best of Luck
#mydivname img a {
text-decoration: none;
border: none;
}or simply
img a {
text-decoration: none;
border: none;
}
That makes no sense... how can you have an anchor within an image, an empty element?
The problem here, MKwebnovice, is that CSS cascades downwards, not upwards. We cannot change a property of the parent due to what children it has within it.
The anchor is the one with the bottom border... but the image is the part you don't want to have it.
I agree; the best options are to encase the text in a
<span>, or try a train of thought similar to that suggested by rolandsea, but hopefully with less complication. I suggest this:
HTML:
<a href="#">Text <img src="#" /></a> CSS:
a { border-bottom: 1px solid #f00;
text-decoration: none; } a img { position: relative;
bottom: -5px;
border-left: 5px solid #fff;
vertical-align: baseline; } What is happening:
So there you have it. IE 6, 7, FF 2, Safari 3, Opera 9 all tested.
Why this is better than rolandsea's float method:
rolandsea wrote:
.clear {
clear: left;
}
#myDiv p a {
color: #0087BF;
border-bottom: 1px dotted #0087BF;
text-decoration: none;
width: 100%;
/*height: 1em;*/
}
#myDiv p a img {
border:none;
float: left;
margin-top: .4em;
} width to an inline element such as an anchor will only work in IE, not in standards-compliant browsers, so I'm not sure what the point of that is; [edited by: Setek at 8:44 am (utc) on May 8, 2008]