2013-10-14 9 views
12

グローバルリンクスタイルを上書きしたいdivがあります。私は2つのリンクスタイルを持っています。一つはグローバル、一つは固有です。動作しないようですがhtml div内のリンクスタイルを無効にする

<div id="macrosectiontext"><a href="www.google.it">bla bla bla</a></div> 

:ここでは、コード:

A:link {text-decoration: none; color: #FF0000;} 
A:visited {text-decoration: none; color: #FF0000;} 
A:hover {text-decoration: none; color: #FF0000;} 
A:active {text-decoration: none; color: #FF0000;} 

#macrosectiontext 
{ 
    position:relative; 
    font:Arial, sans-serif; 
    text-align:center; 
    font-size:50px; 
    font-style: bold; 
    margin-top:245px; 
    opacity: 0.6; 
    background-color:transparent; 
} 

#macrosectiontext A:link {text-decoration: none; color: #000000;} 
#macrosectiontext A:visited {text-decoration: none; color: #FFFFFF;} 
#macrosectiontext A:hover {text-decoration: none; color: #FFFFFF;} 
#macrosectiontext A:active {text-decoration: none; color: #FFFFFF;} 

と私はこのようなdiv要素を使用しています。 divは引き続きグローバルリンクスタイルを継承します。私は小文字の「Aを使用

  • ".macrosectiontext" クラスを使用するリンクコードのために:私は "リンク... #macrosectiontext" IDを使用していないだろうCSSで

  • +0

    はちょうどデモため、ホバー色を変更)あなたのHTMLにアンカーリンクが表示されていません。 –

    +1

    '#macrosectiontext {color:#000000};と書いてください。これは動作します –

    +0

    私にとってうまく動作します。ここには[jsfiddle](http://jsfiddle.net/Xz8KQ/)があります。 –

    答えて

    7
    1. "リンクスタイルのキャップ" A "の代わりに

    2. リンクをスパンタグで数回使用してから、divの代わりにspanタグからスタイルを呼び出すことができます。

    +0

    上記の最初のポイントが鍵です。リンクのクラスを割り当て、クラス内の色を定義します。クール! – spiderman

    10

    CSSは継承に基づいているため、変更するプロパティを上書きする必要があります。

    HTML & CSSの小文字、まだあなたのHTMLとCSSを書くことを常に試しは

    a:link, a:visited, a:hover, a:active { 
        text-decoration: none; color: #f00; 
    } 
    
    #macrosectiontext { 
        position:relative; 
        font:Arial, sans-serif; 
        text-align:center; 
        font-size:50px; 
        font-style: bold; 
        margin-top:245px; 
        opacity: 0.6; 
        background-color:transparent; 
    } 
    
    #macrosectiontext a:link {color: #000;} 
    #macrosectiontext a:visited, #macrosectiontext a:hover, 
    #macrosectiontext a:active { 
        color: #fff; 
    } 
    
    正しいI made a fiddle for youあなたのコードが動作している表示する

    関連する問題