在開發頁面的時候,遇到很多的列表都需要用到箭頭,可以直接用圖片作背景鋪墊,純CSS也能實現,并且沒有兼容性顧慮,不用CSS3,相比而言,比圖片更好用。
原理:一個高寬相等的正方形,選取你所需要的某一邊,截取之,就是一個梯形,當高寬都為0,且其他邊為透明顏色時,一個三角形就出來了
梯形代碼:
html: <div class="arrow"></div> css: arrow{ width:10px; height:10px; border:10px solid #000; border-left-color:orange; }
把高寬設為0,其他邊為透明顏色,三角形出來了:
html: <div class="arrow"></div> css: arrow{ width:0; height:0; border: 10px solid transparent; border-left-color: orange;//左箭頭 }
在開發中,可以利用偽類,定位實現,不改變dom結構,簡潔優雅。content提供給三角形的位置,這個屬性不能少。
html: <div class="arrow">文字文字</div> css: div{ position:relative; arrow{ width:0; height:0; border: 10px solid transparent; border-left-color: orange; position:absolute; content:''; }
現在追求平面化設計,還有另一種三角線箭頭,更受歡迎。
設置兩個偽類,前一個偽類覆蓋至另一個了偽類,留出一些線出來就好:
html: <div class="arrow">文字文字</div> CSS: div { position: relative; } .arrow:after,.arrow:before { width: 0; height: 0; border: 10px solid transparent; border-left-color: orange; position: absolute; content: ""; } .arrow:before{ top: 0; left: 70px;//根據實際情況調整 border-left-color: white; }
may you like it.
感謝大家的閱讀,希望大家收益多多。
本文轉自:https://blog.csdn.net/qq_34250472/article/details/55513862
推薦教程:《CSS教程》
網站題目:帶你玩轉css中各種方向小箭頭
分享路徑:http://vcdvsql.cn/article28/chcjcp.html
成都網站建設公司_創新互聯,為您提供網站建設、商城網站、企業網站制作、軟件開發、網站維護、網站設計公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯