- Mastering CSS
- Rich Finelli
- 152字
- 2021-07-08 09:45:53
IDs
Scroll up to the top of our site, and in our HTML, go to h1:

Let's give the first h1 tag a special ID called main-site-title:
<h1 id="main-site-title">Old Chompy</h1>
With an ID, you can also use whatever name you want inside the quotes as long as it's meaningful. Switch over to the CSS and scroll down to just underneath our alt-headline class. This is where we'll add main-site-title. The main difference between writing classes and IDs is we start classes with a period and IDs with a number sign or pound sign or a hashtag (whatever you want to call it):
#main-site-title
In this case, we'll then say the color is different: deep pink. Save this and refresh the site to see the effect:
#main-site-title{ color: deeppink; }
Following is the output of preceding code:

You can see that this changes just the Old Chompy h1, the one that has the ID.
推薦閱讀
- JavaScript前端開發模塊化教程
- Java程序設計實戰教程
- Oracle 12c中文版數據庫管理、應用與開發實踐教程 (清華電腦學堂)
- Practical Windows Forensics
- Visual C++應用開發
- NetBeans IDE 8 Cookbook
- Learning PHP 7
- Programming with CodeIgniterMVC
- Hands-On JavaScript for Python Developers
- Apache Camel Developer's Cookbook
- Implementing Microsoft Dynamics NAV(Third Edition)
- Python面試通關寶典
- Android初級應用開發
- IBM DB2 9.7 Advanced Application Developer Cookbook
- Learning Swift