如何在 HTML 中使用内联 CSS(样式表)?
htmlweb developmentfront end technology更新于 2024/6/29 0:12:17
层叠样式表用于格式化网页的呈现方式。
CSS 用于设置网页的样式和布局 - 您可以使用 CSS 属性来控制网页的呈现方式,例如更改内容的字体、颜色、大小和间距,将其拆分为多列,或添加动画和其他可用的装饰功能。
内联 - 使用 HTML 元素内的 style 属性。
内联 CSS - 内联 CSS 用于将独特的样式应用于标签内使用的单个 HTML 元素。
示例
以下是示例程序,使用内联 CSS 在 HTML 中设置样式。
<!DOCTYPE html> <html> <head> <h1 style="font-family: fantasy">HTML</h1> </head> <body style="background-color: bisque"> <p style="background:yellow" >HTML is used to structure a web page and its content.</p> </body> </html>
示例
以下是示例程序,使用内联 CSS 为 <h1> 和 <h2> 元素设置样式。
<!DOCTYPE html> <html> <head> <h1 style="font-family: fantasy">HTML</h1> </head> <body style="background-color: seagreen"> <h2 style="background:whitesmoke" >HTML is used to structure a web page and its content.</h2> </body> </html>
示例
以下是示例程序,使用内联 CSS 为 <table> 元素设置样式。
<!DOCTYPE html> <html> <head> <title>Inline CSS</title> </head> <body> <table style = "border: 1px solid";> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>Peter</td> <td>Griffin</td> </tr> <tr> <td>Lois</td> <td>Griffin</td> </tr> </table> </body> </html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

