课程表

HTML 基础教程

HTML XHTML

HTML 表单

HTML5

HTML 图形

HTML 媒体

HTML API

实例/总结

HTML 速查手册

工具箱
速查手册

HTML 类

当前位置:免费教程 » HTML/CSS » HTML

对 HTML 进行分类(设置类),使我们能够为元素的类定义 CSS 样式。

为相同的类设置相同的样式,或者为不同的类设置不同的样式。

实例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. .cities {
  6. background-color:black;
  7. color:white;
  8. margin:20px;
  9. padding:20px;
  10. }
  11. </style>
  12. </head>
  13.  
  14. <body>
  15.  
  16. <div class="cities">
  17. <h2>London</h2>
  18. <p>
  19. London is the capital city of England.
  20. It is the most populous city in the United Kingdom,
  21. with a metropolitan area of over 13 million inhabitants.
  22. </p>
  23. </div>
  24.  
  25. </body>
  26. </html>

亲自试一试

分类块级元素

HTML <div> 元素是块级元素。它能够用作其他 HTML 元素的容器。

设置 <div> 元素的类,使我们能够为相同的 <div> 元素设置相同的类:

实例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. .cities {
  6. background-color:black;
  7. color:white;
  8. margin:20px;
  9. padding:20px;
  10. }
  11. </style>
  12. </head>
  13.  
  14. <body>
  15.  
  16. <div class="cities">
  17. <h2>London</h2>
  18. <p>London is the capital city of England.
  19. It is the most populous city in the United Kingdom,
  20. with a metropolitan area of over 13 million inhabitants.</p>
  21. </div>
  22.  
  23. <div class="cities">
  24. <h2>Paris</h2>
  25. <p>Paris is the capital and most populous city of France.</p>
  26. </div>
  27.  
  28. <div class="cities">
  29. <h2>Tokyo</h2>
  30. <p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
  31. and the most populous metropolitan area in the world.</p>
  32. </div>
  33.  
  34. </body>
  35. </html>

亲自试一试

分类行内元素

HTML <span> 元素是行内元素,能够用作文本的容器。

设置 <span> 元素的类,能够为相同的 <span> 元素设置相同的样式。

实例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. span.red {color:red;}
  6. </style>
  7. </head>
  8. <body>
  9.  
  10. <h1>My <span class="red">Important</span> Heading</h1>
  11.  
  12. </body>
  13. </html>

亲自试一试

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号