无法居中指定宽度的段落

时间:2018-06-12 13:59:05

标签: html css

我给了一个段宽度属性,因为我希望它折叠并且不会水平拉伸。在我这样做之后,我想将该文本与中心对齐,但是当我添加<div>时它所做的就是使段落的方向居中。

我需要将文本本身放在中心位置。我尝试将p添加到.content { margin: 3cm auto; text-align: center; } .content p { line-height: normal; font-size: 16px; } #text { width: 500px; }<div class="content"> <div id="text"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam rutrum ex quis hendrerit sagittis. Proin fringilla id sapien suscipit hendrerit. Integer sed diam nec turpis fringilla facilisis id non nulla.</p> </div> </div>。没有任何回报。

也许它不需要特定的宽度?需要帮助。

&#13;
&#13;
{{1}}
&#13;
{{1}}
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:1)

将左右边距更改为auto

&#13;
&#13;
.content {
  margin: 3cm auto 3cm;
  width: 300px;
  text-align: center;
}
&#13;
<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ornare odio arcu, id dictum turpis fermentum eu. Nunc congue dolor at est auctor, ut mollis tellus consectetur. Suspendisse ullamcorper, justo ac rutrum maximus, dui ipsum laoreet est,
    id malesuada purus dolor sed augue.</p>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我认为你说的是​​你想要整个段落的中心。尝试将边距设置为自动,如此。

&#13;
&#13;
.content {
  margin: 3cm auto;
  width: 300px;
}
&#13;
<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ornare odio arcu, id dictum turpis fermentum eu. Nunc congue dolor at est auctor, ut mollis tellus consectetur. Suspendisse ullamcorper, justo ac rutrum maximus, dui ipsum laoreet est,
    id malesuada purus dolor sed augue.</p>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

Loads API key from step 2 in memory Gets a list of files (chunks) For every file, calls speech to text API endpoint Adds results to a list Combines all results and adds a timestamp (every 30 seconds) Saves results to transcript.txt 更改为margin: 3cm 1cm 3cm 1cm;。这将允许margin: 3cm auto;自动调整并占用margin居中所需的空间。

&#13;
&#13;
div
&#13;
.content {
  margin: 3cm auto;
  width: 300px;
  text-align: center;
}
&#13;
&#13;
&#13;

同样的原则适用于您的第二个示例,但您需要将<div class="content"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ornare odio arcu, id dictum turpis fermentum eu. Nunc congue dolor at est auctor, ut mollis tellus consectetur. Suspendisse ullamcorper, justo ac rutrum maximus, dui ipsum laoreet est, id malesuada purus dolor sed augue.</p> </div> auto添加到margins

&#13;
&#13;
#text
&#13;
.content {
  margin: 3cm auto;
  text-align: center;
}

.content p {
  line-height: normal;
  font-size: 16px;
}

#text {
  margin: auto;
  width: 500px;
}
&#13;
&#13;
&#13;

答案 3 :(得分:0)

您可以添加到您的样式

#text {
  margin: 0 auto;
}