博主信息
博文 35
粉丝 0
评论 0
访问量 27820
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
html和css基础知识(盒子模型and对齐方法and相对定位)—2018年8月17日17:01:24
Hi的博客
原创
965人浏览过

在web页面设计中。都是一个大盒子中套着无数个小盒子,因此学好盒子的模型设计。元素的对其方式,和相对定位的使用。在日后的布局中是相当有用的。

以下是我的代码

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>盒子、对齐方式、相对定位</title>
    <style>
        body{
            margin: 0;
            padding: 0;

        }
        h1,h3{
            text-align: center;
        }
        .box1{
            width: 300px;
            height: 300px;
            background:blue;
            color: #efefef;
        }
        .box2{
            width: 300px;
            height: 300px;
            background:green;
            color: #efefef;
            margin-top: 20px;
        }
        .box3{
            width: 300px;
            height: 300px;
            background: peru;
            color: #efefef;
            text-align: center;

        }
        .box3 span{
            line-height: 300px;
        }
        .box4 {
            width: 300px;
            height: 300px;
            background: pink;
            color: #efefef;

            text-align: center;
            /*display: table-cell;将这个盒子转换为一个单元格显示*/
            display: table-cell;
            /*vertical-align: middle; 垂直居中*/
            vertical-align: middle;
        }
        .box5{
            width: 300px;
            height: 300px;
            background: peru;
            display: table-cell;
            vertical-align: middle;
        }
        .box5 p{
            width: 200px;
            height: 200px;
            background: blueviolet;
            margin: 0 auto;
            text-align: center;
            line-height: 200px;
        }
        .box6{
            width: 300px;
            height: 300px;
            text-align: center;
            display: table-cell;
            /*vertical-align: bottom;位于底部*/
            vertical-align: bottom;
            background: #0388f1;
        }
        ul{
            margin: 0;
            padding: 0;
        }
        .box6 ul li{
            display: inline;
        }
        #box10{
            width: 900px;
            height: 900px;
            /*position: relative;把父级用来相对定位*/
            position: relative;
        }
        .a1{
            width: 300px;
            height: 300px;
            background: #0388f1;
            /*position: absolute;绝对定位*/
            position: absolute;
            top: 0;
            left: 300px;
        }
        .a2{
            width: 300px;
            height: 300px;
            background: #efefef;
            /*position: absolute;绝对定位*/
            position: absolute;
            top: 300px;
            left:0;
        }
        .a3{
            width: 300px;
            height: 300px;
            background:indianred;
            /*position: absolute;绝对定位*/
            position: absolute;
            top: 300px;
            left: 300px;
        }
        .a4{
            width: 300px;
            height: 300px;
            background: hotpink;
            /*position: absolute;绝对定位*/
            position: absolute;
            top: 300px;
            left: 600px;
        }
        .a5{
            width: 300px;
            height: 300px;
            background: powderblue;
            /*position: absolute;绝对定位*/
            position: absolute;
            top: 600px;
            left: 300px;
        }
    </style>
</head>
<body>
<h1>盒子模型</h1>
<div class="box1">我是盒子1</div>
<div class="box2">我是盒子2</div>
<hr>
<h1>元素对齐的四种方式</h1>
<h3>第一种</h3>
<div class="box3"><span>子元素是单行的行内元素</span></div>
<h3>第二种</h3>
<div class="box4">
    <span>子元素是多行的行内元素</span><br>
    <span>子元素是多行的行内元素</span>
</div>
<h3>第三种</h3>
<div class="box5">
    <p>子元素是块元素</p>
</div>
<h3>第四种</h3>
<div class="box6">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>子元素是不定宽的块元素</li>
    </ul>
</div>
<hr>
<h3>绝对定位</h3>
<div id="box10">
    <div class="a1"></div>
    <div class="a2"></div>
    <div class="a3"></div>
    <div class="a4"></div>
    <div class="a5"></div>
</div>
<hr>
</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+教程免费学