Quick css hover question

Discussion in 'CSS' started by fadetoblack22, Jul 1, 2009.

  1. #1
    I have this html:

    <a href="">
    <div class="post_bottom">
    <p class="post_bottom_text">text in here</p>
    </div>
    </a>

    and this is the css:

    .post_bottom {
    position: relative;
    background: url(bottom.jpg)no-repeat;
    width: 640px; height: 140px;
    }

    p.post_bottom_text {
    position: absolute;
    bottom: 20px;
    left: 200px;
    width: 350px;
    font-weight: bold;
    text-align: center;
    color: #d33c3d;
    }

    How do I make the text underline when I hover over the post_bottom div holding the background image?

    thanks.
     
    fadetoblack22, Jul 1, 2009 IP
  2. KnuTz

    KnuTz Well-Known Member

    Messages:
    169
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    Digital Goods:
    1
    #2
    uhm i suggest you used this html code
    
    <div class="post_bottom">
    <p class="post_bottom_text"><a href="">text in here</a></p>
    </div>
    
    HTML:
    instead of

    
    <a href="">
    <div class="post_bottom">
    <p class="post_bottom_text">text in here</p>
    </div>
    </a>
    
    HTML:

    then you can add this to your css

    
    .post_bottom a{
     text-decoration:underline;
    }
    
    Code (markup):
     
    KnuTz, Jul 1, 2009 IP
  3. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I generally agree with Knutz, and the HTML s/he provided is excellent.

    However the default for anchors is already underlining. So, normally they would already be underlined. So maybe you're removing the underline? If that's the case then modify Knutz' post to something like:

    .post_bottom a:focus, .post_bottom a:hover {
    text-decoration:underline;
    }

    Yeah, :focus baby!
     
    Stomme poes, Jul 2, 2009 IP
  4. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #4
    I have got it to underline when the text is hovered over, but I moved the a href so that the text would underline when I hovered over the box that it was in.

    If I move the a href back around the text and put .post_bottom a{
    text-decoration:underline;
    }

    it will be back where I started.

    Does that make sense?

    thanks.
     
    fadetoblack22, Jul 2, 2009 IP
  5. unigogo

    unigogo Peon

    Messages:
    286
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    .post_bottom a{
    text-decoration:none;
    }
    .post_bottom a:hover{
    text-decoration:underline;
    }
     
    unigogo, Jul 2, 2009 IP
  6. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #6
    Thats what I tried to start with and I didn't work :(
     
    fadetoblack22, Jul 2, 2009 IP
  7. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The html source should be like this .
    <div class="post_bottom">
    <p class="post_bottom_text"><a href="">text in here</a></p>
    </div>

    Using the <a> tag to wrap the <div> tag (block elements) is not allowed .
    Fix the html problems and then discuss the css . Good luck .
     
    justinlorder, Jul 3, 2009 IP
  8. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Correct. You can't do this:
    <a href="#"><div> stuff</div></a>

    An anchor is an inline, and inlines are like water. Divs are blocks, which are like buckets. Buckets can hold water, but water can't hold a bucket. This is even if you change the anchor to display: block in the css&#8212; the HTML rules still apply.

    If you aren't worried about IE6 not working, you can do this (with Knutz' code):

    div:hover a {
    text-decoration: underline;
    }

    it says when the div gets hovered, the anchors inside of it get underlined.

    IE6 can't hover over non-anchors so for IE6 at least make it that the anchor itself can get underlined:

    div:hover a {
    text-decoration: underline;
    }
    * html div a:hover {
    text-decoration: underline;
    }


    so that at least IE6 users get something.
     
    Stomme poes, Jul 3, 2009 IP
  9. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #9
    But this way it doesn't do what I want because they text only underlines when I hover over the text rather than the box it contains.
     
    fadetoblack22, Jul 3, 2009 IP
  10. 007c

    007c Peon

    Messages:
    611
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Then use display:block or put spans in it and use display block on the span, either way, you'll need your fixed height n widths or floats heights n padding.
     
    007c, Jul 3, 2009 IP
  11. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Nice explanation!

    fade_to_black the example posted by Stomme works fine, whenever you hover anywhere over the DIV the link will get underlined.
     
    wd_2k6, Jul 3, 2009 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #12
    As already pointed out, invalid markup from an inline-level wrapping block-level. The solution is to use all inline-level elements and then style off them. You also seem to have more elements than you actually NEED for that layout.

    <a href="" class="post_bottom">
    	<span>text in here</span>
    </a>
    Code (markup):
    With the following CSS:

    .post_bottom {
    	display:block;
    	position:relative;
    	width:640px;
    	height:140px;
    	text-decoration:none;
    	background:url(bottom.jpg) 0 0 no-repeat;
    }
    
    .post_bottom span {
    	position:absolute;
    	left:0;
    	bottom:20px;
    	width:640px;
    	font-weight:bold;
    	text-align:center;
    	color:#D33C3D;
    }
    
    .post_bottom:active,
    .post_bottom:focus,
    .post_bottom:hover {
    	color:#D33C3C; /* slight color change on hover fixes IE bug */
    }
    
    .post_bottom:active span,
    .post_bottom:focus span,
    .post_bottom:hover span {
    	text-decoration:underline;
    }
    Code (markup):
    I think that's what you are trying to do...
     
    deathshadow, Jul 3, 2009 IP
  13. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #13
    Thanks for all the help guys. I appreciate it.
     
    fadetoblack22, Jul 3, 2009 IP