Home >Web Front-end >CSS Tutorial >How to add padding to the beginning and end of each line of text within a span element with a background color?

How to add padding to the beginning and end of each line of text within a span element with a background color?

Linda Hamilton
Linda HamiltonOriginal
2024-11-07 08:56:02265browse

How to add padding to the beginning and end of each line of text within a span element with a background color?

Padding Text Lines

Question:

How do you add padding to the beginning and end of each line of text within a span element that has a background color?

Answer:

CSS Solution:

This solution requires using inline blocks and careful positioning:

div { 
    line-height: 1.1; 
    padding: 1px 0;
    border-left: 30px solid #000; 
    display: inline-block; 
}
h3 { 
    background-color: #000; 
    color: #fff; 
    display: inline; 
    margin: 0; 
    padding: 0
} 
h3 .indent { 
    position: relative; 
    left: -15px;
}
h3 .subhead {
    padding: 0 15px;
    float: left;
    margin: 3px 0 0 -29px;
    outline: 1px solid #00a3d0;
    line-height: 1.15
}

HTML Markup:

<div>

The above is the detailed content of How to add padding to the beginning and end of each line of text within a span element with a background color?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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