首页 > 解决方案 > 如何使用 CSS 设置常规(未标记)HTML 文本的样式?

问题描述

所以我刚开始学习 HTML 和 CSS,就像 2 天前一样,我遇到了一个问题。我正在为自己创建一个备忘单,无论我做什么,所有的 CSS 文本缩进都只适用于我的 h2 标签。

<section>
    <!-- Bold, Italics, Underline -->
    <h2>Bold, Italics, and Underline</h2>
    <strong>&ltstrong&gt;</strong> The strong tag is used to <strong>bolden</strong> text.
    <br>
    <strong>&lt;em&gt;</strong> The em tag is used to <em>italicise</em> text.
    <br>
    <strong>&lt;u&gt;</strong> The u tag is used to <u>underline</u> text.
  </section>

这就是我编写代码的方式,我根据相关标签对行进行分段,并将它们全部放在带有容器类的 div 中。在我的 CSS 样式表中,我玩弄了一下text-indent,发现无论我把它放在哪里,它都只适用于我的 h2 标签。

我已经尝试将该命令嵌套在不同的 CSS 类中,删除我的所有部分并将我的文本保留在 div 中,等等,但没有任何效果。由于填充,我不想为每一行文本使用段落标签,这就是我使用常规文本的原因。

标签: htmlcss

解决方案


正如w3schools所说text-indent

定义和使用

text-indent 属性指定文本块中第一行的缩进。

至于什么算作文本块,你可以在这里找到。

或者,您可以使用 CSSmargin-left样式移动该部分。

例子:

<section style="margin-left: 12px;">
  <strong>This is Indented with margin</strong>
  <br>
  Lorem consectetur mollit proident ad quis commodo pariatur ullamco mollit eiusmod cupidatat amet fugiat.
</section>

<br>
<br>
<br>

<section>
  <strong>This is unindented</strong>
  <br>
  Lorem consectetur mollit proident ad quis commodo pariatur ullamco mollit eiusmod cupidatat amet fugiat.
</section>


推荐阅读