CSS :ターゲットセレクター
例
アクティブなHTMLアンカーを強調表示します。
:target
{
border: 2px solid #D4D4D4;
background-color: #e5eecc;
}
定義と使用法
#の後にアンカー名が続くURLは、ドキュメント内の特定の要素にリンクします。リンク先の要素がターゲット要素です。
:target
セレクターを使用して、現在アクティブなターゲット要素のスタイルを設定できます。
バージョン: | CSS3 |
---|
ブラウザのサポート
表の数字は、セレクターを完全にサポートする最初のブラウザーのバージョンを示しています。
Selector | |||||
---|---|---|---|---|---|
:target | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS構文
:target {
css declarations;
}
その他の例
例
タブ付きメニューを作成します。
.tab div {
display: none;
}
.tab div:target {
display: block;
}
例
モーダル(ダイアログボックス)を作成します。
/* The modal's background */
.modal {
display: none;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}
/* Display the modal when targeted */
.modal:target {
display: table;
position: absolute;
}
/* The modal box */
.modal-dialog {
display: table-cell;
vertical-align: middle;
}
/* The modal's content */
.modal-dialog .modal-content {
margin: auto;
background-color: #f3f3f3;
position: relative;
padding: 0;
outline: 0;
border: 1px #777 solid;
text-align: justify;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}