


How can I add padding to the edges of multi-line text using CSS and HTML?
Add Padding to the Edges of Multi-Line Text Using CSS and HTML
In order to achieve this effect without using non-breaking space tags, we can utilize a combination of CSS and HTML. Here's how:
CSS:
#titleContainer { width: 520px; } h3 { margin:0; font-size: 42px; font-weight: bold; font-family: sans-serif; } h3 .heading { background-color: #000; color: #00a3d0; } h3 .subhead { background-color: #00a3d0; color: #000; } 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:
<div>
Penjelasan:
- We wrap the text in a <div> with an id of "titleContainer" to contain the entire text.
- We wrap the text in an
tag and define styles for the entire
as well as for the nested elements with classes of "heading" and "subhead".
- To create the line separation, we create another <div> within the
and style it with line-height, padding, border-left, and display. This separates the lines while maintaining their alignment.
- We wrap the text in a with the class "indent" and use position: relative and left: -15px to shift the text to the left, creating the desired padding at the beginning of the line.
- The subtext with the class "subhead" is floated left and positioned using margins to ensure proper alignment.
- Internet Explorer (IE) requires an additional style to correct the margin of the subhead text, which is included within conditional comments.
This CSS and HTML solution provides a flexible and cross-browser compatible way to add padding to the beginning and end of each line of text, as demonstrated in the screenshot from Chrome provided earlier.
The above is the detailed content of How can I add padding to the edges of multi-line text using CSS and HTML?. For more information, please follow other related articles on the PHP Chinese website!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

Buy or build is a classic debate in technology. Building things yourself might feel less expensive because there is no line item on your credit card bill, but

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's
