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

จะสร้าง Icon Bar ด้วย CSS ได้อย่างไร?


ในการสร้างแถบไอคอนด้วย CSS โค้ดจะเป็นดังนี้ -

ตัวอย่าง

<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.icon-bar {
   width: 100%;
   background-color: black;
   overflow: auto;
}
.icon-bar a {
   float: left;
   width: 30%;
   text-align: center;
   color: white;
   font-size: 30px;
}
.active {
   background-color: blue;
}
</style>
<body>
   <div class="icon-bar">
      <a href="#"><i class="fa fa-home"></i></a>
      <a href="#"><i class="fa fa-search"></i></a>
      <a class="active" href="#"><i class="fa fa-bars"></i></a>
   </div>
</body>
</html>

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

จะสร้าง Icon Bar ด้วย CSS ได้อย่างไร?

ตัวอย่าง

ให้เรามาดูตัวอย่างอื่นที่เราจะสร้างแถบไอคอนแนวตั้ง -

<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.icon-bar {
   width: 50px;
   background-color: black;
}
.icon-bar a {
   display: block;
   text-align: center;
   color: white;
   font-size: 30px;
}
.active {
   background-color: blue;
}
</style>
<body>
   <div class="icon-bar">
      <a class="active" href="#"><i class="fa fa-home"></i></a>
      <a href="#"><i class="fa fa-search"></i></a>
      <a href="#"><i class="fa fa-bars"></i></a>
   </div>
</body>
</html>

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

จะสร้าง Icon Bar ด้วย CSS ได้อย่างไร?