Html 我需要图像水平对齐,并在页面上居中
我不知道如何在不使用表格的情况下将图像水平对齐并使其在页面上居中。我用divs试过了,但没能把它放在页面中央。我也希望它们反应灵敏,所以它们总是在缩小时保持在中间。 这是我在JSFIDLE中得到的: CSSHtml 我需要图像水平对齐,并在页面上居中,html,css,Html,Css,我不知道如何在不使用表格的情况下将图像水平对齐并使其在页面上居中。我用divs试过了,但没能把它放在页面中央。我也希望它们反应灵敏,所以它们总是在缩小时保持在中间。 这是我在JSFIDLE中得到的: CSS /*Black and White --------------------------------------------------*/ .bw { -webkit-transition: all .5s ease; -moz-transition: all .5s ease;
/*Black and White
--------------------------------------------------*/
.bw {
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
}
.bw:hover {
-webkit-filter: grayscale(100%);
}
*/container
-----------------------------------------*/
.footersocial {
width:100%;
float:center;
}
HTML
<div id="footersocial"><div class="bw pic"><a href="https://www.facebook.com/PeopleAndPlatforms" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_facebook_hover.png" alt="facebook"></a></div>
<div class="bw pic"><a href="http://twitter.com/peoplenplatform" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_twitter_hover.png" alt="Twitter"></a></div>
<div class="bw pic"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_pinterest_hover.png" alt="pinterest"></div>
<div class="bw pic"><a href="http://www.linkedin.com/company/people-&-platforms" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_linkedin_hover.png" alt="linkedin"></a></div>
<div class="bw pic"><a href="https://plus.google.com/u/1/112443165541377795854" target="_blank"><img style="float: left; margin: 2px;" src="http://test.peopleandplatforms.com/wp-content/uploads/2014/11/Footer_gplus_hover.png" alt="googleplus"></a></div>
</div>
这里有一个使用表的解决方案: HTML: 下面是另一个使用
文本对齐:居中的解决方案:
CSS:
在这里,我做了一个更改和添加一些CSS的示例:
大多数情况下,我使用边距:0 auto将.footersocial
对齐到中心代码>,但为此您需要固定宽度。现在,要使其具有响应性,请使用@media screen
并在更改屏幕宽度后更改.footer
宽度。一旦图像变小,图像也会变小,因为它们的宽度以%为单位
例如:
@media screen and (max-width: 720px) {
.footersocial {
width: 100px;
}
}
媒体查询W3S文档:
#footersocial {
display: table;
margin: 0 auto;
}
#footersocial > a {
display: inline-block;
position: relative;
width: 34px;
height: 33px;
}
#footersocial > a > img {
height: 100%;
}
#footersocial > a:before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
border-radius: 4px;
background-color: rgba(0, 0, 0, 0.2);
opacity: 0;
transition: opacity 0.5s linear;
}
#footersocial > a:hover:before {
opacity: 1;
}
#footersocial {
text-align: center;
}
/* The rest is the same as in the first solution */
@media screen and (max-width: 720px) {
.footersocial {
width: 100px;
}
}