CSS solution for inserting content around text
This article will discuss how to insert icons around text, how to control the positional relationship between them, through the rationality of HTML structure and the use of CSS attributes To compare the advantages and disadvantages of the effects achieved by different solutions.
Common design draft requirements
Insert icons, lines, triangles, circles before, after, above and below the text
The inserted elements must achieve spacing, alignment (center, top, baseline) and other positional relationships with the text.
ethical knowledge
Flexibly use display, background and other attributes
Pass
:before
and:after
cooperate with the content attribute to insert content.Realize the positional relationship between text and symbols through absolute, vertical, margin, line-height and other attributes.
Graphics that can be drawn using CSS properties use CSS properties, otherwise use the background property to display the background image
Practical operation
Solution 1: Change the HTML structure by adding tags before or after text elements such as
<span></span>
and<i></i>
Solution 2: Directly use pseudo-elements: before and :after (not supported below Ie7)
Must have content attribute
The inserted element is an inline element, which needs to be explicitly defined as a block-level element before the height can be set , padding, margins, etc
Line
<div>
<h2>
<span>前端技术</span><i>前端技术前端技术</i>
</h2>
</div>
css.article-block-title {
height: 44px;
/*实现文本与竖线对齐*/
line-height: 44px;
border-left: 3px solid #72b16a;
padding-left: 20px;
}
Analysis
- Directly use the container of the text to use border-left, border-right, border-top, and border-bottom to display only the text. Lines up, down, left, and right.
- For inline, inline-block, etc., you can use line-height to center the text and vertical lines.
##html
<p> <i></i>resto restaurant home page website template<i></i> </p>
css
.text-info .line { display: inline-block; width: 40px; border-top: 1px solid #fff; /*使横线居中*/ vertical-align: middle; /*for IE7*/ *margin-top: 22px; }
Analysis
- Adding
- i
and
span
tags before and after the text is clearer than using pseudo-elements: before and :after. vertical-align:middle achieves vertical centering of lines and text. - can be implemented using margin-top (prerequisite is to know the parent-element height
- This attribute is invalid in ie7
<div>The menu</div>
css
.menu-tips:after { position: absolute; left: 0; bottom: 0; content: ""; width: 0; height: 0; /*menu是156px宽,所以这里设置78px*/ border-left: 78px solid transparent; border-right: 78px solid transparent; border-bottom: 10px solid #fff; }
Analysis
- Passed The transparent attribute works with the border to implement the triangle.
- Note that we can use the position attribute to insert :before and :after at any position, not just "before" or "after". The line on the right can be placed directly below the text "Become our volunteer"
- ##circle
<div> <a></a> <a></a> <a></a> <a></a> </div>

.index-panel-header .btn-group { float: right; /*清除行内元素的4px空白间距*/ font-size: 0; } .index-panel-header .btn { display: inline-block; margin-left: 11px; width: 9px; height: 9px; background: #dedede; /*画圆*/ -moz-border-radius: 5px; /* Firefox */ -webkit-border-radius: 5px; /* Safari 和 Chrome */ border-radius:5px; /* Opera 10.5+, 以及使用了IE-CSS3的IE浏览器 */ /*for ie7、8*/ position: relative; z-index:2; behavior: url(../ie-css3.htc); /* 通知IE浏览器调用脚本作用于'btn'类 */ }
Analysis
Here is how to do the banner carousel diagram and other requirements, because it is a continuous button, as long as the border-radius is used The attribute draws a circle.
border-radius cannot be used below IE8 and needs to be forced
##Trick1: Replace with image background.
- ##The current element. There must be positioning attributes, such as position:relative or position:absolute attributes.
- ##Trick2: Call the script ie-css3.htc to make IE browser support css3 attributes
- ##. #Custom icon
- ##html
<div> <span></span> <span></span> <span></span> <span></span> <span></span> </div>
.star-bar { font-size: 0px; } .star { display: inline-block; width: 10px; height: 10px; margin-right: 5px; background: url("../images/index-star.png") no-repeat; } .nostar { background-position: 0 -10px; }
Analysis
##Extended knowledge
- About how to center. Element, here is a cheat tool: How to center an element
- Summary
- If there are multiple icon symbols in a row, use HTML tags to represent them.
- If you are inserting a single symbol, use pseudo-element > to add additional HTML tags without considering compatibility.
The above is the detailed content of Insert content around text using CSS. For more information, please follow other related articles on the PHP Chinese website!

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
