老师问下怎么去除toggle以及下拉层中间的阴影,我试了一些办法好像都不行

来源:3-5 自由编程

vivi_li

2020-05-28 13:13:57

我写在一起了  其余文件老师可以用课上那些 ,另外还有个问题  

我如果设置cart  的maigin-top值的话,底部的下拉层会与上方toggle部分重叠,是什么原因呢

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>购物车组件</title>
   <link rel="stylesheet" href="../css/base.css">
   <link rel="stylesheet" href="../css/common.css">
<!--    <link rel="stylesheet" href="../css/index.css">-->
   <style>
       .container{
           margin-bottom: 30px;
       }
       .cart>a{
           display: block;
           color: #fff;
           width: 158px;
           background-color: #f01414;
           height: 40px;
           text-align: center;
           line-height: 40px;
           font-size: 14px;
           border: 1px solid #f01414;
       }
       .cart:hover>a{
           color: #f01414;
           background-color: #fff;
           border-color: #e9e9e9;
           border-bottom: none;
           box-shadow: 0 0 3px rgba(0, 0, 0,.1);
       }
       .cart-line{
           margin: 0 15px 0 13px;
       }
       i.dropdown-cart{
           margin-right: 14px;
       }
       .cart i:nth-child(2){
           margin-left: 14px;
       }
       .cart .dropdown-layer{
           /*display: block;*/
           padding: 0 30px 0 12px;
           font-size: 14px;
           border: 1px solid #d9dde1;
           min-width: 278px;
           top: 40px;
           box-shadow: 0 0 3px rgba(0, 0, 0,.1);

       }
       .cart-bd{
           height: 52px;
           line-height: 52px;
           color: #000;
           border-bottom: 1px solid #d9dde1;
           text-indent: 12px;
       }
       .cart .dropdown-layer .cart-item{
           height: 44px;
           padding: 10px;
           border-bottom: 1px solid #d9dde1;
       }

       .cart-item .cart-detail{
           max-width: 145px;
           margin-left: 15px;
       }
       .cart-item .cart-detail-title{
           width: 145px;
           color: #4d555d;
           margin-top: 6px;
           font-size: 12px;
       }
       .word-nowrap{
           overflow: hidden;
           white-space: nowrap;
       }
       .cart-item .cart-delete{
           margin-top: 5px;
       }
       .cart-detail-price{
           margin-top: 10px;
           color: #4d555d;
           font-weight: 700;
       }
       .cart-ft{
           padding-left: 12px;
           height: 68px;
           line-height: 68px;
           color: #000;
       }
       .cart-ft-price::before{
           content: " ¥";
           display: inline-block;
       }
       .cart-ft-linkCart{
           display: inline-block;
           width: 80px;
           height: 35px;
           border-radius: 3px;
           background-color: #f01410;
           line-height: 35px;
           color: #fff;
           cursor: pointer;
           text-align: center;
           margin-top: 15px;
       }
   </style>
</head>
<body>
<div class="container">
   <div class="cart fr dropdown" data-active="cart"  data-load="cart.json">
       <a href="###" target="_blank" class="dropdown-toggle link transition">
           <i class="dropdown-cart icon">&#xe601;</i>
           购物车
           <span class="cart-line">|</span>
           <span class="cart-count-total">0</span>
           <i class="dropdown-arrow icon">&#xe7b1;</i>
       </a>
       <div class="dropdown-layer dropdown-right">
           <div class="dropdown-loading"></div>
<!--            <div class="cart-bd"><strong>最新加入的宝贝</strong></div>-->
<!--            <ul class="cart-content">-->
<!--                <li class="cart-item">-->
<!--                    <div class="cart-img fl"><a href="###" target="_blank"><img src="../img/1.png" alt=""></a></div>-->
<!--                    <div class="cart-detail fl">-->
<!--                        <div class="cart-detail-title word-nowrap fl">adidas 阿迪达斯 训练 男子</div>-->
<!--                        <div class="cart-detail-price fl">¥-->
<!--                            <strong class="price">299</strong>&nbsp;x-->
<!--                            <strong class="cart-detail-count">2</strong>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="cart-delete fr"><i class="icon">&#xe60a;</i></div>-->
<!--                </li>-->
<!--                <li class="cart-item">-->
<!--                    <div class="cart-img fl"><a href="###" target="_blank"><img src="../img/1.png" alt=""></a></div>-->
<!--                    <div class="cart-detail fl">-->
<!--                        <div class="cart-detail-title word-nowrap fl">adidas 阿迪达斯 训练 男子</div>-->
<!--                        <div class="cart-detail-price fl">¥-->
<!--                            <strong class="price">299</strong>&nbsp;x-->
<!--                            <strong class="cart-detail-count">2</strong>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="cart-delete fr"><i class="icon">&#xe60a;</i></div>-->
<!--                </li>-->
<!--            </ul>-->
<!--            <div class="cart-ft ">-->
<!--                共 <strong>0</strong>-->
<!--                件商品-->
<!--                &nbsp;&nbsp;共计<strong class="cart-ft-price">200.00</strong>-->
<!--                <a href="###" class="cart-ft-linkCart fr">去购物车</a>-->
<!--            </div>-->
       </div>
   </div>
</div>
</body>
<!--<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>-->
<script>
   window.jQuery || document.write('<script src="../plug/jQ/jQuery3.5.1.js"><\/script>');
</script>
<!--<script src='plug/jQ/jQuery3.5.1.js'></script>-->
<script src="../js/transition.js"></script><!--此文件须早于引用文件引入-->
<script src="../js/showHide.js"></script><!--此文件须早于引用文件引入-->
<script src="../js/dropdown.js"></script><!--此文件须早于引用文件引入-->
<script src="../js/search.js"></script>
<!--<script src="../js/index.js"></script>-->
<script>
   //menu
   //四舍五入保留2位小数(不够位数,则用0替补)
   function keepTwoDecimalFull(num) {
       var result = parseFloat(num);
       if (isNaN(result)) {
           alert('传递参数错误,请检查!');
           return false;
       }
       result = Math.round(num * 100) / 100;
       var s_x = result.toString();
       var pos_decimal = s_x.indexOf('.');
       if (pos_decimal < 0) {
           pos_decimal = s_x.length;
           s_x += '.';
       }
       while (s_x.length <= pos_decimal + 2) {
           s_x += '0';
       }
       return s_x;
   }
   $(".cart").on("dropdown-show",function (e) {
       var $this = $(this),
           $cartCountTotal=$this.find(".cart-count-total")
           dataLoad = $this.data("load");

       console.log(dataLoad)
       if (!dataLoad) return;
       if(!$this.data("loaded")){
           var $layer = $this.find(".dropdown-layer"),
               total = 0,
               html = "";

           //确保异步请求只调用一次,以免重复渲染页面
           $.getJSON(dataLoad,function (data) {
               // console.log(data)
               setTimeout(function () {
                   var dataLength = data.length
                   for (var i = 0;i<dataLength;i++){
                       total+=data[i]['count']*data[i]['price'];

                       html += '<li class="cart-item">'+
                                  '<div class="cart-img fl">' +
                                       '<a href="###" target="_blank">' +
                                           '<img src="'+data[i].url+'" alt="'+data[i].detail+'">' +
                                       '</a>'+
                                   '</div>'+
                                   '<div class="cart-detail fl">'+
                                       '<div class="cart-detail-title word-nowrap fl">'+data[i].detail+'</div>'+
                                       '<div class="cart-detail-price fl">¥'+
                                           '<strong class="price">'+data[i]['price']+'</strong>&nbsp;x'+
                                           '<strong class="cart-detail-count">'+data[i]['count']+'</strong>'+
                                        '</div>'+
                                   '</div>'+
                                   '<div class="cart-delete fr">'+'<i class="icon">'+'&#xe60a;'+'</i></div>'+
                               '</li>'
                   }
                   total=keepTwoDecimalFull(total);
                   $layer.html('<div class="cart-bd">'+'<strong>'+'最新加入的宝贝'+'</strong></div>'+
                       '<ul class="cart-content">'+html+'</ul>'+ '<div class="cart-ft ">'+ '共 <strong>'+dataLength+'</strong>'+ '件商品'+ '&nbsp;&nbsp;共计<strong class="cart-ft-price">'+total+'</strong>'+ ' <a href="###"' +'class="cart-ft-linkCart fr">'+'去购物车'+'</a>'+ ' </div>');
                   //加载完成标记
                   $this.data("loaded",true);
                   $cartCountTotal.text(dataLength)
               },1000)
           })
       }
   })
   $(".dropdown").dropdown({
       css3:true,
       js:false,
       delay:0,
   })

</script>
</html>

写回答

4回答

好帮手慕言

2020-05-28

同学你好,目前阶段,同学可以自己斟酌一下样式怎么设置会好些,保持美观即可,在实际工作中,根据设计稿来定就可以(一般情况下,公司会有设计师,会提供设计稿)。

祝学习愉快~

0

好帮手慕言

2020-05-28

同学你好,这与浏览器有关系,例如谷歌浏览器,不能比12px小,如果小于12px的话,会默认显示12px。同学了解下即可,不要设置的太小,用户体验也不好。祝学习愉快~

0
hivi_li
h 那假如如果购物车总金额比较大怎么办?设置省略号?( 0 x 0 )
h020-05-28
共1条回复

好帮手慕言

2020-05-28

同学你好,如果字体设置的很小,是不生效的,建议:把值设置的大些,例如20px。

祝学习愉快~

0
hivi_li
h 为什么?因为我看图上比较小,主要是因为购物车总金额如果比较大可能会让购物车那个按钮到下一行,所以我想设置的小点
h020-05-28
共1条回复

好帮手慕言

2020-05-28

同学你好,可以设置一个伪元素遮盖住,例如:
http://img.mukewang.com/climg/5ecf5b17091bf04704160233.jpg

设置maigin-top值会发生重叠指的是哪里呢?可以把代粘贴过来,并把效果截图上传,老师帮助解答。

祝学习愉快~

0
hivi_li
h 我找下,另外老师帮我看下 layer里面的尾部的商品价格以及数量部分我无法更改里面strong标签的字体大小 比如.cart-ft-price{ font-size: 8px; } 无法生效
h020-05-28
共1条回复

0 学习 · 14456 问题

查看课程