如何在 HTML 中使用内部 CSS(样式表)?


层叠样式表用于设置网页的显示格式。

CSS 用于设置和布局网页,使用它可以控制网页的显示格式、更改内容的字体、颜色、大小和间距、将其拆分为多列,或添加动画和其他 CSS 属性中可用的装饰性特征。

内部 CSS

内部 CSS 用于在单个 HTML 页面中定义样式标签。它定义在 HTML 页面 <head> 标记内,在 <style> 标记元素内。

示例

以下示例程序在 HTML 中使用内部 CSS 进行样式设置。

<!DOCTYPE html> <html> <head> <style> body {background-color:tan;} h1 {color: whitesmoke; font-family: cursive} p {color:whitesmoke; background-color: dimgrey; font-family: monospace} </style> </head> <body> <h1>HTML-HyperText Markup Language </h1> <p>The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser.</p> </body> </html>

示例

以下示例程序在 HTML 中使用内部 CSS 为 <ol> 元素设置样式。

<!DOCTYPE html> <html> <head> <style> ol.a { list-style-type: upper-roman; } </style> </head> <body> <h2>List</h2> <ol class = "a" > <li>GOT</li> <li>HOTD</li> <li>HBO</li> </ol> </body> </html>

示例

以下示例程序在 HTML 中使用内部 CSS 为 <table>元素设置样式。

<!DOCTYPE html> <html> <head> <title>Inline CSS</title> <style> table, th, td { border: 3px solid; } </style> </head> <body> <table> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>SS</td> <td>Rajamouli</td> </tr> <tr> <td>Prashant</td> <td>Neel</td> </tr> </table> </body> </html>

更新于:2022 年 11 月 11 日

4K+ 次浏览

开启 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.