Home >Web Front-end >HTML Tutorial >(Transfer) DIV CSS layout tutorial: using ul and li to implement table format_html/css_WEB-ITnose
Let’s first analyze how to make it: li has a fixed width and height (cell). Set li to float in ul. When ul is not wide enough, li will automatically be arranged in a new row. (The width of ul can be obtained by calculating how many columns there are in a row. For example, if there are four columns in a row and one column is 100px wide, then the width of ul is 400px plus a certain margin). This achieves an effect similar to a table, or we use UL LI to simulate the effect of a table. Let’s start writing HTML code:
Example Source Code [www.52css.com]
Example Source Code [www.52css.com]
#biaoge {
width:405px;
margin :50px auto;
}
The CSS code of ul whose ID is biaoge, the width is 405px (one column 100px*4 column li margins), the top and bottom margins are 50px, and the left and right margins are automatic , to achieve horizontal center alignment.
#biaoge li,#biaoge li.biaotou {
list-style-type:none;
width:100px; height:30px;
line-height:30px;
text-align:center;
float:left;
Define the style of each list item li (i.e. cell), set the default mark of the list item to None, the width and height are 100px and 30px respectively. In order to center the text vertically in the li, set the line height to 30px. The text is centered horizontally. Set it to float to the left, and the left margin and bottom margin are both 1px, achieving the effect of a simple table line. (If the table line is designed as a border, many CSS HACKs are difficult to control and adjust, especially in FF, which is extremely abnormal. It is not recommended to use border to implement this type of ulli definition of table lines!) Set the background color to light gray# ccc.
Example Source Code [www.52css.com]
#biaoge li.biaotou {
background:#999;
}