How to Select by ID in CSS
Zenva
ACCESS the FULL COURSE here: https://academy.zenva.com/product/bite-sized-coding-academy/
TRANSCRIPT
In this lesson we'll talk about IDs, and how we can use IDs to select single elements in our HTML page. Let me give you an example. I wanna select just this paragraph here. If I go and type in p, that will select all the paragraphs in the page, but I just wanna select this one. So there are different ways to do it in CSS but I'm gonna illustrate this, the concept of ID, for this particular example. We can give this paragraph a unique ID. For that, we need to add the attribute id="", and in here we enter the name, the unique ID of that particular element, it's a unique identifier. It cannot contain spaces. You can say something like "main paragraph", something like that, so instead of selecting all the paragraphs like that, we can select by ID. For which we need to type in the hash sign, and then the name of the ID, and that will allow us to select a single element by ID. You can have multiple elements in your page that have different IDs, but, IDs need to be unique. You can't have two elements that have the same value for ID, they all need to be different. And it needs to exactly match the name that you selected here, so now, you can select by tag, which will select all of the elements that have the tag, and now you can also select by unique ID.
Free Tutorials:
- Unity: https://gamedevacademy.org
- Phaser: https://phasertutorials.com
- Machine Learning: https://pythonmachinelearning.pro
- Web Dev: https://html5hive.org
- Android: https://androidkennel.org
- Swift: https://swiftludus.org
- VR: https://vrgamedevelopment.pro ... https://www.youtube.com/watch?v=EJynBQ3TnsQ
3711707 Bytes