html用css画米奇
时间: 2023-09-19 09:08:08 浏览: 61
好的,让我来给您讲解如何用 HTML 和 CSS 来绘制米奇的图案。
首先,我们需要先在 HTML 中创建一个 div 容器,然后在 CSS 中设置该 div 的宽度和高度,并设置背景色为黑色,代码如下:
HTML 代码:
```html
<div class="mickey"></div>
```
CSS 代码:
```css
.mickey {
width: 200px;
height: 200px;
background-color: black;
}
```
接下来,我们需要在该 div 容器中绘制米奇的头部和耳朵。米奇的头部是一个圆形,可以使用 CSS 中的 border-radius 属性来实现。耳朵是两个圆形,可以使用伪元素 ::before 和 ::after 来实现。
HTML 代码:
```html
<div class="mickey">
<div class="head"></div>
<div class="left-ear"></div>
<div class="right-ear"></div>
</div>
```
CSS 代码:
```css
.mickey {
width: 200px;
height: 200px;
background-color: black;
position: relative;
}
.head {
width: 140px;
height: 140px;
border-radius: 70px;
background-color: white;
position: absolute;
top: 30px;
left: 30px;
}
.left-ear,
.right-ear {
width: 60px;
height: 60px;
border-radius: 30px;
background-color: white;
position: absolute;
top: 20px;
}
.left-ear {
left: -20px;
}
.right-ear {
right: -20px;
}
.left-ear::before,
.left-ear::after,
.right-ear::before,
.right-ear::after {
content: "";
width: 30px;
height: 30px;
border-radius: 15px;
background-color: black;
position: absolute;
top: 15px;
}
.left-ear::before,
.right-ear::before {
left: 15px;
}
.left-ear::after,
.right-ear::after {
right: 15px;
}
```
最后,我们还需要在头部中绘制米奇的眼睛和嘴巴。眼睛可以使用圆形和伪元素 ::before 和 ::after 来实现,嘴巴可以使用弧形和伪元素 ::before 和 ::after 来实现。
HTML 代码:
```html
<div class="mickey">
<div class="head">
<div class="left-eye"></div>
<div class="right-eye"></div>
<div class="mouth"></div>
</div>
<div class="left-ear"></div>
<div class="right-ear"></div>
</div>
```
CSS 代码:
```css
.mickey {
width: 200px;
height: 200px;
background-color: black;
position: relative;
}
.head {
width: 140px;
height: 140px;
border-radius: 70px;
background-color: white;
position: absolute;
top: 30px;
left: 30px;
}
.left-eye,
.right-eye {
width: 30px;
height: 30px;
border-radius: 15px;
background-color: black;
position: absolute;
top: 40px;
}
.left-eye {
left: 40px;
}
.right-eye {
right: 40px;
}
.left-eye::before,
.right-eye::before {
content: "";
width: 15px;
height: 15px;
border-radius: 7.5px;
background-color: white;
position: absolute;
top: 5px;
left: 5px;
}
.left-eye::after,
.right-eye::after {
content: "";
width: 10px;
height: 10px;
border-radius: 5px;
background-color: black;
position: absolute;
top: 10px;
left: 10px;
}
.mouth {
width: 50px;
height: 30px;
border-radius: 0 0 25px 25px;
border: 3px solid black;
position: absolute;
top: 70px;
left: 45px;
}
.mouth::before,
.mouth::after {
content: "";
width: 10px;
height: 10px;
border-radius: 5px;
background-color: black;
position: absolute;
}
.mouth::before {
top: 10px;
left: 10px;
}
.mouth::after {
top: 10px;
right: 10px;
}
.left-ear,
.right-ear {
width: 60px;
height: 60px;
border-radius: 30px;
background-color: white;
position: absolute;
top: 20px;
}
.left-ear {
left: -20px;
}
.right-ear {
right: -20px;
}
.left-ear::before,
.left-ear::after,
.right-ear::before,
.right-ear::after {
content: "";
width: 30px;
height: 30px;
border-radius: 15px;
background-color: black;
position: absolute;
top: 15px;
}
.left-ear::before,
.right-ear::before {
left: 15px;
}
.left-ear::after,
.right-ear::after {
right: 15px;
}
```
这样,我们就成功地用 HTML 和 CSS 绘制了一个简单的米奇图案。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)