我很难强制包含一组图像的 DIV,每个图像都包裹在一个 DIV 中,并在我的响应元素中居中。我试图为主 DIV 提供 100% 的宽度,并在图像 DIV 上混合使用透明和 float ,但我似乎根本无法让它们移动。我知道我很接近,但找不到我丢失的东西。这是我拥有的:
<footer>
<div id="Follow-Us"><p>Follow us on:</p></div>
<div id="social">
<!--<div id="left-social-spacer"></div>-->
<div id="FB">
<img src="Images/FB.jpg" />
</div>
<div id="Tweet" style="margin: 0 auto">
<img src="Images/Twitter.jpg" />
</div>
<div id="WP" style="margin: 0 auto">
<img src="Images/WordPress.jpg" />
</div>
</div><!-- end social -->
</footer>
<div id="safety"></div>
</article>
<hr />
<div id="Unsubscribe"><p>Not interested in email updates? <a href="mailtocontent" target="_blank">Unsubscribe here</a>. Click <a href="http://www.content.com/">here</a> to subscribe.
<br /><br />To ensure that subscription newsletters make it to your inbox, add <a href="mailtocontent"><!--info@content.com--></a> to your address book.</p>
</div>
这是正常和响应式设计在运行时的样子:
这是我的控制 CSS:
#FB
{
float: right;
/*position: relative;*/
margin: 0 auto;
background-color: blue;
}
#Tweet
{
float: left;
/*position: relative;*/
margin: 0 auto;
background-color: fuchsia;
}
#WP
{
float: left;
/*position: relative;*/
margin: 0 auto;
background-color: hotpink;
}
#social div
{
background-color: yellow;
height: 57px;
margin: 0 auto;
position: relative;
float: left;
}
#left-social-spacer
{
width:90%;
/*background-color: #ff0000;*/
height: 37px;
float: left;
margin-left: 59px;
}
footer
{
/*background-color: #003E79;*/
height: 37px;
display: block;
}
#Follow-Us p
{
clear: left;
float: left;
width: 100%;
text-align: center;
}
#LowNavBar p
{
clear: left;
float: left;
width: 100%;
text-align: center;
}
#Copyright p
{
clear: left;
float: left;
margin-top: -15px;
width: 100%;
text-align: center;
}
#safety
{
clear: both;
/*background-color: #ee7799;*/
width: 100%;
/*height: 50px;*/
}
.no_anchor_styles
{
text-decoration: none;
cursor: pointer;
}
#read-more
{
border-radius: 5px;
border: none;
background-color: red;
color: white;
}
我在这里遗漏了什么,或者我添加了什么不应该在这里阻止我控制 DIV 以将它们强制到中心?
最佳答案
text-align-center
父元素和 display:inline-block
社交图标。
例子:
.main {
text-align: center;
}
.in {
display: inline-block;
}
<div class="main">
<div class="in">
<img src="http://www.w3schools.com/tags/smiley.gif" alt="Smiley face" width="42" height="42">
</div>
<div class="in">
<img src="http://www.w3schools.com/tags/smiley.gif" alt="Smiley face" width="42" height="42">
</div>
</div>
关于html - 强制包含图像 DIV 的主 DIV float 中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38046801/