...

View Full Version : Remove Underline from part of the Link



zaltek
02-25-2011, 12:53 AM
Hey guys, I'm using background-image within a div so it centers vertically with the rest of the links in my nav bar. But I don't want an underline to appear over the background-image (but I do want it to link). How can I remove the underline from just the part that goes over the image? Here's my page:

www.uatparts.com (it's the yellow Checkout link with the cart image to the right)

my code:



<div class="top_nav_bar_green_container">
<div class="top_nav_bar_green_left" style="width: 3%;">&nbsp;</div>
<div class="top_nav_bar_green_middle" style="width: 87%;">
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=SFNT&Store_Code=uatparts">Store Front</a>&nbsp;&nbsp;&nbsp;
<a href="https://www.uatparts.com/miva/merchant.mvc?Session_ID=711401268d5dfa0fee5077986fe1af91&Screen=LOGN&Order=0&Store_Code=uatparts">Account</a>&nbsp;&nbsp;&nbsp;
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=SRCH&Store_Code=uatparts">Search</a>&nbsp;&nbsp;&nbsp;
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=PLST&Store_Code=uatparts">Product List</a>&nbsp;&nbsp;&nbsp;
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=BASK&Store_Code=uatparts">Basket Contents</a>&nbsp;&nbsp;&nbsp;
</div>
<div class="top_nav_bar_green_right" style="width: 10%; text-align: right;"><a class="red_shopping_cart" href="https://www.uatparts.com/miva/merchant.mvc?Session_ID=711401268d5dfa0fee5077986fe1af91&Screen=OINF&Store_Code=uatparts">Checkout<span class="no_underline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a></div>
</div>




div.top_nav_bar_green_container {
padding: 0;
margin: 0;
border-spacing: 0;
text-align: left;
}

div.top_nav_bar_green_left {
float: left;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
background-color: green;
background-image:url('../graphics/en-US/mmui/hotdog/blades.gif');
background-repeat: no-repeat;
background-position: left center;
display: inline-block;
}

div.top_nav_bar_green_middle {
float: left;
background-color: green;
}

div.top_nav_bar_green_right {
float: left;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
background-color: green;
background-image:url('../images/shopping_cart.gif');
background-repeat: no-repeat;
background-position: right center;
display: inline-block;
}

a.red_shopping_cart:hover, a.red_shopping_cart:active {
background-image:url('../images/shopping_cart_red.gif');
background-repeat: no-repeat;
background-position: right center;
display: inline-block; /* If you remove this, the whole cart won't turn red. */
}

.no_underline:link, .no_underline:visited, .no_underline:hover, .no_underline:active {
text-decoration: none;
}

div.top_nav_bar_green_middle a:link, a.red_shopping_cart:link, div.top_nav_bar_green_middle a:visited, a.red_shopping_cart:visited { /* Links or visited links inside a top_nav_bar class. */
color: yellow;
text-decoration: none;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
}

div.top_nav_bar_green_middle a:hover, a.red_shopping_cart:hover, div.top_nav_bar_green_middle a:active, a.red_shopping_cart:active { /* Links hovered or active inside a top_nav_bar class. */
color: red;
text-decoration: underline;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
}

bullant
02-25-2011, 02:09 AM
try setting text-decoration: none; on the appropriate links

Arbitrator
02-25-2011, 03:50 AM
Hey guys, I'm using background-image within a div so it centers vertically with the rest of the links in my nav bar. But I don't want an underline to appear over the background-image (but I do want it to link). How can I remove the underline from just the part that goes over the image?You appear to be using (eight) space characters to create the room needed for your background image. Those characters are treated as normal text and, therefore, get underlined.

To fix this issue, you might want to use the padding-right CSS property to create the desired space instead of those space characters (because padding doesn't get underlined).

zaltek
02-25-2011, 07:33 AM
If I add padding, my div creates a new line and leaves a hole up top. :-(

www.uatparts.com (checkout the nav_bar with the green background color)

my code:



<div class="top_nav_bar_green_container">
<div class="top_nav_bar_green_left" style="width: 3%;">&nbsp;</div>
<div class="top_nav_bar_green_middle" style="width: 87%;">
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=SFNT&Store_Code=uatparts">Store Front</a>&nbsp;&nbsp;&nbsp;
<a href="https://www.uatparts.com/miva/merchant.mvc?Session_ID=711401268d5dfa0fee5077986fe1af91&Screen=LOGN&Order=0&Store_Code=uatparts">Account</a>&nbsp;&nbsp;&nbsp;
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=SRCH&Store_Code=uatparts">Search</a>&nbsp;&nbsp;&nbsp;
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=PLST&Store_Code=uatparts">Product List</a>&nbsp;&nbsp;&nbsp;
<a href="http://www.uatparts.com/miva/merchant.mvc?Screen=BASK&Store_Code=uatparts">Basket Contents</a>&nbsp;&nbsp;&nbsp;
</div>
<div class="top_nav_bar_green_right" style="width: 10%; padding-right: 30px; text-align: right;"><a class="red_shopping_cart" href="https://www.uatparts.com/miva/merchant.mvc?Session_ID=711401268d5dfa0fee5077986fe1af91&Screen=OINF&Store_Code=uatparts">Checkout</a></div>
</div>


CSS:



div.top_nav_bar_green_container {
padding: 0;
margin: 0;
border-spacing: 0;
text-align: left;
}

div.top_nav_bar_green_left {
float: left;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
background-color: green;
background-image:url('../graphics/en-US/mmui/hotdog/blades.gif');
background-repeat: no-repeat;
background-position: left center;
display: inline-block;
}

div.top_nav_bar_green_middle {
float: left;
background-color: green;
}

div.top_nav_bar_green_right {
float: left;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
background-color: green;
background-image:url('../images/shopping_cart.gif');
background-repeat: no-repeat;
background-position: right center;
display: inline-block;
}

a.red_shopping_cart:hover, a.red_shopping_cart:active {
background-image:url('../images/shopping_cart_red.gif');
background-repeat: no-repeat;
background-position: right center;
display: inline-block; /* If you remove this, the whole cart won't turn red. */
}

.no_underline:link, .no_underline:visited, .no_underline:hover, .no_underline:active {
text-decoration: none;
}

div.top_nav_bar_green_middle a:link, a.red_shopping_cart:link, div.top_nav_bar_green_middle a:visited, a.red_shopping_cart:visited { /* Links or visited links inside a top_nav_bar class. */
color: yellow;
text-decoration: none;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
}

div.top_nav_bar_green_middle a:hover, a.red_shopping_cart:hover, div.top_nav_bar_green_middle a:active, a.red_shopping_cart:active { /* Links hovered or active inside a top_nav_bar class. */
color: red;
text-decoration: underline;
font: italic bold 14px/160% Arial, Verdana, Helvetica, sans-serif;
}

Excavator
02-25-2011, 04:11 PM
Hello zaltek,
When you add padding, you are also adding to the width of that element. Your .top_nav_bar_green_right becomes 10% PLUS 30px wide.
Many times mixing % and pixels doesn't work well and this is a good example of that.

See the box model here (http://www.w3.org/TR/CSS2/box.html). The box model says that whatever you put inside an element cannot be larger than that element. margin/padding/border all could when figuring width/height.


A better solution might be to make that element a little wider or narrower, at the same time reducing/increasing the width of the element floating beside it so there is room for all on the same line.
Once .top_nav_bar_green_right is sized right, text-align: left; would give the appearance of right padding.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum