学习HTML(八)style属性相关样式

前几篇文章中,不论是添加列表,还是添加标题或者段落,其中的字体,包括大小、颜色等属性都是没有设置的。
为了提高文本的可读性,使文本看起来五光十色、色彩缤纷。可以设置文本的style属性。
1)style属性可以设置字体样式(font-family:***)、字体大小(font-size:***)、文本的颜色(color:***)等内容。它可以在
每个不同的标签中设置,也可以放置到CSS样式表中进行设置。因为我的文章都是跟随着 http://www.codecademy.com
写的,目前还没有介绍到CSS,所以在这里暂时先不涉及CSS,仅仅是在标签中进行设置,下面是示例代码和示意图:
<!DOCTYPE html>
<html>
<head>
<title>color the text</title>
</head>
<!-- now i will color the text-->
<body>
<h3 style="color:blue;font-size=20px">Hello World!</h3>
<p style="color:red;font-size=10px">你好!!!!</p>
</body>
</html>
 
  注意:
a)我用的浏览器是chrome,在其中编辑并显示时总是发现设置的10px字体没有应用,通过查找chrome设置,发现
是在chrome中设置的最小字体是12px,所以10px字体大小没有用,把chrome浏览器的最小字体改小就好了。
b)style属性中的赋值方式是:属性名称:值,而不是习惯的等号=,如果用等号,则style效果不会被执行。
 
2)style样式中也可以设置背景颜色,style中包含属性background-color,设置它的颜色值就可以使整个标签范围内的背景颜色变
为background-color指定的颜色。下面是示例代码和示意图:
<!DOCTYPE html>
<html>
<head>
<title>color the text</title>
</head>
<!-- now i will color the text-->
<body>
<h3 style="color:blue;font-size=20px ;background-color:yellow">Hello World!</h3>
<p style="color:red;font-size=10px ;background-color:green">你好!!!!</p>
</body>
</html>
 
3)文本对齐
有些标签属性中有align属性,可以设置文本对齐方式,在style中也可以设置类似的属性。这个属性值就是text-align。它的
取值包括left、center和right。下面是示例代码和示意图:
<!DOCTYPE html>
<html>
<head>
<title>color the text</title>
</head>
<!-- now i will color the text-->
<body>
<h3 style="color:blue;font-size=20px ;background-color:yellow;text-align:center">Hello World!</h3>
<p style="color:red;font-size=10px ;background-color:green;text-align:right">你好!!!!</p>
</body>
</html>
 
 
参考文献:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值