<img> tag within <a>: css behaviour and background

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    #1

    <img> tag within <a>: css behaviour and background

    Hello,
    I'm trying to put these images in line without any spaces surround. I wrote this piece of code and I'd like to understand why that code has that behaviour. Why the the <img> is not within the <a> element??
    Any good links to this point will be very appreciated. Thanks.


    Code:
    #followus {
    	clear: left;	
    	float: right;
    	width: 300px;
    	background: pink;
    	padding: 10px; margin:10px;
    	border: Dashed 2px; 	
    }
    #followus img {	
    	border: Solid 2px; 	
    	padding: 5px;
    	margin: 10px;
    }
    
    
    #followus img:hover {
    	border: Solid 2px yellow; 
    }
    
    #followus a {
            /* display:inline */
    	width: 70px;	
    	border: Solid 2px yellow; 				
    }
    #followus a:hover {		
    		background: black;		
    }
    Code:
    <div id="followus">
     <a....> <img ..... /> </a>
     <a....> <img ..... /> </a>
    </div>
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    Anchor tag is inline element. Width or height don't work on inline elements. Try setting:

    Code:
    #followus a {
    .
    .
    .
    display: block;
    float: left;
    }
    However I would probably remove all styling on anchor tag and just play with padding on images.

    Comment

    Working...