我一直在尝试让它发挥作用。但无论我尝试什么,我都无法让它出现在中心。
我搜索了stackoverflow。我试过保证金:0自动;并尝试删除浮动元素。但似乎没有任何效果。
我一定很遗憾。我对CSS不是很了解。你能指出来吗?
body {
align-content: center;
text-align: center;
background-image: url(images/marble.gif);
margin: 0 auto;
}
#about {
align-content: center;
text-align: center;
width: 700px;
}
#about img {
align-content: center;
text-align: center;
border-right: black thick solid;
border-top: black thick solid;
border-left: black thick solid;
border-bottom: black thick solid;
padding-right: 0px;
padding-left: 0px;
padding-bottom: 0px;
margin: 3px;
padding-top: 0px;
}
#myPicture p {
align-content: center;
text-align: center;
font-weight: bold;
font-size: 11pt;
}
#myName p {
align-content: center;
text-align: center;
font-weight: bold;
font-size: 24pt;
clear: both;
margin-top: 15px;
}
<div id="about">
<div id="myPicture">
<p> </p>
<p>
<img src="images/profile2.jpg" />
</p>
</div>
<div id="myName">
<p>Dude</p>
</div>
<div id="myTitles">
<div class="myTitleClass">
<p>...
</div>
</div>
答案 0 :(得分:0)
ADd margin-left:auto和margin-right:auto to about about section
这是fiddle
body {
width: 100%;
text-align: center;
background-image: url(images/marble.gif);
margin: 0 auto;
}
#about {
margin-left: auto;
margin-right: auto;
text-align: center;
width: 700px;
}
#about img {
text-align: center;
border-right: black thick solid;
border-top: black thick solid;
border-left: black thick solid;
border-bottom: black thick solid;
padding-right: 0px;
padding-left: 0px;
padding-bottom: 0px;
margin: 3px;
padding-top: 0px;
}
#myPicture p {
text-align: center;
font-weight: bold;
font-size: 11pt;
}
#myName p {
text-align: center;
font-weight: bold;
font-size: 24pt;
clear: both;
margin-top: 15px;
}
<body>
<div id="about">
<div id="myPicture">
<p> </p>
<p>
<img src="images/profile2.jpg" />
</p>
</div>
<div id="myName">
<p>Dude</p>
</div>
<div id="myTitles">
<div class="myTitleClass">
<p>...
</div>
</div>
</body>
答案 1 :(得分:0)
您已将图像和文本置于height: 650
内,宽度为700像素,但div#about
本身并未居中。我在div中添加了div#about
,因此您可以看到此处发生了什么:
您所要做的就是将background-color: orange;
添加到margin: 0 auto;
,然后您就可以了:
它现在集中。你可以摆脱橙色背景。 我也缩短了你的CSS,请查看:
div#about
&#13;
body {
margin: 0;
}
#about {
width: 700px;
background-color: orange;
margin: 0 auto;
}
#about img {
border: black thick solid;
padding: 0;
margin: 3px;
}
#myPicture p {
text-align: center;
}
#myName p {
text-align: center;
font-weight: bold;
font-size: 24pt;
margin-top: 15px;
}
&#13;