HTML中如何设置类

发布时间:2022-03-10 11:33:36 作者:小新
来源:亿速云 阅读:464

小编给大家分享一下HTML中如何设置类,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

对 HTML 进行分类(设置类),使我们能够为元素的类定义 CSS 样式。

为相同的类设置相同的样式,或者为不同的类设置不同的样式。

实例

<!DOCTYPE html>

<html>

<head>

<style>

.cities {

    background-color:black;

    color:white;

    margin:20px;

    padding:20px;

</style>

</head>

<body>

<div class="cities">

<h3>London</h3>

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

</div> 

</body>

</html>

分类块级元素

HTML <div> 元素是块级元素。它能够用作其他 HTML 元素的容器。

设置 <div> 元素的类,使我们能够为相同的 <div> 元素设置相同的类:

实例

<!DOCTYPE html>

<html>

<head>

<style>

.cities {

    background-color:black;

    color:white;

    margin:20px;

    padding:20px;

</style>

</head>

<body>

<div class="cities">

<h3>London</h3>

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

</div>

<div class="cities">

<h3>Paris</h3>

<p>Paris is the capital and most populous city of France.</p>

</div>

<div class="cities">

<h3>Tokyo</h3>

<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,

and the most populous metropolitan area in the world.</p>

</div>

</body>

</html>

分类行内元素

HTML <span> 元素是行内元素,能够用作文本的容器。

设置 <span> 元素的类,能够为相同的 <span> 元素设置相同的样式。

实例

<!DOCTYPE html>

<html>

<head>

<style>

  span.red {color:red;}

</style>

</head>

<body>

<h2>My <span class="red">Important</span> Heading</h2>

</body>

</html>

以上是“HTML中如何设置类”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. html中居中如何设置
  2. html中图片居中怎么设置

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

html

上一篇:HTML布局的示例分析

下一篇:实用的HTML特效代码有哪些

相关阅读

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

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