欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何用css實(shí)現(xiàn)三角形

本篇內(nèi)容介紹了“如何用css實(shí)現(xiàn)三角形”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的洛扎網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

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

如何用css實(shí)現(xiàn)三角形

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

使用 border 繪制三角形

使用 border 實(shí)現(xiàn)三角形應(yīng)該是大部分人都掌握的,也是各種面經(jīng)中經(jīng)常出現(xiàn)的,利用了高寬為零的容器及透明的 border 實(shí)現(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;
}

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

如何用css實(shí)現(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實(shí)現(xiàn)三角形

使用 linear-gradient 繪制三角形

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

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

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

如何用css實(shí)現(xiàn)三角形

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

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

如何用css實(shí)現(xiàn)三角形

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

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

如何用css實(shí)現(xiàn)三角形

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

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

如何用css實(shí)現(xiàn)三角形

設(shè)置圖形的旋轉(zhuǎn)中心在左下角 left bottom,進(jìn)行旋轉(zhuǎn),配合 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,最后一種,有些獨(dú)特,就是使用字符表示三角形。

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

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

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

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

效果還是不錯的:

如何用css實(shí)現(xiàn)三角形

“如何用css實(shí)現(xiàn)三角形”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

本文標(biāo)題:如何用css實(shí)現(xiàn)三角形
URL地址:http://www.chinadenli.net/article48/geiiep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航做網(wǎng)站ChatGPTGoogle營銷型網(wǎng)站建設(shè)網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)