CSS CSS Basics Basic Selectors ID Selectors

Can I create an ID within a Div element that has an ID?

What would happen if I created an ID within a div element that has an ID?

For example

<div id = primary-content> <h1>Heading<h/1> <p id = paragraph-one>Paragraph</p> </div>

Will any issues arise from creating the paragraph ID within the div element that has an ID?

Thanks in advance!

2 Answers

rabin
seal-mask
.a{fill-rule:evenodd;}techdegree
rabin
Front End Web Development Techdegree Student 15,903 Points

Hey Kane,

Yes, you can create an ID within a Div element that has an ID.

ID's are unique, therefore, each element can have only one ID and each page can have only one element with that ID.

<div id = primary-content> 
<h1>Heading</h1> 
<p id = paragraph-one>Paragraph</p> 
</div>

The example you provided, there will be no issues. You can style the paragraph by selecting #paragraph-one. But classes would be the better option as they are not unique and you can use the same class on multiple elements.

Muhammad Khan
PLUS
Muhammad Khan
Courses Plus Student 2,398 Points

Hi Kane, Yes, you can create another id in your div element but the name of the id should be different, that is each element must have unique id name.