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!