Div加CSS如何对HTML的table表格定位
发表于:2026-11-04 作者:千家信息网编辑
千家信息网最后更新 2026年11月04日,这篇文章将为大家详细讲解有关Div加CSS如何对HTML的table表格定位,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。如果有一个元素div ,他的
千家信息网最后更新 2026年11月04日Div加CSS如何对HTML的table表格定位
这篇文章将为大家详细讲解有关Div加CSS如何对HTML的table表格定位,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
如果有一个元素div ,他的position属性设置为absolute,那么这个div 的位置取决于其父元素中position值设置为relative的元素。如果在其父元素中没有一个元素的position值是relative、absolute、或者fixed,那么这个div位置将以 body位置为参考。
但是对于某些浏览器来说似乎不是每个元素都遵从这一规则,有如下一段代码
CSS Code复制内容到剪贴板
table{ margin-left: 100px; margin-top: 50px; } td{ height: 150px; width: 100px; position: relative; } td div{ height: 30px; width: 50px; background-color: red; position: absolute; left: 10px; top:50px; }这是一个position:absolute元素
由于div元素的尺寸较小,理想的情况是div总是在最后一个td中,但是在firefox中div并不以td为参考,而是body。
所以要实现这个效果的兼容方式是在td中添加一个能应用position:relative的元素,上述代码可以更改为
XML/HTML Code复制内容到剪贴板
- 这是一个position:absolute元素
这样就可以保证 div元素始终在td中。
table的td相对定位实例
下面我们来看一个处理td相对定位的实例,这里我们建两个table样式:table和table2
CSS Code复制内容到剪贴板
.table,.table2 { overflow:hidden; } .table > .header { position:relative; height:40px; background-color:#84a9cc; } .header > .header-title { margin:0 auto;line-height:40px;color:#fff;width:80px;text-align: center;font-size:14px; } .header > .header-add { background-color: #488FD2; color: #FFFFFF; cursor: pointer; height: 20px; line-height: 20px; padding: 10px; position: absolute; rightright: 0; text-align: center; top: 0; width: 45px; } .header > .header-search { background-color: #fff; height: 30px; line-height: 20px; position: absolute; rightright: 80px; text-align: center; top: 5px; width: 200px; } .table > .body,.table2 > .body { border: 1px solid #BCC6D0;/border-style:none solid solid solid;/background-color:#fff; } .header-search > input { border:none; border-right: 1px solid #BCC6D0; color: #666666; font-size: 14px; height: 100%; line-height: 100%; width: 170px; float:left; } .header-search > .search-logo { float:left;width:29px;height:30px; background:url(…/…/images/global/serachBlue.png) center no-repeat; } tbody > .tr { height:20px;line-height:20px; } th { display:inline-block;margin-right:-3px; } th + th { margin-left:-3px; } td { padding:10px 0;display: inline-block;margin-right: -3px; } td + td { margin-left: -3px; } tbody > .tr:nth-child(2n+1) { background-color:#e6e5e5; } .table2 tbody > .tr:nth-child(2n+1) { background-color:#fff; } .ml30 { margin-left:30px; } .tr .checkbox { width:20px;border:1px solid #BCC6D0;height:20px;cursor:pointer;float:left; } .tr .checkbox.selected { background-color:#488FD2; } .tr .checkbox > input[type=‘checkbox’] { display:none; } table.body,table2.body { width:100%; overflow-y:auto; } .body { margin:0; } td, td div { font-size:14px;text-align: center; } .canClick { color:#2E5CB9;cursor:pointer; } .btn { background-color: #488FD2; color: #FFFFFF; cursor: pointer; font-size: 14px; padding: 6px 10px; } .line > .submit { float:rightright;padding:10px 25px; } .btnPush > .tagRight { background: url("…/…/images/global/smallGotoRight.png") no-repeat scroll center center #9EC5EB; float: left; height: 85px; width: 8px; } .opcity5 { opacity:0.5; filter:alpha(opacity=50); } .search { background-color: #FFFFFF; height: 30px; line-height: 20px; text-align: center; width: 210px; } .search > input { border:none; border: 1px solid #BCC6D0; color: #666666; font-size: 14px; height: 28px; line-height: 100%; width: 170px; float:left; } .search > .search-logo { float:left;width:29px;height:30px; background:url(…/…/images/global/searchWhite.png) center no-repeat #488FD2; } .tableRight { float:left;margin-left:20px;width: 962px; } .btnLeft { float:left; } th { font-size: 14px; font-weight: normal; line-height: 35px; height:35px; } .textl { text-align: left; } .table2 td { border-top:1px solid #BCC6D0; } .hoverTag { cursor:pointer;position: relative; } .titTag { min-width:135px;height:50px;display:none;position:absolute; } .titTag > .titTag-left, .titTag > .titTag-msg { float:rightright; } .titTag > .titTag-left { width:15px; height:100%; } .titTag > .titTag-msg { background-color:#fcffe0;min-width:119px;border:1px solid #BCC6D0;height:48px;text-align:left; }
关于Div加CSS如何对HTML的table表格定位就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
元素
内容
定位
位置
剪贴板
剪贴
参考
表格
代码
实例
文章
是在
更多
知识
篇文章
这是
不错
两个
取决于
尺寸
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
咖啡豆
互联网佳科技有限公司
关于新基建和互联网科技
米客互联网科技
互联网科技公司介绍
多迪互联网科技有限公司
重庆科技学院互联网
中盈科技互联网信息有限公司
深圳国际航运科技和互联网
承德科技产业互联网发展
移动互联网科技股
互联网科技与大数据专业
辽宁互联网新科技
中科明德北京互联网科技
科技互联网海报
万物互联网智能科技
互联网金融运营模式中的金融科技
互联网科技职业技能培训学校
互联网的科技体现在哪里
颐高云石互联网科技
互联网科技图片
广州紫鲸互联网科技有限公司
合肥互联网科技公司
上游互联网科技
互联网科技教育视频
苏州五指互联网络科技有限
翼展科技 首家互联网医院
互联网金融科技元年
数字互联网科技有限公司
利用互联网等科技手段