首页 前端知识 CSS:HTML各种元素标签的属性

CSS:HTML各种元素标签的属性

2025-03-05 18:03:27 前端知识 前端哥 573 182 我要收藏

一.字体属性

css字体属性定义字体,颜色,大小,加粗,文字样式

1.color

规定文本的颜色

div{ color:red;}
div{ color:#ff0000;}
div{ color:rgb(255,0,0);}
div{ color:rgba(255,0,0,.5);}

2.font-size

设置文本的大小

能否管理文字的大小,在网页设计中非常重要的,但是,你不能通过调整字体大小段落看上去像标题,或者使标题看上去像段落。

h1{font-size:40px;}
h2{font-size:30px;}
p{font-size:14px;}

chrome浏览器接受最小字体是12px

3.font-weight

设置文本的粗细

描述
bold

定义粗体字符

bolder定义更粗的字符
lighter定义更细的字符
100-900400默认,700bold
h1{font-size:normal;}
div{font-size:bold;}
p{font-size:900;}

4.font-family

设置一个元素的字体

Ps:每个值要用逗号隔开,如果字体名称包含空格,必须加上引号

font-size:"microsoft YaHei","Simsun","SimHei";

二.背景属性

css背景属性主要有以下几个

属性描述
background-color设置背景颜色
background-image设置背景图片
background-position设置背景图片显示位置
background-repeat

设置背景图片如何填充

background-size设置背景图片大小属性

1.background-color

设置背景的颜色,div设置区块,style设置大小(不设置长宽默认为0,无法看见)

<head> 
<style>
        div{
            width:300px;
            height:500px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div></div>
</body>

2.background-image

设置背景图片

在style中添加设置属性background-image,并用url来标注路径,用(“”)包含

并且可以设置平铺方式,通过repeat

3.background-repeat

该属性设置如何平铺背景图像

说明
repeat默认值
repeat-x只向水平方向平铺
repeat-y只向垂直方向平铺
no-repeat不平铺

4.background-size属性

说明
length设置宽高,第一个宽第二个高,如果只设置一个,第二个值auto
percentage计算相对位置区域百分比,第一个宽度第二个高,如果只设置一个第二个auto
cover保持纵横比缩放完全覆盖背景区域大小
contain保持纵横比并将图像缩放成适合背景定位(自适应)

5.background-position

说明
left top左上角
left center左中
left center左下
right top右上角
right bottom右中
right bottom右下
center center中中
center center中中
center bottom中下

三.文本属性

1.text-align

指定元素文本的水平对齐方式

描述
left文本居左排列,默认值
right右边
center中间

h1 {text-align:center}
h2 {text-align:left}
h3 {text-align:right}

2.text-decoration

文本的修饰,下划线上划线删除线等

描述
underline定义下划线
overline定义上划线
line-through定义删除线

h1 {text-decoration:overline}
h2 {text-decoration:line-througe}
h3 {text-decoration:underline}

3.text-transform

属性控制文本的大小写

描述
captialize定义每个单词开头大写
uppercase定义全部大写
lowercase定义全部小写字母

h1 {text-transform:uppercase}
h2 {text-transform:capitialize}
p {text-transform:lowercase}

4.text-indent

规定首行文本的缩进

p{text-indent:50px;}

提示:负值是允许的,将第一行向左缩进,30px为俩个字的大小

四.表格属性

1.表格边框

指定css表格边框,使用border属性

table, td {
    border: 1px solid black;
}

如果要内部也有,那就加个td

2.折叠边框

border-collapse属性设置表格的边框是否被折叠成单一个边框或隔开

把外围的边框合成一个

table { border-collapse:collapse; }
table, td { border: 1px solid black}

solid实线

3.表格的宽度和高度

weight和height定义表格的宽度和高度

4.表格填充

表的内容中控制空格之间的边框,使用td和th填充属性(在文本的周围加入一些空白)

td { padding:15px;}

5.表格颜色

指定边框颜色和th元素的文本和背景颜色

table, td, th {border:1px solid green; }
td { background-color:green; color:white;}

转载请注明出处或者链接地址:https://www.qianduange.cn//article/22767.html
标签
评论
发布的文章

python连接neo4j的方式汇总

2025-03-05 18:03:12

五子棋对弈

2025-03-05 18:03:12

奖学金(acwing)c

2025-03-05 18:03:11

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!