我是靠谱客的博主 危机项链,最近开发中收集的这篇文章主要介绍html内联样式(表),外部样式表,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

<!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的颜色显示为黑色。

<!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)

body {
	background-color:PowderBlue;
}
p {
	color:red
}

html如何引用CSS

<!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内联样式(表),外部样式表所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部