2016-09-27 2 views
-1

フォーカスセレクタ付きのCSSを独自のクラスに適用したいと思います。私はそれだけでフォーカスのクラスを非表示にしたくない。ここに私のコードスニペットがあります。独自のクラスに焦点を当てたCSSを適用する

body { 
 
    display: block; 
 
} 
 
.span3:focus ~ .alert { 
 
    display: none; 
 
} 
 
.span2:focus ~ .alert { 
 
    display: block; 
 
}
<span class="span3" tabindex="0">Hide Me</span> 
 
<span class="span2" tabindex="0">Show Me</span> 
 
<p class="alert">Some alarming information here</p>

+0

あなたはuは男を言うために何を意味しています –

+0

を言っているのか理解できないのですか? –

+0

うん、私のためにうまくいっているようだ –

答えて

0

私はJavaScriptを使用する必要があり、それはあなたの質問への答えだと思います。少しのスクリプト、およびCSSのいくつかの行を削除します。

https://jsfiddle.net/prsebqg3/


htmlファイル

<span id="span3" tabindex="0">Hide Me</span> 
<span id="span2" tabindex="0">Show Me</span> 
<p id="alert" >Some alarming information here</p> 

<script> 
    document.getElementById("span3").onclick = function() {functionHide()}; 

    function functionHide() { 
     document.getElementById("span2").style.display = "block"; 
     document.getElementById("span3").style.display = "none"; 
     document.getElementById("alert").style.display = "none";  
    } 

    document.getElementById("span2").onclick = function() {functionShow()}; 

    function functionShow() { 
     document.getElementById("span2").style.display = "none"; 
     document.getElementById("span3").style.display = "block"; 
     document.getElementById("alert").style.display = "block";  
    } 
</scrip> 

CSSファイル

#span2{ 
    display:none; 
} 
+0

実際に私は電子メールテンプレートでこの作業をしようとしています。だから私は何かの理由でjqueryまたはJavaスクリプトを使用することはできません。私はcssだけでこの仕事をすることをwan't。 –

関連する問題