CSS练习题

CSS练习题

1、margin——控制网页元素的位置,页面效果如下:
在这里插入图片描述
代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>控制网页元素的位置</title>
<link href="style/2-7.css" rel="stylesheet" type="text/css">

</head>

<body>
<div id="box">
  <div id="pic"><img  class="pic1" src="images/2702.jpg" alt="" /></div>
</div>
</body>
</html>

@charset "utf-8";
/* CSS Document */
*{
	margin:0px;
	padding:0px;
}
body{
	background-color:#917e67;
}
#box{
	width:820px;
	height:687px;
	background-image:url(../images/2701.jpg);
	background-repeat:no-repeat;
	background-position: left 20px;
	margin:0px auto;
	padding-top: 20px;
}
.box{
		background-image: url(images/2701.jpg)
	}
	.pic1{
		
margin:180px 80px 30px 80px;
	}

2、border——为网页元素添加边框,页面效果如下:
在这里插入图片描述
代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>为网页元素添加边框</title>
<link href="style/2-8.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="box">
  <div id="logo"><img src="images/2803.png" width="269" height="37" alt="" /></div>
  <div id="main">
  	<img class="pic1" src="images/2804.jpg" alt="" width="210" height="190" />
  	<img class="pic2" src="images/2805.jpg" alt="" width="210" height="190" />
  	<img class="pic3"  src="images/2806.jpg" alt="" width="210" height="190" />
  	<img class="pic4"  src="images/2807.jpg" alt="" width="210" height="190" />
  	<img class="pic1"  src="images/2808.jpg" alt="" width="210" height="190" />
  	<img class="pic2"  src="images/2809.jpg" alt="" width="210" height="190" />
  	<img class="pic3"  src="images/2810.jpg" alt="" width="210" height="190" />
  	<img class="pic4"  src="images/2811.jpg" alt="" width="210" height="190" />
  </div>
</div>
<p>&nbsp;</p>
</body>
</html>

@charset "utf-8";
/* CSS Document */
* {
	margin: 0px;
	padding: 0px;
}
body {
	font-family: 微软雅黑;
	font-size: 14px;
	color: #FFF;
	line-height: 30px;
	background-image: url(../images/21001.jpg);
	background-repeat: no-repeat;
	background-position: center -100px;
}
#box {
	width: 575px;
	height: 359px;
	margin: 90px auto 0px auto;
	background-image: url(../images/21002.png);
	background-repeat: no-repeat;
	padding: 28px 92px 128px 92px;
}

#pic01 {
	position:relative;
	top:-235px;
	left:250px;
}

3、padding——控制Div中内容的位置,页面效果如下:
在这里插入图片描述
代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>控制Div中内容的位置</title>
<link href="style/2-9.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="box">
	<img src="images/2902.png" alt="" />
</div>
</body>
</html>
@charset "utf-8";
/* CSS Document */
*{
	margin:0px;
	padding:0px;
}
body{
	background-image:url(../images/2901.gif);
	background-repeat:repeat-x;
}
#box{
	width: 917px;
	height: 552px;
	margin: 0px auto;
}
#box {
	padding-top: 60px;
}

4、相对定位、绝对定位、浮动定位、页面效果如下:
在这里插入图片描述

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>设置网页元素叠加显示</title>
<link href="style/2-10.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="box"><img src="images/21003.jpg" width="575" height="359"  alt=""/>
  <div id="pic01">
  	<img src="images/21004.png" alt="" />
  </div>
</div>
</body>
</html>

@charset "utf-8";
/* CSS Document */
* {
	margin: 0px;
	padding: 0px;
}
body {
	font-family: 微软雅黑;
	font-size: 14px;
	color: #FFF;
	line-height: 30px;
	background-image: url(../images/21001.jpg);
	background-repeat: no-repeat;
	background-position: center -100px;
}
#box {
	width: 575px;
	height: 359px;
	margin: 90px auto 0px auto;
	background-image: url(../images/21002.png);
	background-repeat: no-repeat;
	padding: 28px 92px 128px 92px;
}

#pic01 {
	position:relative;
	top:-235px;
	left:265px;
}

在这里插入图片描述

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>设置网页元素固定在右侧显示</title>
<link href="style/2-11.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="box">我们的作品<br>
  <img src="images/21102.png" width="600" height="400"  alt=""/>
</div>

<div id="pic">
	<img src="images/21103.png" alt="" />
</div>
</body>
</html>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>设置网页元素固定在右侧显示</title>
<link href="style/2-11.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="box">我们的作品<br>
  <img src="images/21102.png" width="600" height="400"  alt=""/>
</div>

<div id="pic">
	<img src="images/21103.png" alt="" />
</div>
</body>
</html>

在这里插入图片描述

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>制作作品列表</title>
<link href="style/2-13.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="box">
  <div id="menu"><img src="images/21303.png" width="124" height="50" alt="" /><img src="images/21304.png" width="124" height="50" alt="" /><img src="images/21305.png" width="124" height="50" alt="" /><img src="images/21306.png" width="124" height="50" alt="" /><img src="images/21307.png" width="124" height="50" alt="" /></div>
  <div id="bottom">
    <div id="pic"><img src="images/21309.jpg" width="180" height="96" alt="" /></div>
    <div id="pic01"><img src="images/21310.jpg" width="180" height="96" alt="" /></div>
    <div id="pic02"><img src="images/21311.jpg" width="180" height="96" alt="" /></div>
    <div id="pic"><img src="images/21312.jpg" width="180" height="96" alt="" /></div>
    <div id="pic01"><img src="images/21313.jpg" width="180" height="96" alt="" /></div>
    <div id="pic02"><img src="images/21314.jpg" width="180" height="96" alt="" /></div>
  </div>
</div>
</body>
</html>

@charset "utf-8";
/* CSS Document */
*{
	margin:0px;
	padding:0px;
}
body{
	background-color:#dde1e4;
	background-image:url(../images/21301.jpg);
	background-repeat:no-repeat;
	background-position:center top;
}
#box{
	width:1100px;
	height:auto;
	overflow:hidden;
	margin:0px auto;
}
#menu{
	width:100%;
	height:270px;
	background-image:url(../images/21302.png);
	background-repeat:no-repeat;
	background-position:30px 30px;
	text-align:right;
}
#bottom{
	width:616px;
	height:340px;
	background-image:url(../images/21308.jpg);
	background-repeat:no-repeat;
	padding:10px;
	margin-left:20px;
	margin-bottom:20px;
}
#pic{
	width: 180px;
	height: 96px;
	margin: 4px;
	background-color: #CCC;
	padding: 8px;
	float:left;
}
#pic01{
	width: 180px;
	height: 96px;
	margin: 4px;
	background-color: #CCC;
	padding: 8px;
	float:left;
}
#pic02{
	width: 180px;
	height: 96px;
	margin: 4px;
	background-color: #CCC;
	padding: 8px;
	float:left;
}

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王同学要努力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值