乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      CSS實(shí)現(xiàn)帶陰影的三角形

       前端技術(shù)分享 2019-03-28

      怎么用CSS畫一個(gè)帶陰影的三角形呢 ?

      有童鞋說(shuō), 這還不簡(jiǎn)單嗎

      網(wǎng)上有很多解決方案, 但其實(shí)大多都是實(shí)現(xiàn)不太完美的, 存在一些問題

      假設(shè)我們做一個(gè)向下的三角形箭頭

      常見的方法大致有兩種

      1.通過(guò)邊框控制, border-left和border-right設(shè)為透明, border-top設(shè)為預(yù)定的顏色即可
      2.通過(guò) transform 旋轉(zhuǎn)盒子

      1. 設(shè)計(jì)

      2.1 邊框法

      html結(jié)構(gòu)

      <body>
          <div class="box"></div>
      </body>

      css樣式

      .box {
          position: relative;
          width: 200px;
          height: 100px;
          background: #ff8605;
          box-shadow: 2px 2px 2px rgba(0, 0, 0, .2);
      }
      .box::after {
          content: '';
          position: absolute;
          bottom: -9px;
          left: 45px;
          border-left: 10px solid transparent;
          border-right: 10px solid transparent;
          border-top: 10px solid #ff8605;
      }

      缺點(diǎn)很明顯, 我們不能通過(guò)box-shadow的方式來(lái)設(shè)置陰影, 陰影會(huì)是一個(gè)盒子

      但如果不用設(shè)陰影, 只是需要邊框的話, 我們可以再定義一個(gè)偽類元素, 覆蓋到三角形的下面即可

      .box::before {
          position: absolute;
          bottom: -10px;
          left: 45px;
          content: '';
          border-left: 10px solid transparent;
          border-right: 10px solid transparent;
          border-top: 10px solid rgba(0, 0, 0, .1);
      }

      如圖所示

      如果要求不嚴(yán)格似乎也夠用了. 但作為一個(gè)嚴(yán)格的前端工程師! 我們還是不能容忍這種實(shí)現(xiàn)方法

      正確的姿勢(shì)是使用濾鏡(filter)中的drop-shadow()

      drop-shadow才是真正意義上的投影,而box-shadow只是盒陰影

      它只會(huì)投影出真實(shí)圖形的陰影

      .box::after {
          position: absolute;
          bottom: -9px;
          left: 45px;
          content: '';
          border-left: 10px solid transparent;
          border-right: 10px solid transparent;
          border-top: 10px solid #ff8605;
          filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, .2));
      }

      2.2 transform方法

      這種方法的思路就是使用transform旋轉(zhuǎn)盒子, 一半被上面的容器遮擋, 一半顯示出來(lái)

      .box::before {
          position: absolute;
          bottom: -5px;
          left: 45px;
          content: '';
          width: 10px;
          height: 10px;
          background: #ff8605;
          transform: rotate(135deg);
          box-shadow: 1px -2px 2px rgba(0, 0, 0, .2);
      }

      我們似乎實(shí)現(xiàn)了我們想要的結(jié)果, 但是, 其實(shí)是存在一個(gè)問題的, 但因?yàn)槲覀兊年幱懊娣e不夠大, 所以圖片上看起來(lái)不明顯

      當(dāng)我們把box-shadow的陰影面積擴(kuò)大時(shí), 我們發(fā)現(xiàn)到問題的所在了

      盒子突出來(lái)了, 那怎么解決呢

      我們?cè)俣x一個(gè)與容器顏色相同的盒子, 將上半部分蓋住就可以啦.

      /* transform方法 */
      .box::before {
          position: absolute;
          bottom: -5px;
          left: 45px;
          content: '';
          width: 10px;
          height: 10px;
          background: #ff8605;
          transform: rotate(135deg);
          box-shadow: 1px -2px 5px rgba(0, 0, 0, .2);
      }
      .box::after {
          position: absolute;
          bottom: 0px;
          left: 40px;
          content: '';
          width: 20px;
          height: 20px;
          background: #ff8605;
      }

      要注意三角形應(yīng)該用before定義, 覆蓋的盒子應(yīng)該用after定義, 這樣盒子才能覆蓋到三角形上面

      實(shí)現(xiàn)效果:

      當(dāng)然這種方法有可能影響盒子內(nèi)的內(nèi)容

      1. 最終解決方案代碼

      <!DOCTYPE html>
      <html>
          <head>
              <meta charset="utf-8" />
              <meta name="viewport" content="width=device-width" />
              <title>CSS實(shí)現(xiàn)帶陰影效果的三角形</title>
              <style>
                  .box {
                      position: relative;
                      width: 200px;
                      height: 100px;
                      background: #ff8605;
                      box-shadow: 2px 2px 2px rgba(0, 0, 0, .2);
                  }
                  
                  /* drop-shadow */
                  .box::after {
                      position: absolute;
                      bottom: -9px;
                      left: 45px;
                      content: '';
                      border-left: 10px solid transparent;
                      border-right: 10px solid transparent;
                      border-top: 10px solid #ff8605;
                      filter: drop-shadow(1px 3px 1px rgba(0, 0, 0, .2));
                  }
                  
                  /* tranform */
                  .box::before {
                      position: absolute;
                      bottom: -5px;
                      left: 45px;
                      content: '';
                      width: 10px;
                      height: 10px;
                      background: #ff8605;
                      transform: rotate(135deg);
                      box-shadow: 1px -2px 5px rgba(0, 0, 0, .2);
                  }
                  
                  .box::after {
                      position: absolute;
                      bottom: 0px;
                      left: 40px;
                      content: '';
                      width: 20px;
                      height: 20px;
                      background: #ff8605;
                  }
              </style>
          </head>
          <body>
              <div class="box"></div>
          </body>
      </html>

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多