Html 在html中设置段落的左边距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4507030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:48:46  来源:igfitidea点击:

Set left margin for a paragraph in html

htmlparagraphs

提问by Ishan

i want to start a paragraph after putting 5 spaces and all the lines beneath the first line should come in a straight line, imean all the lines in the paragraph should have 5 spaces before it starts.

我想在放置 5 个空格后开始一个段落,并且第一行下方的所有行都应该在一条直线上,即段落中的所有行在开始之前都应该有 5 个空格。

I am getting this paragraph from databse.

我从数据库中得到这一段。

I want a Html tag that will define left margin for a complete paragraph.

我想要一个 Html 标签来定义一个完整段落的左边距。

回答by danjah

<p style="margin-left:5em;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut lacinia vestibulum quam sit amet aliquet. Phasellus tempor nisi eget tellus venenatis tempus. Aliquam dapibus porttitor convallis. Praesent pretium luctus orci, quis ullamcorper lacus lacinia a. Integer eget molestie purus. Vestibulum porta mollis tempus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>

That'll do it, there's a few improvements obviously, but that's the basics. And I use 'em'as the measurement, you may want to use other units, like 'px'.

这样就可以了,显然​​有一些改进,但这是基础知识。我使用'em'作为度量单位,您可能想使用其他单位,例如'px'.

EDIT: What they're describing above is a way of associating groups of styles, or classes, with elements on a web page. You can implement that in a few ways, here's one which may suit you:

编辑:他们在上面描述的是一种将样式组或类与网页上的元素相关联的方法。您可以通过多种方式实现它,这里有一种可能适合您:

In your HTML page, containing the <p>tagged content from your DB add in a new 'style' node and wrap the styles you want to declare in a class like so:

在您的 HTML 页面中,包含<p>来自您的数据库的标记内容添加一个新的“样式”节点并将您想要声明的样式包装在一个类中,如下所示:

<head>
  <style type="text/css">
    p { margin-left:5em; /* Or another measurement unit, like px */ }
  </style>
</head>
<body>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut lacinia vestibulum quam sit amet aliquet.</p>
</body>

So above, all <p>elements in your document will have that style rule applied. Perhaps you are pumping your paragraph content into a container of some sort? Try this:

因此,<p>您的文档中的所有元素都将应用该样式规则。也许您正在将段落内容注入某种容器中?尝试这个:

<head>
  <style type="text/css">
    .container p { margin-left:5em; /* Or another measurement unit, like px */ }
  </style>
</head>
<body>
  <div class="container">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut lacinia vestibulum quam sit amet aliquet.</p>
  </div>
  <p>Vestibulum porta mollis tempus. Class aptent taciti sociosqu ad litora torquent per conubia nostra.</p>
</body>

In the example above, only the <p>element inside the div, whose class name is 'container', will have the styles applied - and not the <p>element outside the container.

在上面的示例中,只有<p>div 内的元素,其类名为“容器”,才会应用样式 - 而不是<p>容器外的元素。

In addition to the above, you can collect your styles together and remove the style element from the <head>tag, replacing it with a <link>tag, which points to an external CSS file. This external file is where you'd now put your <p>tag styles. This concept is known as 'seperating content from style' and is considered good practice, and is also an extendible way to create styles, and can help with low maintenance.

除了上述之外,您还可以将样式收集在一起并从<head>标签中删除样式元素,将其替换为<link>指向外部 CSS 文件的标签。这个外部文件是您现在放置<p>标签样式的地方。这个概念被称为“从样式中分离内容”,被认为是一种很好的做法,也是一种创建样式的可扩展方式,有助于降低维护成本。