常见的布局技巧~(margin负值的应用、行内块巧妙应用以及三角的强化)

四.常见的布局技巧

1.1 margin负值运用

​ 商品的显示框

​ 1.解决盒子边框重合 margin:-1.....;
​ 2.鼠标经过某个盒子的时候,提高当前盒子的层级即可(如果没有有定位,则加相对定位(保留位置),如果有定位,则加z-index)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        ul,
        li {
            list-style: none;
        }
        
        a {
            text-decoration: none;
        }
        
        .w {
            width: 1178px;
            margin: 0 auto;
        }
        
        .wrapper {
            margin-top: 72px;
        }
        
        .wrapper ul {
            float: left;
        }
        
        .wrapper ul li {
            position: relative;
            float: left;
            height: 376px;
            width: 215px;
            padding: 75px 39px 18px 39px;
            margin: 0 -1px -1px 0;
            border: 1px solid #e0e0e0;
            text-align: center;
        }
        
        .wrapper ul li:hover {
            z-index: 1;
            border: 1px solid orangered;
        }
        
        .wrapper ul li>img {
            width: 100%;
            height: 270px;
        }
        
        .wrapper ul li a {
            display: block;
            margin-top: 18px;
            color: #828282;
            font-size: 16px;
        }
        
        .wrapper ul li h4 {
            margin-top: 46px;
            color: #349167;
        }
    </style>
</head>

<body>
    <div class="wrapper w">
        <ul>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
            <li>
                <img src="images/oppo1.png" alt="">
                <a href="#">
                    <p> 玫瑰金 前后1000万像素</p>
                </a>
                <h4>¥2900.00</h4>
            </li>
        </ul>
    </div>
</body>

</html>

1.2 文字围绕浮动元素运用

在这里插入图片描述
布局示意图
在这里插入图片描述
巧妙运用浮动元素不会压住文字的特性

1.3 行内块巧妙运用

在这里插入图片描述
页码在页面中间显示:

  1. 把这些链接盒子转换为行内块, 之后给父级指定 text-align:center;
  2. 利用行内块元素中间有缝隙,并且给父级添加 text-align:center; 行内块元素会水平会居中

​ 代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        a {
            text-decoration: none;
            color: #5a5959;
        }
        
        .box {
            text-align: center;
        }
        
        .box a {
            display: inline-block;
            width: 36px;
            height: 36px;
            text-align: center;
            line-height: 36px;
            font-size: 14px;
            background-color: #cccccc;
        }
        
        .box .prev,
        .box .next {
            width: 85px;
        }
        
        .box .clicked,
        .box .ellip {
            background-color: #fff;
        }
        
        .box input {
            width: 45px;
            height: 36px;
            outline: none;
            border: 1px solid #cccccc;
        }
        
        button {
            width: 55px;
            height: 34px;
            border: none;
            outline: none;
            cursor: pointer;
            background-color: #cccccc;
        }
    </style>
</head>

<body>
    <div class="box">
        <a href="#" class="prev">&lt;&lt;上一页</a>
        <a href="#">1</a>
        <a href="#" class="clicked">2</a>
        <a href="#">3</a>
        <a href="#">4</a>
        <a href="#">5</a>
        <a href="#">6</a>
        <a href="#" class="ellip">...</a>
        <a href="#" class="next">&gt;&gt;下一页</a> 跳转到第
        <input type="text" name="" id=""><button>确定</button>
    </div>
</body>

</html>

1.4 三角强化

案例:
在这里插入图片描述

​代码:京东价格标签栏

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 185px;
            height: 25px;
            margin: 100px auto;
            line-height: 25px;
            border: 1px solid orangered;
            font-size: 14px;
            font-weight: 700;
            color: #cccccc;
        }
        
        .box .decreace {
            position: relative;
            float: left;
            width: 100px;
            height: 100%;
            margin-right: 10px;
            text-align: center;
            background-color: orangered;
        }
        
        .decreace i {
            position: absolute;
            top: 0;
            right: 0;
            width: 0;
            height: 0;
            border-width: 25px 10px 0 0;
            border-style: solid;
            border-color: transparent white transparent transparent;
        }
        
        .box .price {
            text-decoration: line-through;
        }
    </style>

</head>

<body>
    <div class="box">
        <span class="decreace">¥1256
            <i></i>
        </span>
        <span class="price">¥3489</span>
    </div>
</body>

</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值