JavaScript and CSS use expression to center Table display

Source: Internet
Author: User

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!

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.