2013-08-27 17 views

答えて

7

をあなたの現在の現在のHTMLのためにあなたが

.always-here { 
    display:none; 
} 
.im-here ~ .always-here{ 
    display:block; 
} 

これを行うことができます。

<style type="text/css"> 
.always-here { 
    display:none; 
} 
</style> 

<div class="im-here">This div exists on this particular page!</div> 
<div class="always-here">This div is always here but has the style 
display: none unless a div with the class "im-here" exists.</div> 
+0

これはCSSで解決できるとは考えていませんでした。このメソッドはブラウザ間で互換性がありますか? – Heather

+0

@Heather http://reference.sitepoint.com/css/generalsiblingselector、https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_selectors、https://www.google.tt/を参照してください。検索?q =一般+兄弟+セレクタ&oq =一般+兄弟+セレクタ&aqs = chrome..69i57j0l3.6681j0&sourceid = chrome&ie = UTF-8#fp = 828651ec3b51e1b8&q = css +一般+兄弟+セレクタ+ブラウザ+サポート – Musa

0

これを試してみてください....私はjqueryのを推測しているか、jsが進むべき道だろう.always-here.im-hereが兄弟で、.im-hereが前に来る場合にのみ動作します。

http://jsfiddle.net/BKYSV/から.im-here存在
http://jsfiddle.net/BKYSV/1/ - ここ.im-here不在

1
$(document).ready(function(){ 
    if($(".im-here").length > 0) 
    { 
     $(".always-here").show(); 
    } 
}); 

はコード Click Here!

0

ですはい、あなたはjqueryのを使用することで、このコード

$(document).ready(function(){ 
    if($('.im-here').length) 
     $('.always-here').show(); 
}); 

を表示することを行うことができますexample here

関連する問題