【发布时间】:2016-12-02 17:19:54
【问题描述】:
我正在尝试使包含两个 div 的 div 居中 - 一个是段落,另一个是图像。我试图将自动 0 边距应用于容器 div,但它没有居中任何东西。有没有办法让所有内容都居中,同时保留我在较小 div 中所做的格式? 我的代码
.whole {
height: 800px;
max-width: 98%;
margin-left: 0 auto;
margin-right: 0 auto;
text-align: center;
}
.about-text {
width: 40%;
color: #66096c;
font-family: Lucida bright;
font-size: 20px;
height: 100%;
float: left;
padding: 1.8 em;
padding-right: 6em;
margin-left: 5%;
margin-right: auto;
}
.about_pic {
width: 40%;
height: 100%;
float: left;
margin-left: auto;
margin-right: auto;
}
<div class="whole">
<div class="about-text">
<p> <strong> Hi, I'm Kelsie. </strong>
<p>
<p>Hello there.
<br />My name is Kelsie, and I like to create things. So I decided to do it for a job. I am learning how to do this at Michigan State University, where I study professional writing. This program teaches web design, print design, editing, and writing.
I am also learning about how to make rhetorical decisions that will have a positive impact on an audience by studying visual design principles, website accessibility and usability laws, and persuasion techniques.</p>
<p>I live in East Lansing where I am a full-time student. So basically I study all the time. On the rare occasions that I do have some free time, I like to read, shop, and visit my <span> home</span> cats.</p>
<p>Want to create something together? Me too. Send me a message using the contact form, and let's get together.</p>
</div>
<div class="about_pic">
<img src="https://msu.edu/~donald88/kelsie.jpg" alt="kelsie by river" align="center" />
</div>
</div>
【问题讨论】:
-
margin-left: 0 auto; margin-right: 0 auto;- 这些属性中的每一个都不能获得 2 个值 -
您希望文字和图片并排还是在下方?
-
img元素没有align属性。你也有 unclosed<p>标签,而其他标签是关闭的。不要混合这两种使用类型。两者在 HTML 5 中都是有效的,但我建议始终关闭所有打开的元素,并且 b) 如果您不希望这样做,则不要混淆它。 -
我希望它们挨着
标签: html css containers center