网页部分重构(网易)

经过对页面布局以及插入图片位置的不断调整,逐渐熟悉CSS样式规则以及多种选择器的应用。

代码记录

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网易严选</title>
    <style>
        html,body{
            width: 1250px; ;
            margin: 0;
            padding: 0;
        }
        .header{
            margin-top: 60px;
            padding-top: 60px;
            height: 100px;

        }
        .popularity{
            margin-bottom: 60px;
            height: 780px;
            background-color: rgb(204, 228, 236);
        }
        .name{
            margin: 0px 20px 0px 100px;
            padding-top: 0px;
            font-size: 28px;
            display: inline-block;
        }
        .name:hover{
            color: rgb(122, 17, 122);
            cursor: pointer;
        }
        .headerLeft{
            display: inline-block;
            margin: 10px 20px 10px 10px;
            padding-left: 10px;
            padding-right: 10px;
        }
        .headerLeft:hover{
           cursor: pointer;
           color: rgb(145, 32, 145);
        }
        .checked{
            color: rgb(184, 38, 171);
            border-bottom: 2px solid rebeccapurple;
        }
        .headerRight{
            margin-top: 13px;
            margin-right: 60px;
            float: right;
            display: inline;
        }
        .headerRight:hover{
            color: rgb(145, 32, 145);
            cursor: pointer;
        }
        .headerLeft,
        .headerRight{
            font-size: 14px;

        }
        #productItemfirst{
            margin-left: 0px;
            width: 390px;
            height: 570px;
        }
        #productItemFirst>:nth-child(2) {
      width: 320px;
      margin: 40px 35px;
    }

    #productItemFirst>:first-child {
      width: 48px;
      height: 48px;
      position: absolute;
    }

    #productItemFirst>:nth-child(2):hover {
      margin: 35px 30px;
      width: 336px;
      height: 336px;
      cursor: pointer;
    }

    .productItem {
      margin-left: 10px;
      background-color: white;
      width: 223px;
      height: 280px;
      float: left;
    }


    .productItem>:nth-child(2) {
      width: 200px;
      margin: 80px 100px;
    }

    .productItem>:first-child {
      width: 48px;
      height: 48px;
      position: absolute;
    }

    .productItem>:nth-child(2):hover {
      margin: 60px 80px;
      width: 240px;
      height: 240px;
      cursor: pointer;
    }
        .product{
            margin-left: 100px;
        }
        .product>:nth-child(5),
        .product>:nth-child(6),
        .product>:nth-child(7){
            margin-top: 10px;
        }
        #productItemFirst>.title {
      width: 100%;
      text-align: center;
      border-top: 1px solid #f4f0eb;
    }

    #productItemFirst>.title>.name {
      margin: 40px 71px 13px 71px;
      padding-top: 0px;
      font-size: 18px;
      display: inline-block;
    }

    #productItemFirst>.title>.name:hover {
      color: #b1a07d;
      cursor: pointer;
    }

    #productItemFirst>.title>.price {
      color: #D4282D;
      font-size: 18px;
    }

    /* 其它商品卡片的title样式 */
    .productItem>.title {
      width: 100%;
      text-align: center;
      border-top: 1px solid #f4f0eb;
    }

    .productItem>.title>.name {
      margin: 0 43.5px 4px;
      padding-top: 0px;
      font-size: 13px;
      display: inline-block;
    }

    .productItem>.title>.name:hover {
      color: #b1a07d;
      cursor: pointer;
    }

    .productItem>.title>.price {
      color: #D4282D;
      font-size: 13px;
      margin: 0;
    }


    </style>
</head>
<body>
    <div class="popularity" >
        <div class="headr">
            <h3 class="name">人气推荐</h3>
            <div class="headerLeft checked">编辑推荐</div>
            <div class="headerLeft">热销总榜</div>
            <div class="headerRight">更多推荐></div>
        </div>
        <div class="product">
            <div id="productItemfirst" class="productItem">
                <img src="https://yanxuan.nosdn.127.net/static-union/1628213373854ca1.png" alt="图片丢失">    
            <img src="https://yanxuan-item.nosdn.127.net/5d89a6f902e09a90d75db57c39c1b817.png?imageView&thumbnail=230x230&quality=95" alt="图片丢失">
       <div class="title">
           <h5 class="nameo">有效抑菌配方 免洗净手喷雾10ml便携卡片装</h5>
           <p class="price">¥21.8</p>
       </div>
        </div>
        <div class="productItem">
            <img src="https://yanxuan.nosdn.127.net/static-union/1628213373854ca1.png" alt="图片丢失">
            <div class="title ">
            </div>
          </div>
          <div class="productItem">3</div>
          <div class="productItem">4</div>
          <div class="productItem">5</div>
          <div class="productItem">6</div>
          <div class="productItem">7</div>
        </div>
      </div>
    </body>
    
    </html>

效果展示


 关于选择器:

 first-child伪类选择器是选择它父元素的第一个孩子的所有元素,这个父元素可以为任意的元素,比如body/div/section...,所以first-child可以选择大部分p标签。另外伪类比元素选择器有更高的优先级,即first-child会覆盖掉div > p的样式。

 关于边距:

1.外边距
CSS margin 属性用于在任何定义的边框之外,为元素周围创建空间。
margin: 25px 50px 75px 100px;
margin-top:25px
margin-right:50px
margin-bottom:75px
margin-left:100px

  • 可以将 margin 属性设置为 auto,以使元素在其容器中水平居中。然后,该元素将占据指定的宽度,并且剩余空间将在左右边界之间平均分配。
  • 外边距合并
    外边距合并指的是,当两个垂直外边距相遇时,它们将形成一个外边距。合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者。
    注释:
    只有普通文档流中块框的垂直外边距才会发生外边距合并。行内框、浮动框或绝对定位之间的外边距不会合并。

2.内边距
CSS padding 属性用于在任何定义的边界内的元素内容周围生成空间。
CSS width 属性指定元素内容区域的宽度。内容区域是元素(盒模型)的内边距、边框和外边距内的部分。

因此,如果元素拥有指定的宽度,则添加到该元素的内边距会添加到元素的总宽度中。这通常是不希望的结果。

若要将宽度保持为 300px,无论填充量如何,那么可以使用 box-sizing 属性。这将导致元素保持其宽度。如果增加内边距,则可用的内容空间会减少。 

关于浮动(float):

float 属性用于定位和格式化内容,例如让图像向左浮动到容器中的文本那里。

float 属性可以设置以下值之一:

  • left - 元素浮动到其容器的左侧
  • right - 元素浮动在其容器的右侧
  • none - 元素不会浮动(将显示在文本中刚出现的位置)。默认值。
  • inherit - 元素继承其父级的 float 值

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值