博主信息
博文 15
粉丝 0
评论 0
访问量 11252
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
盒子模型,定位技术,元素的对齐方法
if柚的博客
原创
984人浏览过


实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>相对定位</title>
    <style>
        .box1 {
            width: 200px;
            height: 200px;
            background-color: lightblue;
            position: relative;
            left: 200px;
            top: 0;
        }
        .box2 {
            width: 200px;
            height: 200px;
            background-color: lightgreen;

        }
        .box3 {
            width: 200px;
            height: 200px;
            background-color: lightcoral;
            position: relative;
            left: 400px;
            top: -200px;
        }
        .box4 {
            width: 200px;
            height: 200px;
            background-color: lightgrey;
            position: relative;
            top: -200px;
            left: 200px;

        }
    </style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!doctype html>
<html>
	<head>
		<title>4种元素的对齐方案</title>
		<meta charset="utf-8">
	</head>
	<body>
		<div class="box1" >
			<a href="https://www.baidu.com">baidu</a>
		</div>
		<div class="box2">
			<span>我是一个行内文本</span><br>
			<span>我是一个行内文本</span>
		</div>
		<div class="box3">
			<div id="child">块元素</div>
		</div>
		<div class="box4">
             <ul>
                  <li><a href="">1</a></li>
                  <li><a href="">2</a></li>
                  <li><a href="">3</a></li>
                  <li><a href="">4</a></li>
                  <li><a href="">5</a></li>
             </ul>
        </div>
		<style>
		/*1. 子元素是单行行内元素: 如a, span
a:水平居中: 在父元素应用: text-align: center;
b:垂直居中: 在行内子元素上设置行高与父元素等高: line-height:200px;
*/
		    .box1{
		    	color:white;/*在这个地方设置字体颜色没用*/
		    	width:200px;
		    	height:200px;
		    	background:black;
		    	text-align:center;/*水平居中*/

		    }
		    .box1 a {
		    	line-height:200px;/*垂直居中*/
		    	color:white;
		    }
/*2 子元素是多行的行内元素:
a:水平居中: 在父元素应用: text-align: center;
b:垂直居中: 在父元素: display:table-cell;*/
		    .box2{
		    	color:#FFD801;
		    	width:200px;
		    	height:200px;
		    	background:#F62217;
		    	text-align: center; /*水平居中*/
		    	display:table-cell;
		    	vertical-align: middle; /*垂直居中*/
               }
		    
/*3 子元素是块元素
a: 水平居中: 子元素设置左右外边距自动适应容器margin: auto;
b:垂直居中: 在父元素: display:table-cell;*/

		     .box3{
		    	color:#FF00FF;
		    	width:200px;
		    	height:200px;
		    	background:#FAAFBE;
		    	display:table-cell;
		    	vertical-align: middle;/*垂直居中*/
		    	}
		     .box3 #child{
		     	width: 100px;
                height: 100px;
		     	background:red;
		     	color:black;
		     	margin:auto; /*水平居中*/

		     }
		     .box4 {
                width: 200px;
                height: 200px;
                background-color: lightblue;
                text-align: center; /*水平居中*/
                display: table-cell;
                vertical-align: bottom; /*位于底部*/

             }
             ul {
                   margin: 0;
                   padding-left: 0;
                }
              .box4 li {
              display: inline;  /*将块元素转为行内元素*/
                
		        }
		</style>
	</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!DOCTYPE HTML>
<HTML>
    <HEAD>
    	<TITLE>盒子模型基本要素</TITLE>
    	<meat charset="utf-8">
	</HEAD>
	<body>
		<div class="box1">我是第1个盒子</div>
		<div class="box2">我是第2个盒子</div>
		<div class="box3">我是第3个盒子</div>
		<div class="box4">我是第4个盒子</div>
		<style>
		    .box1{
		    	width:200px;
		    	height:200px;
		    	color:red;
		    	background:black;
		    	/*padding-top:10px;
		    	padding-right:30px;
		    	padding-bottom:20px;
		    	padding-left:20px;*/
		    	padding:10px 30px 20px 20px;
		    	/*border-top-width:5px;
		    	border-top-color:red;
		    	border-top-style: solid;*/
		    	border-top:5px solid red;
		    	border-right:5px dashed red;
		    	border-bottom:5px solid red;
		    	border-left:5px dashed red;
		    	/*margin-top:10px;
		    	margin-right:20px;
		    	margin-bottom:30px;
		    	margin-left:40px;*/
		    	margin:10px 20px 30px 40px;

		    	
		    }
	    </style>
	</body>	
</HTML>

运行实例 »

点击 "运行实例" 按钮查看在线实例


批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学