css,table如何平均行高?

html-css017

css,table如何平均行高?,第1张

两种情况:

列宽不固定:

不用设置隐藏, 设置table或table的父标签宽度, 因为会自适应宽度, 只要规定个高就可以了

table tr{

  height:      30px      /*把table标签的行高设定为固定值*/

}

2.   列宽固定:

  设置隐藏, 如果要设置table或table的父标签宽度, 因超过不会自适应宽度, 每行会折行而破坏宽度, 所以要设置隐藏

table tr{

  height:      30px      /*把table标签的行高设定为固定值, 高度根据自己需求设定*/

overflow:   hidden /*超过隐藏*/

}

给你2个解决方案:

1、使用table布局,好处就是td不会换行,不容易出错,3个td高度一直是一样的,所以可以再在里面套div;

举例:

<div style="height:130pxborder:1px solid redpadding-top:30px">

<table border="0" cellpadding="0" cellspacing="0" width="100%">

<tr>

<td style="width:33%">

<div style="background:redheight:100px"></div>

</td>

<td style="width:33%"><div style="background:#00ffffheight:100px"></div></td>

<td><div style="background:#33CC66height:100px"></div></td>

</tr>

</table>

</div>

2、小div宽度设定为百分比并且加浮动 float:left,如果你对div+Css布局不是很熟练,那么我建议你可以使用div+table+css布局,table布局对于处理很多棘手的问题还是蛮有用的

举例:

<div style="height:130pxborder:1px solid redpadding-top:30px">

<div style=" float:leftwidth:33%background:redheight:100px"></div>

<div style=" float:leftwidth:33%background:#00ffffheight:100px"></div>

<div style=" float:leftwidth:34%background:#33CC66height:100px"></div>

</div>

注:这个方法看似比较好用,但是实际写页面的时候会容易出现很多问题,你自己把握吧

1、首先需要打开sublimeText编辑器。

2、然后需要按照图示代码编写一个html页面,并且放入一张背景。

3、效果显示如下图,图片还是原来大小的背景。

4、然后需要按照图示代码利用css属性background-size: cover把整个背景填充。

5、效果显示如下图,图片table高度把屏幕占满。