在CSS中,body
元素用于表示HTML文檔的主體部分,你可以通過CSS來定義body
元素的樣式,比如顏色、字體、背景等,下面是一些關(guān)于如何在CSS中寫body
的示例:
1、設(shè)置背景顏色:
```css
body {
background-color: #f0f0f0;
}
```
2、設(shè)置字體和顏色:
```css
body {
font-family: Arial, sans-serif;
color: #333;
}
```
3、設(shè)置背景圖片:
```css
body {
background-image: url('path/to/image.jpg');
background-repeat: no-repeat;
background-size: cover;
}
```
4、設(shè)置文本對齊方式:
```css
body {
text-align: justify;
}
```
5、設(shè)置鏈接顏色:
```css
body {
a {
color: #007bff;
}
}
```
6、設(shè)置段落樣式:
```css
body {
p {
line-height: 1.6;
color: #666;
}
}
```
7、設(shè)置列表樣式:
```css
body {
ul {
list-style-type: disc;
color: #333;
}
}
```
8、設(shè)置表格樣式:
```css
body {
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
}
```
9、設(shè)置表單樣式:
```css
body {
form {
display: flex;
flex-direction: column;
}
label, input, button {
margin: 5px 0;
}
}
```
10、設(shè)置響應(yīng)式布局:
```css
body {
@media (max-width: 600px) {
font-size: 18px;
}
@media (min-width: 601px) {
font-size: 22px;
}
}
```
在這個示例中,我們使用了媒體查詢來根據(jù)屏幕寬度調(diào)整字體大小,當(dāng)屏幕寬度小于或等于600px時,字體大小為18px;當(dāng)屏幕寬度大于600px時,字體大小為22px。