我是靠谱客的博主 危机项链,这篇文章主要介绍html内联样式(表),外部样式表,现在分享给大家,希望可以做个参考。

内联样式:直接在元素开始标签中定义style

复制代码
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html> <html> <body style="background-color:PowderBlue;"> <h1>Look! Styles and colors</h1> <p style="font-family:verdana;color:red">This text is in Verdana and red</p> <p style="font-family:times;color:green">This text is in Times and green</p> <p style="font-size:30px">This text is 30 pixels high</p> </body> </html>

在这里插入图片描述

内部样式表:在head标签中统一定义style,这样可以同时定义多个标签里面的相同属性。当和内联样式同时使用时优先使用内联样式,如下的第三个p的颜色显示为黑色。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html> <html> <head> <title>This is title</title> <style> body { background-color:PowderBlue; } p { color:red } </style> </head> <body> <h1>Look! Styles and colors</h1> <p style="font-family:verdana">This text is in Verdana and red</p> <p style="font-family:times">This text is in Times and green</p> <p style="font-size:30px;color:black">This text is 30 pixels high</p> </body> </html>

在这里插入图片描述

外部样式表:将样式表提到css文件中,多个html文件可以同时引用此css样式。

CSS文件内容(文件名style.css)

复制代码
1
2
3
4
5
6
7
body { background-color:PowderBlue; } p { color:red }

html如何引用CSS

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html> <html> <head> <title>This is title</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Look! Styles and colors</h1> <p style="font-family:verdana">This text is in Verdana and red</p> <p style="font-family:times">This text is in Times and green</p> <p style="font-size:30px;color:black">This text is 30 pixels high</p> </body> </html>

最后

以上就是危机项链最近收集整理的关于html内联样式(表),外部样式表的全部内容,更多相关html内联样式(表)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部