html溢出宽度控制,html - 具有固定宽度列的HTML / CSS表(如果内容溢出,则滚动) - 堆栈内存溢出...
我有一個(gè)帶有一個(gè)或多個(gè)固定寬度列的HTML表。 有時(shí),此類(lèi)列的內(nèi)容超出了列的寬度,我想在表格列的底部使用一個(gè)滾動(dòng)條。
我想保持相同的語(yǔ)義HTML結(jié)構(gòu),并且沒(méi)有重復(fù)的表或多次迭代。
我想要盡可能少的JavaScript
如果可以的話(huà),我可以將其轉(zhuǎn)換為CSS Grid或Flexbox(但以前沒(méi)有使用過(guò))
我已經(jīng)注意到,HTML是一個(gè)colgroup ,看起來(lái)我可以設(shè)置width和其他CSS屬性,但不能overflow 。
First | Second long column item that should have scroll 1 | Last column item |
First | Second long column item that should have scroll 2 | Last column item |
First | Second long column item that should have scroll 3 | Last column item |
First | Second long column item that should have scroll 4 | Last column item |
First | Second long column item that should have scroll 5 | Last column item |
First | Second long column item that should have scroll 6 | Last column item |
.table {
table-layout: fixed;
border-collapse: collapse;
width: 100%;
}
.table-row {
box-shadow: 0 0 1px 1px yellowgreen;
}
.table-cell {
box-shadow: 0 0 1px 1px blue;
}
.table-colgroup--first {
background: palegoldenrod;
}
.table-colgroup--second {
background: paleturquoise;
/*
* I would like to pass the width of the column here
*/
width: 50px;
overflow-x: scroll;
}
.table-colgroup--third {
background: palegreen;
}
/* This is intentionally long so that a scrollbar appears somewhere */
.table-cell--second p {
width: 900px;
background: #666;
color: #fff;
}
請(qǐng)使用我嘗試過(guò)的代碼檢查我的Codepen示例: 代碼示例
總結(jié)
以上是生活随笔為你收集整理的html溢出宽度控制,html - 具有固定宽度列的HTML / CSS表(如果内容溢出,则滚动) - 堆栈内存溢出...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Adobe 全力冲刺生成式 AI,但员工
- 下一篇: 怎么修改谷歌浏览器文件提交按钮样式_使用