1.6_HTML基础属性
name 属性
name 属性用于指定标签元素的名称。 标签内必须提供 href 或 name 属性。
id 属性
- id 属性规定 HTML 元素的唯一的 id。
- id 在 HTML 文档中必须是唯一的。
- id 属性可通过 JavaScript(HTML DOM)或通过 CSS 为带有指定 id 的元素改变或添加样式。
示例:
<html> <head> <script type="text/javascript"> function change_header() { document.getElementById("myHeader2").innerHTML="蜉蝣掘阅点击了按钮"; } script> head> <body> <h1 id="myHeader1">你好,蜉蝣掘阅h1> <h1 id="myHeader2">你好,蜉蝣掘阅h1> <button onclick="change_header()">点击确认button> body> html>
style 属性
样式是 HTML 4 引入的,它是一种新的首选的改变 HTML 元素样式的方式。通过 HTML 样式,能够通过使用 style 属性直接将样式添加到 HTML 元素,或者间接地在独立的样式表中(CSS 文件)进行定义。
HTML 样式实例 - 背景颜色
background-color 属性为元素定义了背景颜色:
"This is a heading
"This is a paragraph.
HTML 样式实例 - 字体、颜色和尺寸
font-family、color 以及 font-size 属性分别定义元素中文本的字体系列、颜色和字体尺寸:
A heading
A paragraph.
HTML 样式实例 - 文本对齐
text-align 属性规定了元素中文本的水平对齐方式:
This is a heading
The heading above is aligned to the center of this page.
更多HTML属性请见
http://www.w3school.com.cn/tags/html_ref_standardattributes.asp
示例:
<html> <hand> <title>我要自学网title> hand> <body style="background-color:#C1FFC1"> <img src="D:\学习\selenium自动化测试\课程素材\sc1\代码\Logo.png" width=200 high="100"> <h1>自学网口号h1> <h2>自学网口号h2> <p style="font-family:隶书;color:red;font-size:30;text-align:center">自学成才,<br/>快速成功p> <p>增加收入,改变命运p> <p>这是一个神奇的网站,你值得拥有p> <a href="http://www.baidu.com">百度一下a> <div style="background-color:yellow;height:200;width:200"> <p>这是一个div区域,分区,节p> <a href="http://www.w3school.com.cn/tags/index.asp">更多标签a> <a href="http://www.w3school.com.cn/tags/html_ref_standardattributes.asp">更多属性a> div> body> html>