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

Python MySQL database table modification and query

Python connects to MySQL to modify and query data...

Vue implements graphic verification code

This article example shares the specific code of ...

The whole process of developing a Google plug-in with vue+element

Simple function: Click the plug-in icon in the up...

8 powerful techniques for HTML web page creation

<br />Although there are many web page creat...

Solution to MySQLSyntaxErrorException when connecting to MySQL using bitronix

Solution to MySQLSyntaxErrorException when connec...

Basic ideas for finding errors in Web front-end development

WEB development mainly consists of two interactio...

JavaScript implements countdown on front-end web page

Use native JavaScript to simply implement the cou...

Docker link realizes container interconnection

Table of contents 1.1. Network access between con...

A quick guide to Docker

Docker provides a way to automatically deploy sof...

JavaScript Closures Explained

Table of contents 1. What is a closure? 1.2 Memoi...