简体   繁体   English

对齐 div 元素(css、html)

[英]Aligning div elements (css, html)

I'm a beginner when it comes to HTML and CSS and I'm struggling to position some div elements as described in the image intended outcome .我是 HTML 和 CSS 的初学者,我正在努力按照图像预期结果中的描述定位一些 div 元素。 I've centered the table with margin-left: auto and margin-right: auto .我用margin-left: automargin-right: auto将表格居中。 I want the text div-element to be aligned right above the table.我希望文本div 元素在表格的正上方对齐。 Is there any good way to do that?有什么好的方法可以做到这一点吗?

Any help is much appreciated.任何帮助深表感谢。

Put them both in another div that will be centered inside the box将它们都放在另一个 div 中,该 div 将在框内居中

Set the table width and the div width.设置表格宽度和 div 宽度。

<div id="wrapper-div" style="margin:auto; width:XXpx">
    <div id="text-div" style=""></div>
    <div id="table-div"></div>
</div>

The wrapper div should have the same width as the table div.包装器 div 应与表 div 具有相同的宽度。

有很多方法可以做到这一点,当您尝试时,您可以尝试添加以下 css 样式:

 display:inline-block

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM