16

私のページでは、このcssの助けを借りて、div全体を選択不可にしました(これはstackoverflowから取得しました)

    .unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;

   /*
     Introduced in IE 10.
     See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
   */
   -ms-user-select: none;
   user-select: none;
}

今、私はこの選択できないdiv内にh2タグを持っています.そして、そのh2を選択可能にしたい.これを簡単に達成する方法はありますか.

私は私の質問で何かを忘れていました。コードに 3 つの h2 があり、特定の 1 つを選択可能にする必要があるため、この h2 にクラスを追加し、この .unselectable:not(.class-of-h2) のようなことを試しました (以下の回答から取得しました)。しかし、それは機能していません

4

3 に答える 3

32

h2要素に使用

.unselectable h2{
 -moz-user-select: text;
 -khtml-user-select: text;
 -webkit-user-select: text;
 -ms-user-select: text;
 user-select: text;
}

デモを見る

于 2012-12-28T12:22:00.847 に答える
2

以下のCSSを追加するだけです

.unselectable h2 {
   -moz-user-select: text;
   -khtml-user-select: auto;
   -webkit-user-select: auto ;
   -ms-user-select: auto;
   user-select: auto;
 }

デモを見る

于 2012-12-28T12:21:20.393 に答える
1

あなたが使用することができます

     .unselectable:not(h2:nth-child(2)) {
      //your data
      } 

セレクターのリストから要素を除外することはできません
。これにより、h2 要素を除いて div 全体が選択できなくなります。

于 2012-12-28T12:18:59.877 に答える