web ccs 布局方式

在这里插入图片描述

浮动布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浮动布局</title>
    <style>
        #parent{
            width: 408px;
            /* 方式一: height: 102px; */
            border: solid 1px red;
            margin: 0 auto;
            /* 方式三:在父元素中 增加 overflow: hidden;*/
            overflow: hidden;
        }
        #parent .child{
            width: 100px;
            height: 100px;
            border: dashed 1px #666;
            float: left;
        }
    </style>
</head>
<body>
    <div id="parent">
        <div class="child"></div>
        <div class="child"></div>
        <div class="child"></div>
        <div class="child"></div>
        <!-- 方式二:清除浮动的元素 <div style="clear: left;"></div> -->
    </div>
    <div>
        今天的天气很好
    </div>
</body>
</html>

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文字环绕</title>
    <style>
        .news{
            width: 416px;
            border: solid 1px red;
            /* 浮动布局 父类添加属性  overflow: hidden;*/
            overflow: hidden;
            margin-bottom: 8px;
        }
        img{
            width: 200px;
            height: 200px;
        }
        p{
            width: 200px;
            padding: 0;
            margin: 0;
            margin-left: 8px;
            margin-top: 8px;
            margin-right: 8px;
        }
        /* 浮动布局  向左浮动 */
        .fl{
            float: left;
        }
        /* 浮动布局 向右浮动 */
        .fr{
            float: right;
        }
    </style>
</head>
<body>
    <div class="news">
        <img class="fl" src="imgs/img02.png" alt="">
        <p class="fr">&nbsp;h-shadow 	取像素值,阴影的水平偏移距离
            v-shadow 	取像素值,阴影的垂直偏移距离
            blur 		取像素值,表示阴影的模糊程度,值越大越模糊
        </p>
    </div>

    <div class="news">
        <img class="fr" src="imgs/img02.png" alt="">
        <p class="fl">&nbsp;h-shadow 	取像素值,阴影的水平偏移距离
            v-shadow 	取像素值,阴影的垂直偏移距离
            blur 		取像素值,表示阴影的模糊程度,值越大越模糊
        </p>
    </div>
</body>
</html>

在这里插入图片描述

定位布局–相对定位

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>相对定位</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            border: solid 1px red;
        }
        /* 伪类 nth 批量 */
        /* 在集合中 查找某个子类 (1)第一个*/
        /* div:nth-child(1){
            
        } */
        div:nth-child(2){
            /* 相对定位 不脱离文档流 相对左边 8px*/
            position: relative;
            left: 8px;
        }
        div:nth-child(3){
            /* 相对定位 不脱离文档流 相对上边 8px*/
            position: relative;
            top: 8px;
            
        }
    </style>
</head>
<body>
    <!-- 通过元素的伪类 选择器 获取相同元素的 某个元素 -->
    <div></div>
    <div></div>
    <div></div>
</body>
</html>

在这里插入图片描述

定位布局-绝对定位

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绝对定位</title>
    <style>
        #parent{
            width: 300px;
            height: 300px;
            border: solid 1px gold;
            margin: 0 auto;
            /* 父元素设置为 绝对定位 */
            position: relative;
        }
        #parent>#child{
            width: 300px;
            height: 32px;
            background-color: rgba(0, 0, 255, 0.5);
            /* 子元素 相对定位 */
            position:absolute;
            /* left: 8px; */
            
            /* 相对底部 0px */
            bottom: 0px;
            color: white;
            text-align: center;
        }
        img{
            /* 子元素可以设置为 百分比的宽度 */
            /* 百分比相对于它的父元素 */
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="parent">
        <img src="imgs/img01.png" alt="">
        <div id="child">这是一个美女图片</div>
    </div>
</body>
</html>

在这里插入图片描述

定位布局 绝对定位

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>固定定位</title>
    <style>
        /* *代表全部页面的元素 */
        /* 删除默认样式 */
        *{
            margin: 0;
            padding: 0;
        }
        /* 上下固定定位 */
        #top, #bottom{
            text-align: center;
            background-color: #01204f;
            color: white;
            padding: 10px 0px;
            /* 固定定位 */
            position: fixed;
            /* 针对浏览器 */
            width: 100%;
            height: 25px;
        }
        #top{
            top: 0;
        }
        #bottom{
            bottom: 0;
        }
        #left, #right{
            width: 80px;
            height: 150px;
            background-color: red;
        }
        /* 左右固定定位 */
        #left{
            position: fixed;
            top: 180px;
            left: 0;
        }
        #right{
            position: fixed;
            right: 0;
            top: 180px;
        }
    </style>
</head>
<body>
    <div id="top">
        Web开发功能很强大啊!
    </div>
    <div id="left">

    </div>
    <div id="right">

    </div>
    <div id="bottom">
        Web开发功能很强大啊!
    </div>
    <!-- padding * 2 + height-->
    <div style="margin-top: 45px;">
        我是一个标题栏
    </div>
    <!-- 显示滚动条 -->
    <div style="height: 2000px;">

    </div>
</body>
</html>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

廷益--飞鸟

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

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

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

打赏作者

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

抵扣说明:

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

余额充值