Div table set height vertical center, horizontal center

Source: Internet
Author: User

Div table set height vertical center, horizontal center

Recently, when I was working on a project, I encountered a problem:DivWhen creating a table, you cannot center the table horizontally or vertically.

Vertical-align: middle; is used for vertical center, but floating gives it invalid.

It cannot be used because it is set to high.

How can vertical center be solved?

Add a label to li.

  <Script src = "js/jquery-1.7.2.min.js" type = "text/javascript" charset = "UTF-8"> </script>   

Zheng Xuan was not allowed to meet each other for three years under Ma Rong's door, and master students taught him. The disciples could not solve the problem.

Literature


If vertical center is solved, do you see

text-align: center;
Does not work?

Yes, because

display: table-cell;
Put P's
display: block;
It is equivalent
display: inline;

We can see that the width of p is actually

text-align: center;
It is not invalid, but the width is too small.

So how can we get it?

I think, if I change the width of P to the width of li, will it solve the problem of horizontal center?

I want to solve it with JS.

$(function(){var a=$(".liwidth").innerWidth();$("li p").css("width",a);});
Well, the solution is: for example, if your browser width is PX, you open this page and it is centered. If you do not refresh the page, stretch the browser width above 1001, so congratulations, It is not centered [helpless] Until (helpless) until it is stretched below 1000 is centered. Refresh it and it will adapt

<Script src = "js/jquery-1.7.2.min.js" type = "text/javascript" charset = "UTF-8"> </script> <Script type = "text/javascript"> // control the changes of the p tag following the change of the li width $ (function () {var a = $ (". liwidth "). innerWidth (); $ ("li p" ).css ("width", a) ;}); </script>

Zheng Xuan was not allowed to meet each other for three years under Ma Rong's door, and master students taught him. The disciples could not solve the problem.

Literature

Complete!


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.