spires Posted April 22, 2010 Share Posted April 22, 2010 Hi I have an image, that is inside of an <a> tag, that is inside of a <div> // CSS #boxImgs a img { float: left; border:none; margin-right: 30px; } // Script <div id="boxImgs"> <a href="#"><img src="images/testimonials/play3.jpg" /></a> <a href="#"><img src="images/testimonials/play4.jpg" /></a> <a href="#"><img src="images/testimonials/houses.jpg" /></a> </div> I want all the images to have a right margin, except for the last image in the row. Can I do something like the following? // CSS #boxImgs a img { float: left; border:none; margin-right: 30px; } #boxImgs a img .noMargin { float: left; border:none; margin-right: 0px; } // Script <div id="boxImgs"> <a href="#"><img src="images/testimonials/play3.jpg" /></a> <a href="#"><img src="images/testimonials/play4.jpg" /></a> <a href="#" class="noMargin"><img src="images/testimonials/houses.jpg" /></a> </div> Thanks for your help Quote Link to comment Share on other sites More sharing options...
F1Fan Posted April 22, 2010 Share Posted April 22, 2010 Looks like that should work. Have you tested it? Quote Link to comment Share on other sites More sharing options...
spires Posted April 22, 2010 Author Share Posted April 22, 2010 Yes, I've tested it. But it does not work. I think the order might be incorrect: #boxImgs a img .noMargin { as the class is apart of the <a> tag, maybe something like: #boxImgs a .noMargin img { but that does not work either. Any ideas would be great Quote Link to comment Share on other sites More sharing options...
F1Fan Posted April 22, 2010 Share Posted April 22, 2010 What if you just did this: // CSS #boxImgs a img { float: left; border:none; margin-right: 30px; } .noMargin { float: left; border:none; margin-right: 0px; } // Script <div id="boxImgs"> <a href="#"><img src="images/testimonials/play3.jpg" /></a> <a href="#"><img src="images/testimonials/play4.jpg" /></a> <a href="#" class="noMargin"><img src="images/testimonials/houses.jpg" /></a> </div> Quote Link to comment Share on other sites More sharing options...
spires Posted April 22, 2010 Author Share Posted April 22, 2010 Thanks, but that didn't work either. I'm sure it must be possible. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted April 22, 2010 Share Posted April 22, 2010 Oh, I just realized something. You have the class tag on your <a>, not your image. Try one of these: // CSS #boxImgs a img { float: left; border:none; margin-right: 30px; } #boxImgs a .noMargin { float: left; border:none; margin-right: 0px; } // Script <div id="boxImgs"> <a href="#"><img src="images/testimonials/play3.jpg" /></a> <a href="#"><img src="images/testimonials/play4.jpg" /></a> <a href="#" class="noMargin"><img src="images/testimonials/houses.jpg" /></a> </div> Or: // CSS #boxImgs a img { float: left; border:none; margin-right: 30px; } #boxImgs a img .noMargin { float: left; border:none; margin-right: 0px; } // Script <div id="boxImgs"> <a href="#"><img src="images/testimonials/play3.jpg" /></a> <a href="#"><img src="images/testimonials/play4.jpg" /></a> <a href="#"><img class="noMargin" src="images/testimonials/houses.jpg" /></a> </div> Quote Link to comment Share on other sites More sharing options...
spires Posted April 22, 2010 Author Share Posted April 22, 2010 Thanks for sticking with this But neither of those worked. I can get around it by creating a separate DIV for the last image, but that just means more code, I like to try and keep my code as small as I can. Quote Link to comment Share on other sites More sharing options...
spires Posted April 22, 2010 Author Share Posted April 22, 2010 OK, I've got it. Not quite CSS, but it works. <a href="#"><img style="margin:0;" src="images/testimonials/houses.jpg" /></a> Set the margin in the actual <img> tag. Thanks for your help with this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.