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);
}