純css制作帶三角的邊框(附效果圖)
發(fā)布時(shí)間:2013-03-28 16:07:52 作者:佚名
我要評(píng)論

下面的效果完全是用css 來實(shí)現(xiàn)的,那么是怎么實(shí)現(xiàn)的呢,我們知道 html 中有一些特殊的字符,通過特殊字符,利用 css 中的margin或者position方法完全可以實(shí)現(xiàn)以上效果,感興趣的朋友可以參考下哈,希望可以幫助到你
首先附上效果圖:
以上的效果完全是用 css 來實(shí)現(xiàn)的,那么是怎么實(shí)現(xiàn)的呢?
我們知道 html 中有一些特殊的字符,具體的請(qǐng)點(diǎn)擊 HTML特殊字符大全。
通過特殊字符,利用 css 中的 margin 或者 position 方法完全可以實(shí)現(xiàn)以上效果。
復(fù)制代碼
代碼如下:<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>字符制作三角邊框</title>
<style type="text/css">
*{margin:0;padding:0;}
body{font-family:SimSun;}
h1{text-align:center;}
.demo1{width:300px;margin:20px auto;border:1px solid red;height:100px;}
.demo1 em,.demo1 span{display:block;width:30px;height:16px;font-size:30px;overflow:hidden;_position:relative;margin-left:10px;}
.demo1 em{margin-top:-16px;color:red;font-style:normal;}
.demo1 span{margin-top:-14px;color:white;}
.demo2{width:300px;border:1px solid #F00;height:100px;position:relative;margin-left:auto;margin-right:auto;}
.demo2 em,.demo2 span{font-style:normal;font-size:30px;position:absolute;left:-16px;top:40px;color:red;}
.demo2 span{left:-14px;color:white;}
</style>
</head>
<body>
<h1>demo1 是用 margin 方法</h1>
<div class="demo1">
<em>◆</em>
<span>◆</span>
</div>
<h1>demo2 是用 position 方法</h1>
<div class="demo2">
<em>◆</em>
<span>◆</span>
</div>
</body>
</html>
PS:除了用字符可以實(shí)現(xiàn)三角,我們還可以利用 border 來實(shí)現(xiàn)三角。具體地址:http://www.dbjr.com.cn/css/33748.html
相關(guān)文章
通過CSS邊框?qū)崿F(xiàn)三角形和箭頭的實(shí)例代碼
這篇文章主要介紹了通過CSS邊框?qū)崿F(xiàn)三角形和箭頭的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-15- 本文給大家介紹如何把三角畫出來,基于css代碼實(shí)現(xiàn)小三角邊框原理解析,感興趣的朋友跟隨小編一起看看吧2021-11-03