CSS里可以设置段落的距离吗?

html-css014

CSS里可以设置段落的距离吗?,第1张

1.1、line-height为20px案例,DIV+CSS代码:

2.行高line-height实现段落间距

分别设置20px和50px行高样式案例,对比发现不同行高值,段落上下间距也产生不同距离,所以使用line-height可以设置段落间距距离,但这里不推荐使用line-height设置段落之间间距。

二、css padding内补白(内边距)

可以推荐使用padding设置段落上下间距。通过设置上下内补白,内距离即可实现p段落上下间距设置。

关键字:p{padding:10px 0}

接下来DIVCSS5以案例演示CSS段落上下距离设置。

1、设置上下内补白为10px(padding:10px 0)完整css+div代码:

2.添加如下属性到关联的css文件里:

p{

padding: 0

margin: 0

}

然后在指向段落的样式属性里添加以下css代码:

margin-bottom: 20px

数值可自由设定。

3.设定文字内容

标签的margin-top和margin-bottom值,前提是你的段落是用<P>标签进行分段的,而不是单纯的<br />。

text-align: 段落水平对齐设置值:center、right、left、justify(继承)

vertical-algin: 段落垂直对齐设置值:sub(垂直对齐文本的下标。) super(垂直对齐文本的上标) top(上) middle(中) bottom(下) 10px -10px 相对于元素行高属性的百分比

letter-spacing: 字母的间距

word_spacing: 单词的间距

line-height: 文本行高

text-indent: 缩进方式

white-space: 排版方式设置值:normal (默认,空白会被忽略) pre(原样显示) nowrap(文本不会换行)

html:

<!DOCTYPE html>

<html>

<head>

<title>My webpage</title>

</head>

<body>

<div>

<h1>My first div</h1>

<p>This div uses inline CSS to style its content.</p>

<style>

h1 {

color: red

}

p {

font-size: 16px

text-align: center

}

</style>

</div>

<div>

<h1>My second div</h1>

<p>This div uses an external CSS file to style its content.</p>

<link rel="stylesheet" type="text/css" href="styles.css">

</div>

<div>

<h1>My third div</h1>

<p>This div uses an embedded style sheet to style its content.</p>

<style>

/* This is an embedded style sheet */

h1 {

color: blue

}

p {

font-size: 14px

text-align: left

}

</style>

</div>

</body>

</html>

style.css:

/* This is an external style sheet */

h1 {

color: green

}

p {

font-size: 18px

text-align: right

}

这段代码中,第一个div使用内联CSS来样式其内容,第二个div使用外部CSS文件来样式其内容,第三个div使用嵌入式样式表来样式其内容。