Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question Remove Underline from part of the Link

    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:

    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>
    Code:
    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;
    }

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    try setting text-decoration: none; on the appropriate links

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,315
    Thanks
    29
    Thanked 279 Times in 273 Posts
    Quote Originally Posted by zaltek View Post
    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).
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    New Coder
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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:

    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:

    Code:
    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;
    }

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    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. 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.
    Last edited by Excavator; 02-25-2011 at 04:15 PM.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •