Tạo Thanh Điều Hướng Cố Định Đẹp Mắt Với Tooltip và Responsive Cho Flatsome

Trong bài viết này, tôi xin chia sẻ một đoạn mã HTML và CSS tạo thanh điều hướng cố định với các biểu tượng liên kết (Hotline, Báo giá, Facebook, Zalo) hiển thị ở cạnh phải trên desktop và chuyển thành thanh ngang ở dưới cùng trên thiết bị di động.

Tạo Thanh Điều Hướng Cố Định Đẹp Mắt Với Tooltip và Responsive Cho Flatsome

Thanh Điều Hướng Cố Định Đẹp Mắt Với Tooltip và Responsive Cho Flatsome

Điểm nổi bật của đoạn code này là hiển thị tooltip (tiêu đề) khi hover trên desktop, sử dụng thuộc tính title hoặc tùy chỉnh tooltip bằng CSS để tăng tính thẩm mỹ.

Trên thiết bị di động, các nhãn văn bản sẽ thay thế tooltip để đảm bảo trải nghiệm người dùng tốt hơn.

Đoạn mã được tối ưu hóa cho cả hiệu suất và khả năng tiếp cận, với các thuộc tính aria-label hỗ trợ người dùng sử dụng trình đọc màn hình.

Bạn có thể dễ dàng tùy chỉnh màu sắc, hình ảnh, hoặc thêm hiệu ứng để phù hợp với dự án của mình.

<div id="fixed-right">
  <ul>
    <li>
      <a href="tel:0859329888" class="hotline" title="Hotline" aria-label="Call our hotline"></a>
      <span class="icon-label">Hotline</span>
    </li>
    <li>
      <a href="https://thangmayxanhhp.vn/bao-gia/" class="price_quote" title="Báo giá" aria-label="Request a price quote"></a>
      <span class="icon-label">Báo giá</span>
    </li>
    <li>
      <a href="https://www.facebook.com/thangmayxanhhp" target="_blank" rel="nofollow" class="facebook" title="Facebook" aria-label="Visit our Facebook page"></a>
      <span class="icon-label">Facebook</span>
    </li>
    <li>
      <a href="http://zalo.me/0859329888" class="zalo" title="Zalo" aria-label="Contact us on Zalo"></a>
      <span class="icon-label">Zalo</span>
    </li>
  </ul>
</div>

<style>
/* Style chung cho desktop */
#fixed-right {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 998;
}

#fixed-right ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

#fixed-right ul li {
  margin-bottom: 8px;
  position: relative;
}

#fixed-right ul li a {
  display: block;
  width: 50px;
  height: 50px;
  background-position: center;
  background-repeat: no-repeat;
  transition: all 0.3s ease;
}

#fixed-right ul li a.hotline {
  background-color: #ff302a;
  border-radius: 5px;
  background-image: url(https://thangmayxanhhp.vn/wp-content/uploads/2025/05/phone-right.png);
}

#fixed-right ul li a.price_quote {
  background-color: #258217;
  border-radius: 5px;
  background-image: url(https://thangmayxanhhp.vn/wp-content/uploads/2025/05/price-right.png);
}

#fixed-right ul li a.facebook {
  background-color: #258217;
  border-radius: 5px;
  background-image: url(https://thangmayxanhhp.vn/wp-content/uploads/2025/05/facebook.png);
}

#fixed-right ul li a.zalo {
  background-color: #258217;
  border-radius: 5px;
  background-image: url(https://thangmayxanhhp.vn/wp-content/uploads/2025/05/zalo.png);
}

#fixed-right ul li a:hover {
  transform: scale(1.1);
  opacity: 0.9;
}

/* Custom tooltip for desktop */
#fixed-right ul li a::after {
  content: attr(title);
  position: absolute;
  right: 60px; /* Position to the left of the icon */
  top: 50%;
  transform: translateY(-50%);
  background-color: #333;
  color: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 999;
}

#fixed-right ul li a:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Hide icon-label on desktop */
.icon-label {
  display: none;
}

/* Media query cho mobile (dưới 768px) */
@media screen and (max-width: 768px) {
  #fixed-right {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    background-color: #fff;
    padding: 10px 0;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  }

  #fixed-right ul {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
  }

  #fixed-right ul li {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  #fixed-right ul li a {
    width: 40px;
    height: 40px;
  }

  /* Hide custom tooltip on mobile */
  #fixed-right ul li a::after {
    display: none;
  }

  /* Hiển thị nhãn văn bản trên mobile */
  .icon-label {
    display: block;
    font-size: 12px;
    color: #333;
    margin-top: 5px;
    text-align: center;
  }
}
</style>

Demo: tại đây
Hy vọng mã này sẽ hữu ích cho các dự án web của bạn!