Thuộc tính cột DOM HTML được sử dụng để thao tác với thuộc tính columnWidth và columnCount.
Sau đây là cú pháp cho -
Đặt thuộc tính cột -
object.style.columns = "auto|column-width column-count|initial|inherit"
Các giá trị thuộc tính trên được giải thích như sau -
| Giá trị | Mô tả |
|---|---|
| Tự động | Đặt chiều rộng cột và số cột thành tự động và là giá trị mặc định. |
| columnWidth | Xác định sai độ rộng của cột. |
| columnCount | Xác định sai số cột. |
| tên viết tắt | Đang xác thực thuộc tính này thành giá trị ban đầu. |
| kế thừa | Kế thừa giá trị thuộc tính mẹ |
Hãy để chúng tôi xem xét một ví dụ cho thuộc tính cột -
Ví dụ
<!DOCTYPE html>
<html>
<head>
<style>
#DIV1{
columns: 5rem auto;
}
img {
border: 1px solid brown;
}
</style>
<script>
function changeColumns(){
document.getElementById("DIV1").style.columns="10px 3";
document.getElementById("Sample").innerHTML="The columns are now modified";
}
</script>
</head>
<body>
<div id="DIV1">
<img src="https://www.tutorialspoint.com/images/xamarian.png"><br/>
<img src="https://www.tutorialspoint.com/images/pl-sql.png"><br/>
<img src="https://www.tutorialspoint.com/images/asp-net.png"><br/>
<img src="https://www.tutorialspoint.com/images/powerbi.png"><br/>
<img src="https://www.tutorialspoint.com/images/Tableau.png"><br/>
<img src="https://www.tutorialspoint.com/images/Big-Data-Analytics.png"><br/>
<img src="https://www.tutorialspoint.com/images/home_time_series.png"><br/>
<img src="https://www.tutorialspoint.com/images/microsoftproject.png"><br/>
</div>
<p>Change the above div columns property by clicking the below button</p>
<button onclick="changeColumns()">Change Columns</button>
<p id="Sample"></p>
</body>
</html> Đầu ra
Khi nhấp vào nút “ Thay đổi cột Nút ”-