****HTML类
该功能的作用是:就好比一个模板,要让一些内容或者块表现出相同的内容,每次
设置他们的style属性太麻烦也不高效,而用HTML类就方便许多。
要在<head></head>中用上<style></style>标签,style 标签定义类(用大括号)
ex:
<head>
<style>
.cities{
background-color:black;
color:white;
margin:20px;
padding:20px;
}
</style>
</head>
这样在开头定义了一个类,使用时结合块:
ex:
<body>
<div class="cities">
内容1
</div>
<div class="cities">
内容2
</div>
$注意:在定义类时,类名前面有一点“.”
_______________________________________________________
******分类行内元素
设置 <span> 元素的类,能够为相同的 <span> 元素设置相同的样式。
<head>
<style>
span.red{color:red;}
</style>
</head>
$注意:采用span.类名的形式
使用:
<body>
<h1>My <span class="red">important</span>Heading</h1>
</body>
则将对important采用红色字体。
————————————————————
*****HTML布局(用html5布局和使用<div>元素的HTML布局)
header:定义文档或节的页眉
nav:定义导航链接的容器
section:定义文档中的节
footer:定义文档或者节的页脚
css:
<head>
<style>
header{
background-color:black;
color:white;
text-align:center:
padding:5px;
}
nav{
line-height:30px;
background-color:black;
height:300px;
width:100px;
float:left;
padding:5px;
}
section {
width:350px;
float:left;
padding:10px;
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body>
<header>
<h1>City Gallery</h1>
</header>
<nav>
London<br>
Paris<br>
Tokyo<br>
</nav>
<section>
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</section>
<footer>
Copyright W3Schools.com
</footer>
</body>
</html>
#使用<div>元素的HTML布局
CSS:
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
$注意:要有个“#”号
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="section">
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
Copyright W3School.com.cn
</div>
</body>
再用<div id="ID名”></div>来
$注意:不论是类名还是用HTML5布局还是使用<div>的HTML布局,<style>均要在<head></head>之内
即在<body>之外