In the footer of my page http://www.imbued.co.uk/ I am getting errors on the W3C compliance test, understandably, as I've used the align attribute inline to vertically align the social media icons with its corresponding text. What is the correct CSS alternative to use? If I remove the align attribute the text and image aren't both in the centre and there is no centred float obviously.

有帮助吗?

解决方案

There's a few options. The best probably is to set the style on those elements to use margin: auto;

margin-left: 50%;
margin-right: 50%;
margin: auto;

In the case of one of your images, for example, it would look something like this:

<img style='margin-left: 50%; margin-right: 50%; margin: auto;' src=... />

Of course, you should just put the css in a class and set the class of anything you want centered to that class. The css class would look like:

.centered {
    margin-left: 50%;
    margin-right: 50%;
    margin: auto;
}

其他提示

align translates best to css text-align

so

<div align="left">text</div>

becomes

<div class="left">text</div>

and in css:

.left {
text-align:left;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top