欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          css怎么實現(xiàn)三角形

          實現(xiàn)方法:1、利用高寬為零的容器和透明的border;2、利用線性漸變linear-gradient;3、使用“transform:rotate”配合“overflow:hidden”;4、利用“&#9660”、“&#9650”等字符繪制。

          css怎么實現(xiàn)三角形

          本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。

          使用 border 繪制三角形

          使用 border 實現(xiàn)三角形應該是大部分人都掌握的,也是各種面經(jīng)中經(jīng)常出現(xiàn)的,利用了高寬為零的容器及透明的 border 實現(xiàn)。

          簡單的代碼如下:

          <div class='normal'></div>
          html, body {   width: 100%;   height: 100%;   display: flex; }  div {   width: 0px;   height: 0px;   margin: auto; }  .normal {   border-top: 50px solid yellowgreen;   border-bottom: 50px solid deeppink;   border-left: 50px solid bisque;   border-right: 50px solid chocolate; }

          高寬為零的容器,設置不同顏色的 border:

          css怎么實現(xiàn)三角形

          這樣,讓任何三邊的邊框的顏色為 transparent,則非常容易得到各種角度的三角形:

          <div class='top'></div> <div class='bottom'></div> <div class='left'></div> <div class='right'></div>
          .top {   border: 50px solid transparent;   border-bottom: 50px solid deeppink; }  .left {   border: 50px solid transparent;   border-right: 50px solid deeppink; }  .bottom {   border: 50px solid transparent;   border-top: 50px solid deeppink; }  .right {   border: 50px solid transparent;   border-bottom: 50px solid deeppink; }

          css怎么實現(xiàn)三角形

          使用 linear-gradient 繪制三角形

          接著,我們使用線性漸變 linear-gradient 實現(xiàn)三角形。

          它的原理也非常簡單,我們實現(xiàn)一個 45° 的漸變:

          div {   width: 100px;   height: 100px;   background: linear-gradient(45deg, deeppink, yellowgreen); }

          css怎么實現(xiàn)三角形

          讓它的顏色從漸變色變?yōu)閮煞N固定的顏色:

          div {   width: 100px;   height: 100px;   background: linear-gradient(45deg, deeppink, deeppink 50%, yellowgreen 50%, yellowgreen 100%); }

          css怎么實現(xiàn)三角形

          再讓其中一個顏色透明即可:

          div {   background: linear-gradient(45deg, deeppink, deeppink 50%, transparent 50%, transparent 100%); }

          css怎么實現(xiàn)三角形

          transform: rotate 配合 overflow: hidden 繪制三角形

          這種方法還是比較常規(guī)的,使用 transform: rotate 配合 overflow: hidden。一看就懂,一學就會,簡單的動畫示意圖如下:

          css怎么實現(xiàn)三角形

          設置圖形的旋轉中心在左下角 left bottom,進行旋轉,配合 overflow: hidden。

          完整的代碼:

          <div class="demo"></div> <div class="demo-opacity"></div> <div class="triangle"></div>
          html, body {     width: 100%;     height: 100%;     display: flex; }  div {     width: 141px;     height: 100px;     margin: auto; }  .demo-opacity {     overflow: hidden; }  .demo, .demo-opacity {     position: relative;     border: 1px solid #000;     background: unset;          &::before {         content: "";         position: absolute;         top: 0;         left: 0;         right: 0;         bottom: 0;         animation: conicmove 3s infinite linear;         background: deeppink;         transform-origin: left bottom;         z-index: -1;     } }  .triangle {     position: relative;     background: unset;     overflow: hidden;          &::before {         content: "";         position: absolute;         top: 0;         left: 0;         right: 0;         bottom: 0;         background: deeppink;         transform-origin: left bottom;         transform: rotate(45deg);         z-index: -1;     } }  @keyframes conicmove {     100% {         transform: rotate(45deg);     } }

          利用字符繪制三角形

          OK,最后一種,有些獨特,就是使用字符表示三角形。

          下面列出一些三角形形狀的字符的十進制 Unicode 表示碼。

          ? : &#9668;  ? : &#9658;  ▼ : &#9660;  ▲ : &#9650; ⊿ : &#8895; △ : &#9651;

          譬如,我們使用 &#9660; 實現(xiàn)一個三角形 ▼,代碼如下:

          <div class="normal">&#9660; </div>
          div {     font-size: 100px;     color: deeppink; }

          效果還是不錯的:

          css怎么實現(xiàn)三角形

          (學習視頻分享:css視頻教程)

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號