CSS基础(二)CSS常用文本属性

本文详细介绍了CSS中的核心属性,包括font-size、color、width、height、background-color、text-align和line-height的使用,以及如何通过代码实例展示这些属性在网页设计中的应用。
摘要由CSDN通过智能技术生成

1、font-size : 用来设置字体大小。

chrome浏览器中,能够显示的最小字体为12px。

2、color : 用来设置字体颜色。

用颜色对应英文单词设置:

color:red;

用颜色对应编码设置也行:

color:#ffffff;

3、width : 设置选择器选中元素的宽度。

width:100px;

4、height : 设置选择器选中元素的高度。

height:100px;

5、background-color : 用来设置背景色。

background-color:red;
background-color:#ffffff;

6、text-align : 设置文本水平居中。

text-align:center;

7、line-height :设置文本垂直居中。

line-height:100px;

8、示例代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS常用属性</title>
    <style>
        .test{
            /* chrome浏览器:font-size最小值是12px */
            font-size: 30px;
            /* 字体颜色 */
            color: white;
            /* 背景色 */
            background-color: black;
            /* 文本水平居中 */
            text-align: center;
            /* 文本行高(垂直居中) */
            line-height: 40px;
        }
        img{
            width: 300px;
        }
    </style>
</head>
<body>
    <h1 class="test">hello coder</h1>
    <img src="E:\mydesktop\tupian\coder.jpg" alt="">
</body>
</html>

浏览器打开:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今天自洽了吗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值