初学HTML:采用CSS绘制一幅夏天的图

下面代码使用了HTML和CSS来绘制一幅炎炎夏日吃西瓜的画面。其中,使用了伪元素和阴影等技巧来实现部分效果。

html 复制代码
<!DOCTYPE html>
<html>
<head>
	<title>炎炎夏日吃西瓜</title>
	<style>
		body {
			background-color: #add8e6; /* 背景颜色 */
		}

		.sun {
			position: absolute;
			top: 50px;
			right: 50px;
			width: 100px;
			height: 100px;
			border-radius: 50%;
			background-color: #ffff00; /* 太阳颜色 */
			box-shadow: 0 0 50px #ffff00; /* 太阳光晕 */
		}

		.grass {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 100px;
			background-color: #90ee90; /* 草地颜色 */
		}

		.watermelon {
			position: absolute;
			top: 200px;
			left: 150px;
			width: 300px;
			height: 200px;
			background-color: #228b22; /* 西瓜皮颜色 */
			border-radius: 50%;
			overflow: hidden;
			box-shadow: 0 0 50px #228b22; /* 西瓜皮光晕 */
		}

		.watermelon:after {
			content: "";
			display: block;
			position: absolute;
			top: 20px;
			left: 20px;
			width: 260px;
			height: 160px;
			background-color: #ff4500; /* 西瓜肉颜色 */
			border-radius: 50%;
			box-shadow: 0 0 50px #ff4500; /* 西瓜肉光晕 */
		}

		.person {
			position: absolute;
			bottom: 100px;
			right: 200px;
			width: 100px;
			height: 150px;
			background-color: #ffdab9; /* 人的皮肤颜色 */
			border-radius: 50%;
			box-shadow: 0 0 50px #ffdab9; /* 人的皮肤光晕 */
		}

		.person:before {
			content: "";
			display: block;
			position: absolute;
			top: 30px;
			left: 20px;
			width: 60px;
			height: 60px;
			background-color: #ffffff; /* 眼睛颜色 */
			border-radius: 50%;
			box-shadow: 0 0 20px #ffffff; /* 眼睛光晕 */
		}

		.person:after {
			content: "";
			display: block;
			position: absolute;
			top: 80px;
			left: 20px;
			width: 60px;
			height: 60px;
			background-color: #ff69b4; /* 嘴巴颜色 */
			border-radius: 0 0 50% 50%;
			transform: rotate(-45deg);
		}
	</style>
</head>
<body>
	<div class="sun"></div>
	<div class="grass"></div>
	<div class="watermelon"></div>
	<div class="person"></div>
</body>
</html>

其中包括太阳、草地、西瓜和人的身体。

对于每个元素,都使用了CSS来设置其样式:

  • body 设置了背景颜色为浅蓝色。
  • .sun 设置了太阳的样式,包括位置、大小、颜色和光晕。
  • .grass 设置了草地的样式,包括位置、大小和颜色。
  • .watermelon 设置了西瓜皮的样式,包括位置、大小、颜色、圆角和光晕。同时设置了 overflow: hidden,超出边界部分会隐藏。
  • .watermelon:after 使用伪元素 :after 来实现西瓜肉的样式,包括位置、大小、颜色、圆角和光晕。
  • .person 设置了人的身体的样式,包括位置、大小、颜色、圆角和光晕。
  • .person:before 使用伪元素 :before 来实现人的眼睛的样式,包括位置、大小、颜色和光晕。
  • .person:after 使用伪元素 :after 来实现人的嘴巴的样式,包括位置、大小、颜色、形状和旋转。

在 HTML 中,使用 div 元素来创建这些元素,并分别指定其对应的 CSS 类名。最终通过 HTML 和 CSS 的组合来实现一幅炎炎夏日吃西瓜的画面。

相关推荐
ZC跨境爬虫9 小时前
跟着 MDN 学CSS day_16:(深入掌握背景与边框的艺术)
前端·css·ui·html·tensorflow
之歆1 天前
Day18_JavaScript高级核心:原型链、继承与事件循环机制深度解析(下)
前端·javascript·css
Daydream.V1 天前
深入理解 HTML 头部底层逻辑:DOCTYPE、Meta 标签如何左右浏览器解析与渲染
前端·javascript·html
边界条件╝1 天前
CSS3 高阶使用技巧实战
前端·css·css3
憧憬成为web高手1 天前
ACTF 12307复现
前端·bootstrap·html
㳺三才人子1 天前
初探 Flask
后端·python·flask·html
ZC跨境爬虫1 天前
模块化烹饪小程序开发日记 Day7:(菜谱详情接口开发与JSON数据读取全流程)
前端·javascript·css·ui·微信小程序·json
LaughingZhu1 天前
Product Hunt 每日热榜 | 2026-05-25
前端·人工智能·经验分享·chatgpt·html
wyc是xxs2 天前
浏览器解析HTML头部的底层逻辑
前端·html
来一碗刘肉面2 天前
使用Tailwind CSS 创建一个新项目
前端·css