移動端1px 邊框完整方案(四個方向)

來源:互聯網
上載者:User

標籤:media   長度   dia   pixel      lang   blog   osi   上下   

使用stylus(預先處理)

需要一個函數接收兩個參數 第一個需要在哪個方向出現邊框 第二個邊框顏色

$border1px(face,$color)

根據傳入的方向屬性,調整其他參數

l  左右方向

t  垂直方向

w 上下出現邊框則為width反之為height(邊框在方向上的長度)

b 上出現邊框則為bottom  

x 為哪個方向上的縮放  

具體對應關係如下

  face==top    && (l=left  t=top b=bottom w=width  x=scaleY)  face==bottom && (l=left  b=top t=bottom w=width  x=scaleY)  face==left   && (l=left  t=top b=right  w=height x=scaleX)  face==right  && (l=right t=top b=left   w=height x=scaleX)

下面是邊框

  .border-1px {    position relative  }  .border-1px::after {    display block    position absolute    {l} 0    {t} 0    {w} 100%    border-{b} 1px solid $color    content ‘ ‘  }

媒體查詢

這裡需要使用字串拼接 寫成x(0.7)  x將不會賦值

  @media (-webkit-min-device-pixel-ratio 1.5),(min-device-pixel-ratio1.5) {    .border-1px::after {      -webkit-transform x+‘(0.7)‘      transform x+‘(0.7)‘    }  }  @media (-webkit-min-device-pixel-ratio 2),(min-device-pixel-ratio 2) {    .border-1px::after {      -webkit-transform x+‘(0.5)‘      transform x+‘(0.5)‘    }  }

html

  <div class="product">    <div class="border-1px">      <p>111</p>      <p>111</p>      <p>111</p>      <p>111</p>    </div>  </div>

css

<style scoped lang="stylus">@import ‘../common/css/index‘.product  $border1px(top,red)  border-bottom 1px solid red</style>

完整代碼

 1 $border1px(face,$color) 2   face==top    && (l=left  t=top b=bottom w=width  x=scaleY) 3   face==bottom && (l=left  b=top t=bottom w=width  x=scaleY) 4   face==left   && (l=left  t=top b=right  w=height x=scaleX) 5   face==right  && (l=right t=top b=left   w=height x=scaleX) 6   .border-1px { 7     position relative 8   } 9   .border-1px::after {10     display block11     position absolute12     {l} 013     {t} 014     {w} 100%15     border-{b} 1px solid $color16     content ‘ ‘17   }18   @media (-webkit-min-device-pixel-ratio 1.5),(min-device-pixel-ratio1.5) {19     .border-1px::after {20       -webkit-transform x(0.7)21       transform x+‘(0.7)‘22     }23   }24   @media (-webkit-min-device-pixel-ratio 2),(min-device-pixel-ratio 2) {25     .border-1px::after {26       -webkit-transform x+‘(0.5)‘27       transform x+‘(0.5)‘28     }29   }

 

移動端1px 邊框完整方案(四個方向)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.