7

値を変更せずに、標準タグから設定を自動的に継承するかどうか疑問に思っていhoverましたかactive?focusa

例えば:

.wrapper .left .main .row .holder .more a,
#content .wrapper .left .main .row .holder .more a:visited
{
    width: 92px;
    min-width: 92px;
    max-width: 92px;
    height: 23px;
    min-height: 23px;
    max-height: 23px;
    display: block;
    margin: 0px auto;
    background: #fff url(../images/more-info-btn.png) top left no-repeat;
}

#content .wrapper .left .main .row .holder .more a:hover {
    width: 92px;
    min-width: 92px;
    max-width: 92px;
    height: 23px;
    min-height: 23px;
    max-height: 23px;  
    display: block;
    margin: 0px auto;
    background: #fff url(../images/more-info-btn.png) bottom left no-repeat;
}

以下は同じことをしますか?

#content .wrapper .left .main .row .holder .more a,
#content .wrapper .left .main .row .holder .more a:visited
{
    width: 92px;
    min-width: 92px;
    max-width: 92px;
    height: 23px;
    min-height: 23px;
    max-height: 23px;
    display: block;
    margin: 0px auto;
    background: #fff url(../images/more-info-btn.png) top left no-repeat;
}

#content .wrapper .left .main .row .holder .more a:hover {
    background: #fff url(../images/more-info-btn.png) bottom left no-repeat;
}
4

2 に答える 2

6

はい、その通りです。疑似状態は値を継承します。

一貫性を保つために、疑似状態ルールで変更するスタイルのみを宣言することをお勧めします。

次のコードでは、状態font-size:1.9empadding-top:10px関係なく、テキストは常に になります。:hover

a
{
    color:red;
    font-size:1.9em;
    padding-top:10px;
}

a:hover
{
    color:green;
}​

-- 例を参照 --

于 2012-04-17T09:09:57.397 に答える
2

No, because an a element in one of the states is still an a element, and an element cannot inherit from itself. But any setting that has a as the selector applies when the element is in one of the states, too.

Thus, when you want some properties to apply to a elements in all states, then it suffices to set them using the a selector.

Technically, the two sets of rules in your question are not equivalent, due to differences in selectors, which affect specificity. Situations where this would matter are rare and would involve rather special rules in other stylesheets being applied.

于 2012-04-17T10:13:38.323 に答える