Home Web Front-end HTML Tutorial border-width实现回复效果_html/css_WEB-ITnose

border-width实现回复效果_html/css_WEB-ITnose

Jun 24, 2016 am 11:37 AM

一、发现

前端渣哥逛博客园,经常看到博文评论有这种如下这种效果:

开始还以为是用图片实现的,额...。像博客园这种访问量大的网站,能用js/css实现的就不会用图片代替,果然,仔细一看,两个span就能实现这个效果了。

二、实现

看到不会或者不清楚的,总想探个究竟,并把知识变成自己的。接下来就花点时间,实现这种效果。

2.1 以span 设置 border-width:20px; 为例,这样相当于一个 40*40 的正方形(上下(20*2)和左右(20*2)),然后平分成4份,怎么平分呢,上下左右4个全等三角型就是了。既然这样,我们就可以轻松实现以下效果了:

       

2.2 有了上面的做法,我们同样可以再用一个span,实现如下效果:

这样,把浅蓝色部分换成白色,就可以实现遮挡,再通过绝对定位,就可以实现我们想要的效果了。

2.3 完整代码

<!DOCTYPE><html><head>           <title>css实现博客园回复效果</title>    <style type="text/css">        *{margin:0;padding:0;}        #reply{        	width:600px;        	margin:0 auto;        }        .reply_item{        	padding:10px 20px;        	border-bottom:1px solid #EDD98B;        }        .reply_img{        	float:left;                }        .reply_img a{        	float:left;        	margin-top:20px;        	text-decoration:none;        	color:#fff;        }         .reply_img img{        	width:60px;        	height:60px;        	border-radius:40px;        }                       .reply_content{        	margin-left:110px;        	background:#beceeb;        	padding:30px 20px;        	border-radius:18px;        	position:relative;        }        .dot{        	border-style:solid;        	border-width:20px;        	border-color:#fff #beceeb #beceeb #fff;        	position:absolute;        	left:-40px;        	top:40px;        }        .top{        	border-style:solid;        	border-width:10px 20px;        	border-color:transparent #fff #fff transparent;        	position:absolute;        	left:-40px;        	top:60px;        }    </style></head><body>    <div id="reply">        <div class="reply_item">            <div class="reply_img">                <a href="http://www.cnblogs.com">                    <img src="/static/imghw/default1.png"  data-src="1.jpg"  class="lazy" alt="用户头像" />                </a>            </div>            <div class="reply_content">                好文,要攒                <div class="dot"></div>                <div class="top"></div>            </div>        </div>    </div></body></html>
Copy after login

2.4 效果图:

三、总结

一个简单的demo,以此小记。代码不自己敲就不是你的,有空逛逛园子总会有收获。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles