如何在CSS类中使用标签 [英] How to use tags in classes with CSS

查看:108
本文介绍了如何在CSS类中使用标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,先生,

我在使用CSS的课程时遇到了问题我到目前为止在互联网上搜索但我找不到答案所以我在这里问,


我的外部CSS文件中有一个这样的课程



Good Morning Sir,
I am having a problem on using a classes in CSS I have so far searched in the internet but I could not find the answer so I am asking here,

I have a class in my external CSS file like this

.class
{
    h1
    {
        color:green;
    }
}





我已正确地将CSS链接到我的HTML5文件使用链接标签





I have correctly linked the CSS to my HTML5 file using a link tag

<link href="Venture.css" type="text/css" rel="stylesheet">





但是当我使用标题(h1)标签时,字体没有颜色(绿色)



我试过的:



我在互联网上搜索过。我是自学的,所以我不知道我错过了什么。



我搜索了大约20个网页,没有人给我这个答案,



- 很清楚,我们可以在一个外部css文件中创建许多类吗?在每个类中我们可以为不同的标签创建样式吗?





But when I use the heading (h1) tags the font has no color (green)

What I have tried:

I searched in the internet. I am self-learning this so I don't know what am I missing.

I have searched about 20 web pages none of them gave me this answer,

To make my-self clear, can we create many classes in one external css file and in each class can we create styles for different tags?

.class
{
    h1
    {
        color:green;
    }
}
.class1
{
    h1
    {
        color:blue;
    }
}





如果我使用类,那么如果我使用class1,将显示绿色标题应该显示蓝色标题我该怎么办?



请先帮我这个先生吧!



谢谢你的时间先生!



If I use class then green color heading will be displayed if I use class1 blue color heading should be displayed how can I do that?

Kindly help me with this sir!

Thank you for your time sir!

推荐答案

我认为你的意思是:

I think what you mean to do is the following:
h1.class
{
    color:green;
}

h1.class1
{
    color:blue;
}





或者你可以简单地做







Or you can simply do


.class
{
    color:green;
}

.class1
{
    color:blue;
}





这不会将你的css限制在h1元素。



Which does not limit your css here to just h1 elements.


在CSS中声明一个类是一回事 - 然后你需要让你的各种元素成为类的用户。你可以有很多类 - 除非你告诉它,否则元素如何知道要使用哪个类?你需要一个关于如何使用CSS类的好教程。



试试这个(为我工作): CSS教程 [ ^ ]

Declaring a class in CSS is one thing - you then need to make your various elements users of the class. You can have many classes - how does an element know which class or classes to use unless you tell it? You need a good tutorial on how CSS classes are used.

Try this one (worked for me): CSS Tutorial[^]


HTML5初学者指南& CSS3 - 为您的第一个网页设置样式 [ ^ ]你会没事的。


这篇关于如何在CSS类中使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆