


<div id="d1" style="background: red; width: 90px; height: 90px"> <span>span1</span> <span>span2</span> <span>span3</span> <b>b1</b> <div>div1</div> <span>spanN</span></div>
How to set the style of the Nth element in d1 in css code?
I seem to have seen it on w3cschool, I thought I could remember it...
#d1 > span{ display: block;}
This is the display of all spans under d1 are block.
At first I thought firstchild seemed to be able to meet this need...
Please help!
Oh... don’t use javascript, no dedicated class, N is a variable, they are all clean nodes.
Reply to discussion (solution)
How to know which is the Nth element without using js? HTML and CSS are both static things. If you choose the first or last one, you can still do it with CSS. You are the Nth~~~
If you use js, you can use the following sentence,
document.getElementById("d1").getElementsByTagName("*")[N-1].style.display = "none";
But there is one thing, if the number of your elements is so There are many, so for the sake of safety, you can disassemble the above and make a judgment. Also, if these elements are dynamically generated, you must make sure that the elements are generated before calling this sentence, otherwise an error will occur.
The ability is limited and cannot meet your requirements. It is for reference only.
How to know which is the Nth element without using js? HTML and CSS are both static things. If you choose the first or last one, you can still do it with CSS. You are the Nth~~~
If you use js, you can use the following sentence,
document.getElementById("d1").getElementsByTagName("*")[N-1].style.display = "none";
But there is one thing, if the number of your elements is so There are many, so just to be on the safe side...
css can even be hung with Trojans.
Quote from 1st floor’s reply:
How to know which is the Nth element without using js? HTML and CSS are both static things. If you choose the first or last one, you can still do it with CSS. You are the Nth~~~
If you use js, you can use the following sentence,
document.getElementById("d1").getElementsByTagName("*")[N-1].style.display = "none";
But there is one thing, if you have these elements...
If CSS can do it, why do we need js?

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),