How to select the p element under div in css

WBOY
Release: 2021-12-07 16:23:58
Original
7591 people have browsed it

In CSS, you can use the ":nth-child(n)" selector to select the p element under the div. The function of this selector is to select the nth child element under the parent element. The syntax is "div p:nth-child(n){css style code;}".

How to select the p element under div in css

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

How to select the p element under div in css

In css, you can use the :nth-child() selector to Select the p element under the div.

:nth-child(n) selector matches the Nth child element that belongs to its parent element, regardless of the element's type.

n can be a number, keyword or formula.

The example is as follows:

<html>
<head>
<style> 
div p:nth-child(2)
{
background:#ff0000;
}
</style>
</head>
<body>
<div>
<p>第一个段落。</p>
<p>第二个段落。</p>
<p>第三个段落。</p>
<p>第四个段落。</p>
</div>
</body>
</html>
Copy after login

Output result:

How to select the p element under div in css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to select the p element under div in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template