December 11, 201015 yr Hello Everyone. I have a #main div and inside that I have a couple of paragraphs and two images. One of the images is floated to the left (which is what I want) but I want the other (further down the page to be centred). I have written the following code: #main { position: relative; padding: 0 15px 0 15px; width: 800px; } #main img { float: left; margin: 0 25px 5px 0; } #main img.webtechnos { float: none !important; margin: 0 auto !important; padding: 30px 0 30px 0; } But the image still shows on the left and not centred. I would greatly appreciate any help. Thank You.
December 11, 201015 yr <img> is an inline element so normally they don't pay attention to things like margin: 0 auto. What might help is in #main img.webtechnos adding display:block;, but it depends how the layout around this image is. Try it and if it doesn't work would you be able to post a link to the page or the css and html code so it can be looked at in context to the rest of the layout
December 11, 201015 yr Author @Dizi: I tried the display: block .. it didn't work. @mteam: If you meant width for the image, I gave the image a width and still it doesn't work. If you mean the container of the image (in this case #main) that too has a width (see code above) I don't have a web host to put the code in right now.
December 11, 201015 yr #main img.webtechnos { float: none !important; margin: 0 auto !important; padding: 30px 0 30px 0; width:500px;/*width added in css*/ }
December 11, 201015 yr Yes sorry just tried it lol this will work i've just use the class .webtechnos { float: none !important; margin: 0 auto !important; padding: 30px 0 30px 0; display:block;/*added display block*/ width:500px;/*width added in css*/ }
December 11, 201015 yr Dizi said add display: block and mteam said add a width, did you try both? #main img.webtechnos { float: none !important; margin: 0 auto !important; padding: 30px 0 30px 0; width:500px;/*width added in css*/ display: block; } That might work to place the image in the center of the parent (but not central between the side of the floated div and the right side). [Looks like mteam beat me this time.] Edited December 11, 201015 yr by Wickham
December 11, 201015 yr Author I had tried that as well before and it didn't work. But then accidentally my cursor went over my sidebar on the right (while in firebug) and I saw the problem ! lol I had given the sidebar (on the right) such a long bottom padding that it was stopping the image from centring. Thank You the problem is solved
Create an account or sign in to comment