[英]How to horizontally center-align the content of a div by manipulating the CSS of the wrapper div only?
我有一個元素,這個元素有另一個元素,其中包含一個<table>
。
由於某些原因,我無法操縱內部<div>
或其中包含的<table>
的CSS。
我需要在外部<div>
的center
水平對齊 <table>
(或包含<table>
的內部<div>
,沒關系,我只需要顯示中心對齊的表),通過僅操作外部<div>
的CSS。
border
和padding
屬性似乎可以移動外部本身,我需要將其內容放置在其中心(水平)。 我怎樣才能做到這一點?
外部<div>
的寬度為590px
。
PS:我只能使用內聯CSS。
不能完全確定這是否滿足您的需求,但是桌上的簡單邊距規則似乎可以做到這一點( http://jsfiddle.net/tiesont/ujxh0mjj/1/ ):
#leftwrapper table
{
margin: auto;
}
將以下2條規則添加到您的leftWrapper div中:
display:flex;justify-content: center;
<div id="leftwrapper" style="width:590px;display:flex;justify-content: center; float:left; background-color:grey; overflow-y:auto; height:650px;">
將CSS應用於您的外部div:
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: - as per required;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.