I have a basic HTML file I made. I am trying to get the image to align to the center. I think I did it just as W3C says, but its not working. When I view the page, right align works, but middle and left both align to the left. I don’t understand why.
The problem is you are using “float: middle;”, there is no such float value as middle which is causing the issue. Using the align: center on the div will work how you want (if in doubt, try it out), but with the align in place in the div, you may as well remove the ones on it’s children (the aligns in the p and that float in the img).
Try the following instead. All the style have been taking out of the html and placed in the head of the document: (I’ve added comments to the styles so you can see what rules style which elements on the page).
Thanks. My instructor said we can use CSS instead in the top of the file or in another file, but we won’t learn that until chapter 3 so right now I was using the style tags.
In both the third and fourth edition(page 143) of her textbook, Wendy Willard suugests:
tell browser to display what would NORMALLY be an inline image as a block element. in CSS, block elements will automatically fill the entire available space. So if an image becomes a block element, its margins will grow until they reach the edges of the browser window
display: block
next…tell the browser to make BOTH the left and right margins the same… constructively, this centers the image
margin-left: auto
margin-right: auto
So…the CSS style code LOCATED within the <head></head> element and using “centered” as the CLASS would look like this—