Html 无法设置桌子高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17351545/
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
Not able to set table height
提问by Parag Phadtare
I have a simple html table I am not able to set the height for this table
我有一个简单的 html 表格我无法设置这张表格的高度
Am i missing something
我错过了什么吗
<table border="1" id="abc1" height="10px;" >
<tr><td><b>Name</b></td></tr>
<tr><td><b>Name</b></td></tr>
<tr><td><b>Name</b></td></tr>
<tr><td><b>Name</b></td></tr>
</table>
回答by Godric Gryffindor
Place table inside a div and give height to that div.
将 table 放在 div 内并为该 div 指定高度。
回答by Optox
Both border and height, which you're trying to set, are actually CSS attributes, not HTML. Set them in the following way:
您要设置的边框和高度实际上是 CSS 属性,而不是 HTML。按以下方式设置它们:
<table id="abc1" style="border: 1px; height:10px;" >
<tr><td><b>Name</b></td></tr>
<tr><td><b>Name</b></td></tr>
<tr><td><b>Name</b></td></tr>
<tr><td><b>Name</b></td></tr>
</table>
Or, alternatively, you can use a linked CSS style sheet like this:
或者,您也可以使用链接的 CSS 样式表,如下所示:
#abc1 {
border: 1px;
height: 10px;
}
Just to let you know, setting the height of the table element sets the height of each row, if you want to set the height of the whole table, put the table in div tags and set the height of that element.
What are you missing? you're missing the concept of styling with CSS, try this tutorial: HTMLdog.com
只是为了让您知道,设置表格元素的高度会设置每行的高度,如果要设置整个表格的高度,请将表格放在 div 标签中并设置该元素的高度。
你缺少什么?你缺少 CSS 样式的概念,试试这个教程:HTMLdog.com
回答by Dávid Horváth
Firstly you need to know which html renderer will render your html code. Visit this site: http://www.campaignmonitor.com/css/, after this you can decide which solution is better.
首先,您需要知道哪个 html 渲染器将渲染您的 html 代码。访问此站点:http: //www.campaignmonitor.com/css/,在此之后您可以决定哪种解决方案更好。
1) Use inline-css for your table tag like this:
1) 使用 inline-css 作为您的表标签,如下所示:
<table style="height:50px;"></table>`
2) Use an internal style sheet for your table tags like this:
2)为您的表格标签使用内部样式表,如下所示:
<head>
<style>
table { height:50px; }
p { color:blue; }
</style>
</head>
3) Use an external style sheet like this and give a height value for the table like this:
3)使用这样的外部样式表,并为表格提供一个高度值,如下所示:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Or you can give a value for the td elements and then the table will automatically figure out it's size.
或者您可以为 td 元素提供一个值,然后表格将自动计算出它的大小。
Example: if you work on an html email you can't use external css. You need to solve it with inline-css (solution 1 above). If it's not supported you are still able to do it in the td tags.
示例:如果您处理 html 电子邮件,则不能使用外部 css。您需要使用 inline-css 解决它(上面的解决方案 1)。如果它不受支持,您仍然可以在 td 标签中进行。
回答by biozes
I just solved a similar problem.
我刚刚解决了一个类似的问题。
For this I used the line-height property for setting each element of table's size.
为此,我使用 line-height 属性来设置表格大小的每个元素。
Also, here you can find more information: http://www.w3schools.com/cssref/pr_dim_line-height.asp
此外,在这里您可以找到更多信息:http: //www.w3schools.com/cssref/pr_dim_line-height.asp
Here is it's usage:
这是它的用法:
<table style='line-height: 3px'>
Also you can use percentages instead of absolute values.
您也可以使用百分比而不是绝对值。
回答by Godric Gryffindor
The following code works:
以下代码有效:
table{
height: 86px;
display: inline-block;
overflow-y: scroll;
}