Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

Anchor Pseudo-class ใน CSS


การใช้ CSS pseudo-class selector กล่าวคือ :active, :hover, :link และ :visited เราสามารถกำหนดรูปแบบสถานะต่างๆ ของลิงก์/จุดยึดได้ เพื่อการทำงานที่เหมาะสม ลำดับของตัวเลือกเหล่านี้ควรเป็น −

  • :ลิงค์
  • :เยี่ยมชมแล้ว
  • :โฮเวอร์
  • :ใช้งานอยู่

ไวยากรณ์ของคุณสมบัติ CSS psudo-class มีดังนี้ -

a:(pseudo-selector) {
   /*declarations*/
}

ตัวอย่าง

มาดูตัวอย่างการใช้ CSS Anchor Pseudo Classes -

<!DOCTYPE html>
<html>
<head>
<style>
div {
   display: flex;
   float: left;
}
a {
   margin: 20px;
   padding: 10px;
   border: 2px solid black;
   text-shadow: -1px 0px black, 0px -1px black, 0px 1px black, 1px 0px black;
   font-size: 1.1em;
}
a:link {
   text-decoration: none;
}
a:visited {
   color: blueviolet;
}
a:hover {
   color: orange;
   font-size: 150%;
   font-weight: bold;
   box-shadow: 0 0 5px 1px grey;
}
a:active {
   color: red;
   box-shadow: inset 0 0 15px red;
}
</style>
</head>
<body>
<div>
<h2>Your favourite sports?</h2>
<a href="#">Football</a>
<a href="">Cricket</a>
</div>
</body>
</html>

ผลลัพธ์

เอาต์พุตเริ่มต้น -

Anchor Pseudo-class ใน CSS

เมื่อวางเมาส์เหนือลิงก์แรก เราจะได้ผลลัพธ์ดังต่อไปนี้

Anchor Pseudo-class ใน CSS

ในระหว่างการคลิกลิงก์แรก ผลลัพธ์ต่อไปนี้จะถูกส่งกลับ -

Anchor Pseudo-class ใน CSS

มาดูตัวอย่างอื่นของ CSS Anchor Pseudo Class −

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<title>CSS Anchor Pseudo Classes</title>
</head>
<style>
div {
   color: #000;
   padding:20px;
   background-image: linear-gradient(135deg, grey 0%, white 100%);
   text-align: center;
}
.anchor {
   color: #FF8A00;
}
.anchor:last-child {
   color: #03A9F4;
}
.anchor:visited {
   color: #FEDC11;
}
.anchor:hover {
   color: #C303C3;
}
.anchor:active {
   color: #4CAF50;
}
</style>
<body>
<div>
<h1>Search Engines</h1>
<a class="anchor" href="https://www.google.com" target="_blank">Go To Google</a>
<a class="anchor" href="https://www.bing.com" target="_blank">Go To Bing</a>
</div>
</body>
</html>

ผลลัพธ์

Anchor Pseudo-class ใน CSS