搜索
博主信息
博文 48
粉丝 0
评论 0
访问量 44545
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
css 边距、填充、对齐方式、定位|2018年8月16号作业
雨天的博客
原创
994人浏览过

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
    </div>
    <hr>
    <div class="box3">
        <h3>父元素是块元素:根据子元素不同分为以下几种</h3>
        <h4>1.子元素是行内元素:在父元素设置text-align: center水平居中;垂直居中设置子元素和父元素行号一样line-height</h4>
        <div class="box4">
            <span>行内元素</span>
        </div>
        <h4>2.子元素是多行内联元素:在父元素设置text-align: center水平居中;垂直居中设置子父元素display: table-cell;vertical-align: middle;</h4>
        <div class="box5"><span>多行内联元素</span><br><span>多行内联元素</span></div>
        <h4>3.子元素是块元素:子元素设置margin:auto 水平居中;垂直居中设置子父元素display: table-cell;vertical-align: middle;</h4>
        <box class="box6">
            <div class="box7">
                <p>块元素</p>
            </div>
        </box>
        <h4>4.子元素是不定宽块元素:<br>父元素div和子元素ul设置text-align:center水平居中<br>垂直居底设置子父元素divdisplay: table-cell;vertical-align: middle;<br>设置li行内显示dispaly:inline</h4>
        <div class="box8">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ul>
        </div>
    </div>
    <hr>
    <div class="box9">
        <div class="left"></div>
        <div class="right"></div>
        <div class="top"></div>
        <div class="bottom"></div>
        <div class="center"></div>
    </div>
    <style>
        body{font-family: "微软雅黑"}
        .box{width: 200px;height: 170px;border: solid 2px #880000;padding-top: 30px;}
        .box1{width:140px;height: 140px;background: blueviolet;margin-left: 30px;}
        .box3{}
         h3,h4{font-weight: normal}
         h3{color: #880000;}
        .box4{width:200px;height: 200px;background: chocolate;text-align: center;line-height: 200px;}
        .box4 span{color:#FFF;}
        .box5{width:200px;height: 200px;text-align: center;display: table-cell;vertical-align: middle;background: #4288ce;}
        .box5 span{color: #f8cbcb}
        .box6{width:200px;height: 200px;background: coral;display: table-cell;vertical-align: middle}
        .box7{width:100px;height:100px;background: lightblue;line-height: 100px;margin: auto;text-align: center;}
        .box8{width:200px;height: 200px;background:#880000;text-align: center;display: table-cell;vertical-align:bottom}
        .box8 ul{text-align: center;margin:0;padding: 0;}
        .box8 ul li{list-style: none;display: inline;color: darkturquoise;}
        .box9{width:330px;height: 330px;position: relative;margin:0;padding: 0;background: #f8cbcb;}
        /*父元素相对定位*/
        .box9 div{position: absolute;}
        /*子元素绝对定位*/
        .left,.right{width:150px;height: 30px;}
        .top,.bottom{width:30px;height:150px;}
        .center{width:30px;height:30px;}
        .left{background: coral;top:150px;left:0;}
        .right{background: cornflowerblue;top:150px;left:180px;}
        .top{background: darkturquoise;top:0;left:150px;}
        .bottom{background: blueviolet;top:180px;left:150px;}
        .center{background: crimson;top:150px;left:150px;}
    </style>
</body>
</html>

运行实例 »

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


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

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

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