blog/docs/code/html/css-attribute-primary.md

58 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: CSS属性入门
date: 2022-01-08 15:25:42
tags: [CSS]
categories: [CSS]
author: Anges黎梦
---
## 布局常用样式属性:
- width 设置元素(标签)的宽度width:100px;
- height 设置元素(标签)的高度height:200px;
- background 设置元素背景色或者背景图片background:gold; 设置元素背景色为金色
- border 设置元素四周的边框border:1px solid black; 设置元素四周边框是1像素宽的黑色实线
- 以上也可以拆分成四个边的写法,分别设置四个边的:
- border-top 设置顶边边框border-top:10px solid red;
- border-left 设置左边边框border-left:10px solid blue;
- border-right 设置右边边框border-right:10px solid green;
- border-bottom 设置底边边框border-bottom:10px solid pink;
- padding 设置元素包含的内容和元素边框的距离也叫内边距如padding:20px;padding是同时设置4个边 的也可以像border一样拆分成分别设置四个边:padding-top、padding-left、padding-right、padding- bottom。
- margin 设置元素和外界的距离也叫外边距如margin:20px;margin是同时设置4个边的也可以像border一 样拆分成分别设置四个边:margin-top、margin-left、margin-right、margin-bottom。
- float 设置元素浮动浮动可以让块元素排列在一行浮动分为左浮动float:left; 右浮动float:right;
## 文本常用样式属性一:
- color 设置文字的颜色,如: color:red;
- font-size 设置文字的大小font-size:12px;
- font-family 设置文字的字体font-family:'微软雅黑';为了避免中文字不兼容一般写成font-family:'Microsoft Yahei';
- font-weight 设置文字是否加粗font-weight:bold; 设置加粗 font-weight:normal 设置不加粗
- line-height 设置文字的行高line-height:24px; 表示文字高度加上文字上下的间距是24px也就是每一行 占有的高度是24px
- text-decoration 设置文字的下划线text-decoration:none; 将文字下划线去掉
## 样式中的注释
```css
/* 设置头部的样式 */
.header{
width:960px;
height:80px;
background:gold;
}
```