How does html css fix the header? Does htmlcss fix the header?

Source: Internet
Author: User

How does html css fix the header? Does htmlcss fix the header?

When the position attribute is set to fixed, the position of the element is not affected by the scroll bar, but is located directly based on the window. This is the most direct method to fix the header, other ways on the Internet feel like detours. But at the same time, two problems must be solved. First, the table body will be located based on the body element instead of the header. Therefore, the table body will be moved up, causing the table body to be blocked by the header and have a shadow. Second, the wide height of the table body and the wide height of the table header are independent of each other and are no longer subject to the constraints of the Document Stream, which leads to uneven cell matching. The solution is as follows. You can set the percentage width of padding margin to solve the problem of upper and lower cell alignment. the header and table body can also be placed in their respective div. Style Sheet <style type = "text/css"> * {padding: 0px; margin: 0px;} # thead {/* fixed Header */position: fixed; /* The display level of the table header is higher than that of the table body to prevent duplicate shadows between blank rows and the table header */z-index: 2; background: # ecececff ;} # spacetr {/* blank tr is used to fill the data covered by the header */position: relative; z-index: 1 ;}. tdata {/* display the tr */position: relative; z-index: 1 ;}</style> js script $ (function () {$ ("# spacetr" ).css ("height", $ ("# thead" ..css ("height"); // set the height of the blank row to the height of the header, the distance between the blocked data and the height of the header}); jsp code: <div style = "width: 100%"> <% --  -- %> <table id =" table "border =" 1px gray solid "cellspacing =" 0 "cellpadding =" 0 "width =" 100%; "> <tr id =" thead "> <td width =" 9% "align =" center "> recruitment </td> <c: forEach items = "$ {postnames}" var = "postname"> <td valign = "bottom" align = "center" >$ {postname} </td> </c: forEach> </tr> <tr id = "spacetr"> <td width = "9%"> </td> <c: forEach items = "$ {postnames}" var = "postname"> <td> </c: forEach> </tr> <c: forEach items = "$ {shcoolsPostnumbers}" var = "schoolPostnumbers"> <tr class = "tdata"> <td width = "9%" >$ {schoolPostnumbers. key} </td> <c: forEach items = "$ {schoolPostnumbers. value} "var =" postnumber "> <td align =" center ">$ {postnumber} </td> </c: forEach> </tr> </c: forEach> </table> </div>

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.