Computer >> Máy Tính >  >> Lập trình >> CSS

Đặt chiều rộng tối thiểu và chiều rộng tối đa của một phần tử bằng cách sử dụng CSS

Để đặt chiều rộng tối thiểu và tối đa của một phần tử, bạn có thể thử chạy đoạn mã sau

Ví dụ

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            max-width: 300px;
            min-width: 100px;
            background-color: red;
         }
      </style>
   </head>
   <body>
      <p> Below is a div with maximum and minimum width. Resize the web browser to see the effect.</p>
      <div>This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text.
      </div>
   </body>
</html>

Đầu ra

Đặt chiều rộng tối thiểu và chiều rộng tối đa của một phần tử bằng cách sử dụng CSS