Html 将类应用于 div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4386399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:38:12  来源:igfitidea点击:

applying a class to a div

cssclasshtml

提问by aks

I have a css which has some attribute as follows:

我有一个 css,它有一些属性如下:

.ts{
    background-image: url("images/xyz/pb.gif");
    background-repeat: no-repeat;
    padding:0,0,0,20px;
    display:none;
}

.ts.visible{
    display: inline;
}

Now i want to apply the this style to a div in my html page.How cna i do it.I dont know css

现在我想将此样式应用于我的 html 页面中的 div。我是如何做到的。我不知道 css

回答by Spiny Norman

Yep, what they said. Also, if you want to assign more than one class, use a space to separate them, like so: <div class="ts visible">.

是的,他们说的。此外,如果您想分配多个类,请使用空格将它们分开,如下所示:<div class="ts visible">

Edit:

编辑:

Also, use spaces to separate the "padding" values, like this: padding: 0 0 0 20px;, or just use padding-left: 20px;.

此外,使用空格分隔“填充”值,例如:padding: 0 0 0 20px;,或仅使用padding-left: 20px;.

回答by Hoàng Long

You can use it like this: <div class="ts">... </div>

你可以这样使用它: <div class="ts">... </div>

But I strongly recommend you take a look at css here, it's not that hard.

但我强烈建议你看看这里的css ,这并不难。

回答by Nick Craver

Just give that <div>a class attribute, like this:

只需给它<div>一个类属性,如下所示:

<div class="ts"></div>

If you want it to have both classes, use a space between like this:

如果您希望它同时拥有两个类,请在它们之间使用一个空格,如下所示:

<div class="ts visible"></div>

回答by John Parker

You'd simply do:

你只需要做:

<div class="ts">Contents of div</div>

That said, I very much suspect that's not the answer you're looking for. :-)

也就是说,我非常怀疑这不是您要寻找的答案。:-)