2017-06-12 3 views
0

いくつかのLI要素を含むHTMLページがあり、LI要素にグループ化機能を追加したいとします。 'automobile'私はグループ化を適用したいと思います。私はそれらに同じgroupidを適用し、それらを区別するためにマージンを適用しました。しかし、私は垂直線を適用して、ユーザーがこれら2つのLI要素がグループ化されていることを正しく理解できるようにしたいと考えています。あなたがここにスタイルシートで作業しているので、あなたは、クラス属性のそのid属性を変更する必要がありますとIDが一意である、それをあなたのような複数回使用することはできませんグループを構成する2つのli要素を理解するために垂直線を打つ

Group Pic

<div> 
 
    <ul> 
 
    <li title="Insurance"> 
 
     <div> 
 
     <input type="checkbox" /> 
 
     <span>Malpractice</span> 
 
     </div> 
 
    </li> 
 
    <li title="Construction"> 
 
     <div> 
 
     <input type="checkbox" /> 
 
     <span>Carpentry</span> 
 
     </div> 
 
    </li> 
 

 
    <li title="Education" id="grp1" style="margin-left:20px;"> 
 
     <div> 
 
     <input type="checkbox" /> 
 
     <span>College</span> 
 
     </div> 
 
    </li> 
 
    <li title="Insurance" id="grp1" style="margin-left:20px;"> 
 
     <div> 
 
     <input type="checkbox" /> 
 
     <span>Automobile</span> 
 
     </div> 
 
    </li> 
 

 
    <li title="Education"> 
 
     <div> 
 
     <input type="checkbox" /> 
 
     <span>Iron Worker</span> 
 
     </div> 
 
    </li> 
 
    <li title="Insurance"> 
 
     <div> 
 
     <input type="checkbox" /> 
 
     <span>High School</span> 
 
     </div> 
 
    </li> 
 

 
    </ul> 
 
</div>

+1

IDはusiqueでなければなりません。 classまたはdata属性を 'data-id'の代わりに使用してください。 –

+0

okこれを修正しますが、実際の問題はどうですか? – Utpal

+0

':first-child'と':last-child'を使い、最初の 'border-top'と2番目の' border-bottom'を設定することができます。 –

答えて

0

使っている。

<div> 
    <ul> 
     <li title="Insurance"> 
      <div> 
       <input type="checkbox" > 
       <span>Malpractice</span> 
      </div> 
     </li> 
     <li title="Construction"> 
      <div> 
       <input type="checkbox" > 
       <span>Carpentry</span> 
      </div> 
     </li> 

     <li title="Education" class="grp1" style="margin-left:20px;"> 
      <div> 
       <input type="checkbox" > 
       <span>College</span> 
      </div> 
     </li> 
     <li title="Insurance" class="grp1" style="margin-left:20px;"> 
      <div> 
       <input type="checkbox" > 
       <span>Automobile</span> 
      </div> 
     </li> 

     <li title="Education"> 
      <div> 
       <input type="checkbox" > 
       <span>Iron Worker</span> 
      </div> 
     </li> 
     <li title="Insurance"> 
      <div> 
       <input type="checkbox" > 
       <span>High School</span> 
      </div> 
     </li> 

    </ul> 
</div> 

その後、次の

li.grp1 { 
    border-left: 3px solid blue; 
} 

PSを行うことができます。入力タグを閉じないように覚えています。入力はコンテナではなく要素になるように設計されているため、ここには開かれたタグと閉じタグはありません。

+0

それは印象的な行ですが、私はそれをグループ解除するためのボタンで行が必要です – Utpal

1

これはあなたの探しているものですか?

$(document).on("click", "ul", function() { 
 
    alert("Clicked!"); 
 
})
.grouped { 
 
    border-left: solid 15px pink; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
.grouped:before { 
 
    font-family: fontAwesome; 
 
    content: "\f03a"; 
 
    font-size: 10px; 
 
    position: absolute; 
 
    left: 10px; 
 
    top: 10px; 
 
    cursor: pointer; 
 
    pointer-events: all; 
 
} 
 

 
.grouped li { 
 
    list-style: none; 
 
} 
 

 
.grouped li span { 
 
    padding-left: 1em; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> 
 
<ul class="grouped"> 
 
    <li><input type="text"><span>College</span></li> 
 
    <li><input type="text"><span>Automobile</span></li> 
 
</ul>

+0

はい、それはかなりOKですが、アイコンをクリックすると、私はそれをクリックすると、私はグループを解除するためのjavascriptを起動することができます – Utpal

+0

私はコード。アイコンをクリックすることができます。 – Gerard

+0

すべてのLI要素にグループ化を適用しました。grp1 idを持つLI要素にのみ適用したい – Utpal

関連する問題