Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> CSS

Tạo nút liên kết có viền với CSS

Chuyển liên kết thành nút bấm (Button Link)

Kết hợp display: inline-block, padding, border, và các pseudo-class trạng thái để tạo nút đẹp từ thẻ <a>.

Ví dụ minh họa

<!DOCTYPE html>
<html>
<head>
  <style>
    a:link, a:visited {
      background-color: white;
      color: black;
      border: 1px solid blue;
      padding: 10px 20px; /* Giảm từ 30px cho hợp lý */
      text-align: center;
      text-decoration: none;
      display: inline-block;
    }
    a:hover, a:active {
      background-color: red;
      color: white;
    }
  </style>
</head>
<body>
  <a href="demo.html" target="_blank">Nút Demo</a>
</body>
</html>

Liên kết hiển thị như nút: viền xanh, nền trắng, chữ đen. Hover/Active: nền đỏ, chữ trắng.