Table of Contents
CSS solution for inserting content around text
Common design draft requirements
ethical knowledge
Practical operation
Line
css
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.
##Extended knowledge
Home Web Front-end HTML Tutorial Insert content around text using CSS

Insert content around text using CSS

Jul 18, 2017 pm 05:23 PM
css content

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

Insert content around text using CSS
Insert content around text using CSS

##html
<div class="article-block-title">
    <h2 class="title">
        <span>前端技术</span><i>前端技术前端技术</i>
    </h2>
</div>
Copy after login
css
.article-block-title {
    height: 44px;
    /*实现文本与竖线对齐*/
    line-height: 44px;
    border-left: 3px solid #72b16a;
    padding-left: 20px;
}
Copy after login
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.

Insert content around text using CSS##html

<p class="text-info">
    <i class="line line-left"></i>resto restaurant home page website template<i class="line line-right"></i>
</p>
Copy after login
css
.text-info .line {
    display: inline-block;
    width: 40px;
    border-top: 1px solid #fff;
    /*使横线居中*/
    vertical-align: middle;
    /*for IE7*/
    *margin-top: 22px;
}
Copy after login
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.
    • This attribute is invalid in ie7
    • can be implemented using margin-top (prerequisite is to know the parent-element height
html

<div class="menu-tips">The menu</div>
Copy after login

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;
}
Copy after login
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

##html

<div class="btn-group">
    <a href="" class="btn"></a>
    <a href="" class="btn active"></a>
    <a href="" class="btn"></a>
    <a href="" class="btn"></a>
</div>
Copy after login
Insert content around text using CSScss
.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'类 */
}
Copy after login
Analysis
  • border-radius cannot be used below IE8 and needs to be forced

  • ##Trick1: Replace with image background.

    • ##Trick2: Call the script ie-css3.htc to make IE browser support css3 attributes
    • ##The current element. There must be positioning attributes, such as position:relative or position:absolute attributes.

    The z-index value must be higher than the surrounding elements
  1. ##.

    #Custom icon
  2. ##html
  3. <div class="star-bar">
        <span class="star"></span>
        <span class="star"></span>
        <span class="star"></span>
        <span class="star"></span>
        <span class="star nostar"></span>
    </div>
    Copy after login
css
.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;
}
Copy after login

Analysis

Insert content around text using CSS

Here are some methods for scoring and other requirements, using the background attribute to display pictures
##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!

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)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

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.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

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.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

See all articles