CSS中的继承? [英] Inheritance in CSS?

查看:40
本文介绍了CSS中的继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




CSS中我从未理解过的东西是什么继承

有效?或者至少如果可能的话:


例如我想用几种颜色创建一个Comic 16字体红色,

黄色和蓝色

据我所知,我需要做的是:




..Comic16Red

{

font-family:Comic sans MS,Cursive,Verdana,Arial;

字体大小:16px;

颜色:FF0000;

}


..Comic16Yellow

{

font-family:" Comic sans MS" Cursive, Verdana,Arial;

字体大小:16px;

颜色:FFFF00;

}


..Comic16Blue

{

font-family:" Comic sans MS" Cursive,Verdana,Arial;

font-size: 16px;

颜色:0000FF;

}


但是我可能想要使用相同3种颜色的其他字体

据我所知这样做是合乎逻辑的:


..Comic16

{

font-famil y:Comic sans MS,Cursive,Verdana,Arial;

字体大小:16px;

}


然后定义可重复使用的颜色元素:


..red

{

颜色:FF0000;

}


..yellow

{

颜色:FFFF00;

}


..blue

{

颜色:0000FF;

}


然后通过做类似的事情来使用它(例如):


< p class =" Comic16.red"> Test< / p>

而不是

< p class =" Comic16Red">测试< / p>


但这似乎不可行。那么有没有办法重复使用3

颜色元素而无需重新定义每种颜色的每个字体?

我希望这很清楚;)

解决方案

ch ***** ******@hotmail.com 写道:



CSS中有一些我从未理解过的东西是如何继承
的?或者至少如果可能的话:

例如我想用几种颜色创建一个Comic 16字体红色,
黄色和蓝色

根据我的理解,我需要做的是:



.Comic16Red
{font / family:" Comic sans MS" Cursive,Verdana,Arial;
font-size:16px;
颜色:FF0000;
}

.Comic16Yellow
{
font-family:" Comic sans MS" ;,Cursive,Verdana,Arial;
字体大小:16px;
颜色:FFFF00;
}

.Comic16Blue
{
font-family:Comic sans MS,Cursive,Verdana,Arial;
font-size:16px;
颜色:0000FF;
}

然后我可能想要使用相同的3种颜色的其他字体,所以
根据我的说法,这是合乎逻辑的:

.Comic16
{
字体-family:Comic sans MS,Cursive,Verdana,Arial;
font-size:16px;
}
然后定义可重复使用的颜色元素:

.red
{
颜色:FF0000;
}

。黄色
{/>颜色:FFFF00;


.blue
{
颜色:0000FF;
}

然后通过做类似的事情来使用它(例如):

< p class =" Comic16.red"> Test< / p>
而不是
< p class =" Comic16Red"> Test< ; / p>

然而,这似乎不可能。那么有没有办法重复使用3
颜色元素而不必重新定义每种颜色的每个字体?
我希望这是明确的;)



< p class =" Comic16 red"> test< / p>


这与继承无关,只需使用多个类

和你应该用空格分隔多个类(而不是。)


ch *********** @ hotmail.com 写道:



这里有我从未在CSS中理解过的东西是如何继承
的?或者至少如果可能的话:

例如我想用几种颜色创建一个Comic 16字体红色,
黄色和蓝色

根据我的理解,我需要做的事情:
.Comic16Red
{
font-family:" Comic sans MS" Cursive,Verdana,Arial;
font-size:16px ;
颜色:FF0000;
}

.Comic16Yellow
{font / family:" Comic sans MS" Cursive,Verdana,Arial;
font-size:16px;
颜色:FFFF00;
}

.Comic16Blue
{
font-family:" Comic sans MS,Cursive,Verdana,Arial;
font-size:16px;
color:0000FF;
}

然后我可能想要使用其他字体相同的3种颜色如此
根据我的说法,能够做到这一点是合乎逻辑的:

.Comic16
{
font-family:" Comic sans MS" ;,Cursive,Verdana,Arial;
font-size:16px;
}
然后定义可重复使用的颜色元素:

.red {
颜色:FF0000;
}

。黄色
{
颜色:FFFF00;
}

.blue
{
颜色:0000FF;
}
然后通过做类似的事情来使用它(例如):

< ; p class =" Comic16.red"> Test< / p>
而不是
< p class =" Comic16Red">测试< / p>
但是这似乎不太可能。




只需这样写:

class =" Comic16 red"

空格而不是点。

那么有没有办法重复使用3
颜色元素而不必重新定义每种颜色的每个字体?
我希望这个很清楚;)




是的,完全清楚。但是......不要将px用于字体大小。这意味着IE

用户不能在他们的浏览器中调整字体大小,他们可能找不到

16px易于阅读。


我猜你这个例子只使用了.red和.blue类

对吗?在类名中设置颜色并不聪明 - 如果你想要什么

。以后会变成蓝色? ;-)


-

Els http://locusmeus.com/

Sonhos vem。 Sonhos v?o。 Orestoébritfeito。

- Renato Russo -

现在播放:The Specials - Nite Klub


ch *********** @ hotmail.com 写道:
< blockquote class =post_quotes> CSS中我从未理解过的东西是什么继承
有效?


可继承的CSS属性从父元素继承

元素到子元素。


例如

p {font-weight:bold;}

< p>一些文字< a href ="">和一个链接< / a>< / p> ;

链接将是粗体beacuse font-weight是继承的。


你似乎在谈论一种不同的继承。

或者至少如果可能的话:

例如我想用几种颜色创建一个Comic 16字体红色,
黄色和蓝色

根据我的理解,我需要做的事:
.Comic16Red
{font / family:" Comic sans MS" Cursive,Verdana,Arial;
font-尺寸:16px;
颜色:FF0000;
}




不要将px用于字体大小。

指定前景色时指定背景颜色。

对于所有那些圣洁的爱,请告诉我们你是j ust

使用Comic Sans作为例子...

然后我可能想要使用相同3种颜色的其他字体,所以
根据我的意愿是合乎逻辑的能够做到:

.Comic16
{font / family:Comic sans MS,Cursive,Verdana,Arial;
font-尺寸:16px;
}
然后定义可重复使用的颜色元素:

.red
{/>颜色:FF0000;
}
然后通过做类似的事情来使用它(例如):

< p class =" Comic16.red"> Test< / p>




关闭。

class =" Comic16 red"将两个类都应用于元素。


史蒂夫


-

我的理论给你,我的异端邪说激怒了你,

我从不回信,你也不喜欢我的领带。 - 医生


Steve Pugh< st *** @ pugh.net> < http://steve.pugh.net/>


Hi

There''s something I''ve never understood in CSS is how inheritance
works? Or at least if this is possible:

For example I want to create a Comic 16 font in several colors Red,
Yellow and Blue

From what I understand I need to do:



..Comic16Red
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FF0000;
}

..Comic16Yellow
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FFFF00;
}

..Comic16Blue
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: 0000FF;
}

But then I might want to use other fonts in the same 3 colors so
according to me it would be logical to be able to do:

..Comic16
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
}

Then define reusable color elements:

..red
{
color: FF0000;
}

..yellow
{
color: FFFF00;
}

..blue
{
color: 0000FF;
}

And then use it by doing something like (for example):

<p class="Comic16.red">Test</p>
instead of
<p class="Comic16Red">Test</p>

However this does not seem possible. So is there a way to reuse the 3
color elements without having to redefine each Font in each color?
I hope this is clear ;)

解决方案

ch***********@hotmail.com wrote:

Hi

There''s something I''ve never understood in CSS is how inheritance
works? Or at least if this is possible:

For example I want to create a Comic 16 font in several colors Red,
Yellow and Blue

From what I understand I need to do:



.Comic16Red
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FF0000;
}

.Comic16Yellow
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FFFF00;
}

.Comic16Blue
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: 0000FF;
}

But then I might want to use other fonts in the same 3 colors so
according to me it would be logical to be able to do:

.Comic16
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
}

Then define reusable color elements:

.red
{
color: FF0000;
}

.yellow
{
color: FFFF00;
}

.blue
{
color: 0000FF;
}

And then use it by doing something like (for example):

<p class="Comic16.red">Test</p>
instead of
<p class="Comic16Red">Test</p>

However this does not seem possible. So is there a way to reuse the 3
color elements without having to redefine each Font in each color?
I hope this is clear ;)


<p class="Comic16 red">test</p>

and this has nothing to do with inheritance, just using multiple classes
and you should separate multiple classes with a space (and not a .)


ch***********@hotmail.com wrote:

Hi

There''s something I''ve never understood in CSS is how inheritance
works? Or at least if this is possible:

For example I want to create a Comic 16 font in several colors Red,
Yellow and Blue

From what I understand I need to do:
.Comic16Red
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FF0000;
}

.Comic16Yellow
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FFFF00;
}

.Comic16Blue
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: 0000FF;
}

But then I might want to use other fonts in the same 3 colors so
according to me it would be logical to be able to do:

.Comic16
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
}

Then define reusable color elements:

.red
{
color: FF0000;
}

.yellow
{
color: FFFF00;
}

.blue
{
color: 0000FF;
}

And then use it by doing something like (for example):

<p class="Comic16.red">Test</p>
instead of
<p class="Comic16Red">Test</p>

However this does not seem possible.



Just write it like this:
class="Comic16 red"
A space instead of a dot.
So is there a way to reuse the 3
color elements without having to redefine each Font in each color?
I hope this is clear ;)



Yup, all clear. But... don''t use px for font sizes. It means that IE
users can''t resize the font in their browsers, and they may not find
16px easy to read.

And I guess you only used .red and .blue classes for this example
right? Wouldn''t be smart to set the colours in the class names - what
if you want .red to be blue later? ;-)

--
Els http://locusmeus.com/
Sonhos vem. Sonhos v?o. O resto é imperfeito.
- Renato Russo -
Now playing: The Specials - Nite Klub


ch***********@hotmail.com wrote:

There''s something I''ve never understood in CSS is how inheritance
works?
Those CSS properties that are inheritable are inherite from parent
element to child element.

e.g.
p {font-weight: bold;}
<p>some text <a href="">and a link</a></p>
The link will be bold beacuse font-weight is inherited.

You seem to be talking about a different sort of inheritence.
Or at least if this is possible:

For example I want to create a Comic 16 font in several colors Red,
Yellow and Blue

From what I understand I need to do:
.Comic16Red
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
color: FF0000;
}



Don''t use px for font sizes.
Specify a background-color whenever you specify a foreground color.
And for the love of all that''s holy please tell us that you''re just
using Comic Sans as an example...
But then I might want to use other fonts in the same 3 colors so
according to me it would be logical to be able to do:

.Comic16
{
font-family: "Comic sans MS",Cursive,Verdana,Arial;
font-size: 16px;
}

Then define reusable color elements:

.red
{
color: FF0000;
} And then use it by doing something like (for example):

<p class="Comic16.red">Test</p>



Close.
class="Comic16 red" will apply both classes to the element.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don''t like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>


这篇关于CSS中的继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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