CSS to achieve horizontal lines on both sides of the middle text

CSS to achieve horizontal lines on both sides of the middle text

1. The vertical-align property achieves the following effect:

The vertical-align property sets the vertical alignment of an element.

This property defines the vertical alignment of an inline element's baseline relative to the baseline of the line in which the element resides. Negative length values ​​and percentage values ​​are allowed.

<div class="header">
    <span class="line"></span>
    <span class="text">Text in the middle, horizontal lines on both sides</span>
    <span class="line"></span>
</div>

<style>
.header
{
    width:400px;
    height:36px;
    line-height:36px;
    border:1px solid green;
    text-align:center;
}
.line
{
    display:inline-block;
    width:100px;
    border-top:1px solid #cccccc;
    vertical-align:5px;  
  // I saw online that .text is set to vertical-align:-5px. I tried it and it seems to conflict with the line-height set for .header, so the effect is not quite right. So set vertical-align to .line}
</style> 

2. CSS pseudo-class implementation effect:

<div class="header">
    <div>Text in the middle, horizontal lines on both sides</div>
</div>

<style>
    .header
    {
        width:400px;
        height:36px;
        line-height: 36px;
        text-align:center;
        border:1px solid green;
        position:relative;
    }
    .header div:before, .header div:after
    {
        position:absolute;
        background:#ccc;
        content:"";
        height:1px;
        top:50%;
        width:100px;
    }
    .header div:before{left:10px;}
    .header div:after{right:10px;}
</style> 

Summarize

The above is the CSS that I introduced to you to achieve the horizontal line effect on both sides of the middle text. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Vue template configuration and webstorm code format specification settings

>>:  Detailed tutorial on installing pxc cluster with docker

Recommend

A brief discussion on the implementation principle of Webpack4 plugins

Table of contents Preface know Practice makes per...

CocosCreator Skeleton Animation Dragon Bones

CocosCreator version 2.3.4 Dragon bone animation ...

Vue implements sample code to disable browser from remembering password function

Find information Some methods found on the Intern...

uniapp realizes the recording upload function

Table of contents uni-app Introduction HTML part ...

Detailed explanation of the use of various MySQL indexes

1. Slow query log 1.1 MySQL log types Logs are us...

How to avoid duplication of data when inserting in MySql batch

Table of contents Preface 1. insert ignore into 2...

Summary of various methods for Vue to achieve dynamic styles

Table of contents 1. Ternary operator judgment 2....

Comprehensive summary of Vue3.0's various listening methods

Table of contents Listener 1.watchEffect 2.watch ...

How to redirect URL using nginx rewrite

I often need to change nginx configuration at wor...

jQuery custom magnifying glass effect

This article example shares the specific code of ...

MySQL obtains the current date and time function example detailed explanation

Get the current date + time (date + time) functio...