2

CSS:first-childとの使用に問題があり:last-childます。

<a>margin-bottom:5px のみが必要な最初のタグと最後のタグ 0px のタグ間にスペースを追加する必要があります。

ここに私のコード..私はここで何が間違っていますか? 他の代替案はありますか?ありがとう

.addthis_toolbox.atfixed
    {
        border: 1px solid #eee;
        padding: 5px;
        width: 32px;
    }
    .addthis_toolbox:first-child
    {
        margin-bottom:5px;
    }
    .addthis_toolbox:last-child
    {
     margin-bottom:0px;
    }

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_32x32_style atfixed">
    <a class="addthis_button_preferred_1"></a>
    <a class="addthis_button_preferred_2"></a>
    <a class="addthis_button_preferred_3"></a>
    <a class="addthis_button_preferred_4"></a>
    <a class="addthis_button_compact"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e55018a5d405a71"></script>
<!-- AddThis Button END -->
4

2 に答える 2

4

.addthis_toolbox:first-child/の間にスペースを追加する必要があります:last-child

.addthis_toolboxそれ以外の場合は、親の最初または最後の子である要素のみが選択されます。

:first-childが要素に適用され、その要素その親の要素である要素のみが選択されます。first-child

疑似セレクターがどのように機能するかについては、w3c 仕様を参照してください。

于 2011-08-24T16:28:41.030 に答える
3

提供したものを直接修正するには、次のものが必要です。

.addthis_toolbox a:first-child
{
    margin-bottom:5px;
}
.addthis_toolbox a:last-child
{
 margin-bottom:0px;
}

問題は、親の最初の子である を.addthis_toolbox:first-child選択することです。.addthis_toolboxそして、それはあなたが望んでいたものではありません。


ここで混乱するかもしれませんが、every aの間にギャップを追加しようとしている場合は、これを使用して処理します。

.addthis_toolbox a + a {
    margin-top: 5px;
}

を使用していないため、すっきりしていて、ブラウザーのサポートが向上してい:last-childます。

于 2011-08-24T16:28:47.327 に答える