Cách tạo: Bảng thanh toán

Học cách sử dụng CSS để tạo bảng thanh toán linh hoạt.

Bảng thanh toán linh hoạt

Địa chỉ thanh toán


Thanh toán


Giỏ hàng 4

Mục 1 $15

Mục 2 $5

Mục 3 $8

Mục 4 $2


Tổng cộng $30

Thử ngay

Cách tạo bảng thanh toán

Bước 1 - Thêm HTML:

Sử dụng thẻ <form> để xử lý đầu vào. Bạn có thể tìm hiểu thêm thông tin chi tiết trong hướng dẫn PHP của chúng tôi.

<div class="row">
  <div class="col-75">
    <div class="container">
      <form action="/action_page.php">
        <div class="row">
          <div class="col-50">
            <h3>Billing Address</h3>
            <label for="fname"><i class="fa fa-user"></i> Full Name</label>
            <input type="text" id="fname" name="firstname" placeholder="John M. Doe">
            <label for="email"><i class="fa fa-envelope"></i> Email</label>
            <input type="text" id="email" name="email" placeholder="john@example.com">
            <label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
            <input type="text" id="adr" name="address" placeholder="542 W. 15th Street">
            <label for="city"><i class="fa fa-institution"></i> Thành phố</label>
            <input type="text" id="city" name="city" placeholder="New York">
            <div class="row">
              <div class="col-50">
                <label for="state">Bang</label>
                <input type="text" id="state" name="state" placeholder="NY">
              </div>
              <div class="col-50">
                <label for="zip">Zip</label>
                <input type="text" id="zip" name="zip" placeholder="10001">
              </div>
            </div>
          </div>
          <div class="col-50">
            <h3>Thanh toán</h3>
            <label for="fname">Thẻ được chấp nhận</label>
            <div class="icon-container">
              <i class="fa fa-cc-visa" style="color:navy;"></i>
              <i class="fa fa-cc-amex" style="color:blue;"></i>
              <i class="fa fa-cc-mastercard" style="color:red;"></i>
              <i class="fa fa-cc-discover" style="color:orange;"></i>
            </div>
            <label for="cname">Tên trên thẻ</label>
            <input type="text" id="cname" name="cardname" placeholder="John More Doe">
            <label for="ccnum">Số thẻ tín dụng</label>
            <input type="text" id="ccnum" name="cardnumber" placeholder="1111-2222-3333-4444">
            <label for="expmonth">Tháng Exp</label>
            <input type="text" id="expmonth" name="expmonth" placeholder="Tháng September">
            <div class="row">
              <div class="col-50">
                <label for="expyear">Năm hạn sử dụng</label>
                <input type="text" id="expyear" name="expyear" placeholder="2018">
              </div>
              <div class="col-50">
                <label for="cvv">CVV</label>
                <input type="text" id="cvv" name="cvv" placeholder="352">
              </div>
            </div>
          </div>
        </div>
        <label>
          <input type="checkbox" checked="checked" name="sameadr"> Địa chỉ giao hàng trùng với địa chỉ thanh toán
        </label>
        <input type="submit" value="Tiếp tục thanh toán" class="btn">
      </form>
    </div>
  </div>
  <div class="col-25">
    <div class="container">
      <h4>Giỏ hàng
        <span class="price" style="color:black">
          <i class="fa fa-shopping-cart"></i>
          <b>4</b>
        </span>
      </h4>
      <p><a href="#">Sản phẩm 1</a> <span class="price">$15</span></p>
      <p><a href="#">Sản phẩm 2</a> <span class="price">$5</span></p>
      <p><a href="#">Sản phẩm 3</a> <span class="price">$8</span></p>
      <p><a href="#">Sản phẩm 4</a> <span class="price">$2</span></p>
      <hr>
      <p>Tổng <span class="price" style="color:black"><b>$30</b></span></p>
    </div>
  </div>
</div>

Bước 2 - Thêm CSS:

Tạo bố cục响应 với CSS Flexbox:}

.row {
  display: -ms-flexbox; /* IE10 */
  display: flex;
  -ms-flex-wrap: wrap; /* IE10 */
  flex-wrap: wrap;
  margin: 0 -16px;
}
.col-25 {
  -ms-flex: 25%; /* IE10 */
  flex: 25%;
}
.col-50 {
  -ms-flex: 50%; /* IE10 */
  flex: 50%;
}
.col-75 {
  -ms-flex: 75%; /* IE10 */
  flex: 75%;
}
.col-25,
.col-50,
.col-75 {
  padding: 0 16px;
}
.container {
  background-color: #f2f2f2;
  padding: 5px 20px 15px 20px;
  border: 1px solid lightgrey;
  border-radius: 3px;
}
input[type=text] {
  width: 100%;
  margin-bottom: 20px;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 3px;
}
label {
  margin-bottom: 10px;
  display: block;
}
.icon-container {
  margin-bottom: 20px;
  padding: 7px 0;
  font-size: 24px;
}
.btn {
  background-color: #04AA6D;
  color: white;
  padding: 12px;
  margin: 10px 0;
  border: none;
  width: 100%;
  border-radius: 3px;
  cursor: pointer;
  font-size: 17px;
}
.btn:hover {
  background-color: #45a049;
}
span.price {
  float: right;
  color: grey;
}
/* Thiết kế响应 - Khi độ rộng màn hình nhỏ hơn 800px, hai cột堆叠 thay vì dàn hàng ngang (và thay đổi hướng - đặt cột "Giỏ hàng" ở trên cùng) */
@media (max-width: 800px) {
  .row {
    flex-direction: column-reverse;
  }
  .col-25 {
    margin-bottom: 20px;
  }
}

Thử ngay

Trang liên quan

Hướng dẫn:HTML biểu mẫu

Hướng dẫn:CSS biểu mẫu

Hướng dẫn:CSS Flexbox