Jump to content

Unique element selector no id?

stefanmz
Go to solution Solved by Chris Pratt,

You can use the child combinator (`body > header`) or psuedo-classes like `header:first-of-type` or `header:nth-of-type(1)`.

Hello,so is there a way in  CSS to select without id class name only pseudo-class selectors a unique element for example body header selects only the header of the body the whole page without any headers after that?

I need that for a homework because we are not allowed to change the html and there is no id class name or whatever.

body header{font-weight:bold} 

and not other headers in the body are bold only this one.How?

<body>
	<header>(this one)
    <nav>
    	<header>.....

 

Link to comment
Share on other sites

Link to post
Share on other sites

You can use the child combinator (`body > header`) or psuedo-classes like `header:first-of-type` or `header:nth-of-type(1)`.

CPU: AMD Ryzen 9 5900X · Cooler: Artic Liquid Freezer II 280 · Motherboard: MSI MEG X570 Unify · RAM: G.skill Ripjaws V 2x16GB 3600MHz CL16 (2Rx8) · Graphics Card: ASUS GeForce RTX 3060 Ti TUF Gaming · Boot Drive: 500GB WD Black SN750 M.2 NVMe SSD · Game Drive: 2TB Crucial MX500 SATA SSD · PSU: Corsair White RM850x 850W 80+ Gold · Case: Corsair 4000D Airflow · Monitor: MSI Optix MAG342CQR 34” UWQHD 3440x1440 144Hz · Keyboard: Corsair K100 RGB Optical-Mechanical Gaming Keyboard (OPX Switch) · Mouse: Corsair Ironclaw RGB Wireless Gaming Mouse

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Chris Pratt said:

You can use the child combinator (`body > header`) or psuedo-classes like `header:first-of-type` or `header:nth-of-type(1)`.

Thanks! That worked!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×