温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HTML标签style属性怎么用

发布时间:2020-10-26 09:01:18 来源:亿速云 阅读:167 作者:小新 栏目:web开发

小编给大家分享一下HTML标签style属性怎么用 ,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

首先我们介绍下HTML标签style属性的定义吧:

style 属性是规定元素的行内样式(inline style)

style 属性将覆盖任何全局的样式设定,例如在 <style> 标签或在外部样式表中规定的样式。

HTML style 属性实例

在 HTML 文档中使用 style 属性:

<h2 style="color:blue; text-align:center">This is a header</h2>
<p style="color:red">This is a paragraph.</p>

HTML标签style属性的语法:

<element style="value">

HTML标签style属性的属性值:

style_definition   : 一个或多个由分号分隔的 CSS 属性和值。

HTML中的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>
<h4 style="color:blue;font-size=20px">Hello World!</h4>
<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>
<h4 style="color:blue;font-size=20px ;background-color:yellow">Hello World!</h4>
<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>
<h4 style="color:blue;font-size=20px ;background-color:yellow;text-align:center">Hello World!</h4>
<p style="color:red;font-size=10px ;background-color:green;text-align:right">你好!!!!</p>
</body>
</html>

关于html的style属性的两种具体用法实例:

<!DOCTYPE html>
<html>
     <head>
        <meta charset="utf-8">
        <title>练习使用HTML</title>
        <style>
            /*标签选择器*/
            h5 {
                color: blue;
                text-align: right;
            }
</style>
    </head>
     <body>
        <!--规定元素的行内样式-->
        <p style="color:red;text-align:center">测试html的style属性</p>
        <h5>h51</h5>
        <h5>h52</h5>
    </body>
 </html>

以上是HTML标签style属性怎么用 的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI