(前端)html与css,css7、文本对齐、缩进、修饰

1、font-style:字体样式

设置字体倾斜样式或者正常样式。
取值:normal(正常)、italic(斜体)、oblique(斜体)
代码↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        p{
            font-size: 20px;
            line-height: 48px;
            color: red;
            font-family: "Consolas","Arial","微软雅黑";
        }
        .one{
            font-style: normal;
        }
        .tow{
            font-style: italic;
        }
        .three{
            font-style: oblique;
        }
    </style>
</head>
<body>
    <p class="one">这是一个段落this is a paragraph,normal</p>
    <p class="tow">这是一个段落this is a paragraph,italic</p>
    <p class="three">这是一个段落this is a paragraph,oblique</p>
</body>
</html>
View Code

效果图↓


italic属性值会找一个有斜体的字体进行替换。
oblique0正常的文字斜体
复合属性书写↓

/*复合属性书写*/
.one{
    font: italic bold 40px/200% "微软雅黑";
}

2、文本

text-align:对齐
对齐方式:水平左对齐,水平右对齐,水平居中。
对应的属性:left、right、center
与行数没关系,默认左对齐

修改成局中,直接写就可以。
代码↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        p{
            border: 1px solid red;
            height: 400px;
            width: 400px;
            font-size: 16px;
            line-height: 28px;
            font-family:"Arial","微软雅黑";
            text-align: center;
        }

    </style>
</head>
<body>
    <p>这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字</p>
</body>
</html>
View Code

效果图↓


因为前面文字把格都占满了所以只最后一行局中显示。

3、text-indent:文本缩进

设置的是文本的首行缩进。
单位:em,px,百分比

em:

代码↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 400px;
            height: 400px;
            border: 1px solid red
        }
        p{
            width: 300px;
            font-size: 16px;
            line-height: 28px;
            font-family:"Arial","微软雅黑";
            text-indent: 2em;
        }
    </style>
</head>
<body>
    <div class="box">
        <p>这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字</p>
    </div>
</body>
</html>
View Code

效果图↓


2em缩进2个字符

px:

代码↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 400px;
            height: 400px;
            border: 1px solid red
        }
        p{
            width: 300px;
            font-size: 16px;
            line-height: 28px;
            font-family:"Arial","微软雅黑";
            text-indent: 80px;
        }
    </style>
</head>
<body>
    <div class="box">
        <p>这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字</p>
    </div>
</body>
</html>
View Code

效果图↓

百分比:

代码↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 400px;
            height: 400px;
            border: 1px solid red
        }
        p{
            width: 300px;
            font-size: 16px;
            line-height: 28px;
            font-family:"Arial","微软雅黑";
            text-indent: 10%
        }
    </style>
</head>
<body>
    <div class="box">
        <p>这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字这有很多文字</p>
    </div>
</body>
</html>
View Code

效果图↓


10%:参考父级宽度的10 
图解↓

p的宽度300px,夫盒子400px,所以40是依据父盒子宽度的百分比。

猜你喜欢

转载自www.cnblogs.com/StevenSunYiwen/p/11042817.html
今日推荐