如何定位表格 HTML?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10610963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Position a table HTML?
提问by Harry Esses
I am trying to have the table lower and more to the right to were it originally is. How can i do this? What are the attributes? Thanks!
我试图把桌子放得更低,更靠右一点,原来是这样。我怎样才能做到这一点?属性是什么?谢谢!
回答by Brendan Cutajar
You would want to use CSS to achieve that.
你会想要使用 CSS 来实现这一点。
say you have a table with the attribute id="my_table"
假设你有一个属性为 id="my_table" 的表
You would want to write the following in your css file
您可能希望在 css 文件中写入以下内容
#my_table{
margin-top:10px //moves your table 10pixels down
margin-left:10px //moves your table 10pixels right
}
if you do not have a CSS file then you may just add margin-top:10px, margin-left:10px
to the style attribute in your table element like so
如果您没有 CSS 文件,那么您可以margin-top:10px, margin-left:10px
像这样添加到表格元素中的 style 属性
<table style="margin-top:10px; margin-left:10px;">
....
</table>
There are a lot of resources on the net describing CSS and HTML in detail
网上有很多资源详细描述了 CSS 和 HTML
回答by Hawken
As BalausC mentioned in a comment, you are probably looking for CSS (Cascading Style Sheets) not HTML attributes.
正如 BalausC 在评论中提到的,您可能正在寻找 CSS(级联样式表)而不是 HTML 属性。
To position an element, a <table>
in your case you want to use either padding or margins.
要定位元素,<table>
在您的情况下,您要使用填充或边距。
the difference between margins and paddings can be seen as the "box model":
margins 和 paddings 的区别可以看成是“盒子模型”:
Image from HTML Dog article on margins and padding http://www.htmldog.com/guides/cssbeginner/margins/.
图片来自 HTML Dog 文章中的边距和填充http://www.htmldog.com/guides/cssbeginner/margins/。
I highly recommend the article above if you need to learn how to use CSS.
如果您需要学习如何使用 CSS,我强烈推荐上面的文章。
To move the table down and right I would use margins like so:
要向下和向右移动表格,我会使用这样的边距:
table{
margin:25px 0 0 25px;
}
This is in shorthand so the margins are as follows:
这是简写,所以边距如下:
margin: top right bottom left;