Home  >  Article  >  Web Front-end  >  How to change the color of the first letter in css3

How to change the color of the first letter in css3

青灯夜游
青灯夜游Original
2022-04-25 16:08:004383browse

In CSS3, you can use the ":first-letter" selector and color attribute to modify the color of the first letter. The syntax is "element:first-letter{color:color value;}"; ":first-letter" The first letter of the element can be selected, and color can set the text color for the selected letter.

How to change the color of the first letter in css3

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

css3 Modify the initial letter color

Implementation idea:

  • Use ": The first-letter" selector selects the first letter of the element

  • Use the color attribute to modify the text color of the selected letter.

    TheColor property can specify the color of the text.

Implementation code:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style type="text/css">
			.first {
				width: 200px;
				height: 100px;
				border: 1px solid red;
			}

			.first p::first-letter {
				color: red;
			}
		</style>
	</head>
	<body>
		<div class="first">
			<p>aksadjklahkljasklf</p>
		</div>

	</body>

How to change the color of the first letter in css3

Extended knowledge:

:The first-letter selector can use the following attributes:

  • font

  • ##color

  • background

  • margin

  • padding

  • border

  • text-decoration

  • vertical-align (only if float is 'none')

  • text-transform

  • line-height

  • float

  • clear

(Learn Video sharing:

css video tutorial, web front-end)

The above is the detailed content of How to change the color of the first letter in css3. 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