Javascript 将从外部php文件创建的项目居中
我有一张表格,我想放在我的网页上。html文件从php文件加载一个表,但由于某些原因,即使使用中心块作为类(使用引导),也不会发生任何事情。这张桌子装载得很好,只是没有居中 HTML:Javascript 将从外部php文件创建的项目居中,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一张表格,我想放在我的网页上。html文件从php文件加载一个表,但由于某些原因,即使使用中心块作为类(使用引导),也不会发生任何事情。这张桌子装载得很好,只是没有居中 HTML: $(文档).ready(函数(){ $(“.mytable”).load('pastmoods.php'); }); PHP: $query=mysqli\u query($db\u connection,“SELECT*FROM DemoUser”); $fields\u num=mysqli\u num\
$(文档).ready(函数(){
$(“.mytable”).load('pastmoods.php');
});
PHP:
$query=mysqli\u query($db\u connection,“SELECT*FROM DemoUser”);
$fields\u num=mysqli\u num\u fields($query);
回声“过去的情绪:{$table}”;
回声“;
//打印表格标题
对于($i=0;$i您可以为div使用固定宽度,并使用文本中心引导类,而不是内联样式。echo”“;
echo "<table border='1' align='center' width='xxx'><tr>";
试试这个
按照@Aashray的建议进行编辑。完全不要使用中心。坚持使用css。将表格放在一个“div”或“span”中,并使用css将其居中,确保您已经设置了Sachi上面提到的边距。您的表格是左浮动还是右浮动?这可能是个问题。确保它有浮动:无浮动,或者根本没有浮动
此外,请确保表的父元素有空间使表居中。例如,如果表及其父元素的内部宽度相同,则表将没有空间居中
确保表格不是宽度:100%,因为它将适合其父级,而无需居中。我想您需要CSS:
.mytable.center-block {
margin: 0 auto;
}
这取决于您尝试过的margin:0 auto;
?哈哈…您可以在之间添加
标记。myTable
的
。试试吧..或者共享您的CSS代码。您可能应该避开内部双引号。
echo "<table border='1' align='center' width='xxx'><tr>";
.mytable.center-block {
margin: 0 auto;
}
<div class="parent-div">
<div class="mytable center-block"></div>
</div>
.parent-div {
width: 1000px; /* Let's say for this example the parent-div is 1000px wide */
height: 400px; /* Some height, just to give it dimension */
}
.mytable.center-block {
margin: 0 auto; /* Centers the table within the parent-div */
}