In the previous blog, we set div to center display. Today we will share how to center the table. As for the principle of center, let's not talk about it. Let's take a look at my previous blog. Instead of using two windows events this time, we use a function called expression. Most browsers now support this function. When I wrote my previous blog, I thought I could not assign the calculated value to the left and top attributes of css? Later, I found this function. This function is used to associate CSS attributes with JavaScript expressions. the CSS attributes here can be inherent attributes of elements or custom attributes. That is to say, the CSS attribute can be followed by a JavaScript expression, and the value of the CSS attribute is equal to the result of JavaScript. You can directly reference attributes and methods of an element in an expression, or use other browser objects. This expression is like a member function in this element.
Let's take a look at the center source code first!
We can clearly see that the value written in the expression function is the sum formula. That is, the document's height and width minus its own height and width, and then divide by 2 is the top and left values. Place the code in the style attribute to center the code. :
In this way, the center is displayed.
Would you like to write this code into css? The answer is yes, so the code becomes like this:
In this way, the table can be displayed in the center through CSS and JavaScript, so that the login page will look good. Easy!