给表格加滚动条的思路

<html>
<head>
<title>My table</title>
<style>
.table0 {
	height:90%;
}

.table0 caption{
	width:100%;
	height:26px;
	line-height:26px;
	font-size:20px;
	font-color:black;
	font-weight:900;
	letter-spacing:5px;
}

.table0 thead td {
	text-align:center;
	vertical-align:middle;
	height:20px;
	line-height:18px;
	font-size:14px;
	font-color:black;
	font-weight:bold;
	padding-top:2px;
	padding-bottom:2px;
	border:#555 1px solid;
	margin:0px;
}

.table0 tfoot td{
	text-align:left;
	vertical-align:middle;
	height:20px;
	line-height:18px;
	font-size:12px;
	font-color:black;
	font-weight:bold;
	padding-top:2px;
	padding-bottom:2px;
	padding-left:12px;
	padding-right:12px;
	border:#555 1px solid;
}

.table0 tbody td {
	width:100%;
	height:auto;
	border:#555 1px solid;
	padding:0px;
	margin:0px;
}

.table1 tbody td {
	text-align:left;
	vertical-align:middle;
	height:20px;
	line-height:18px;
	font-size:14px;
	font-color:#444;
	font-weight:normal;
	padding-top:2px;
	padding-bottom:2px;
	padding-left:12px;
	padding-right:12px;
	border-right:#555 1px solid;
	border-bottom:#555 1px solid;
	overflow:hidden;
	text-overflow:ellipsis;
	word-break:keep-all;
	word-wrap:normal;
}

</style>
<script>

function init(){
	theT=createTable("我的收藏夹",["Group:150","Name:300","URL:200","Visited:100","Modify:100","Delete:100"]);
	//参数说明:createTable(strCaption,colHeads)
	//strCaption 标题
	//colHeads 是一个array,每个item的格式是 名称:宽度 的字符串
	for(var i=0;i<40;i++){
		theR=theT.insertRow();
		for(var j=0;j<7;j++){
			theC=theR.insertCell();
			theC.innerText=j;
		}
	}
}


function createTable(strCaption,colHeads){
	//参数说明:colHeads 是一个array,每个item的格式是 名称:宽度 的字符串
	//生成表格
	oTable=document.createElement("table");
	document.body.insertBefore(oTable);
	//设置class
	oTable.className="table0";
	
	with(oTable.style){
		tableLayout="fixed";
		borderCollapse="collapse"
		borderSpacing="0px";
	}
	//设置变量
	oTCaption=oTable.createCaption();
	oTHead=oTable.createTHead();
	oTFoot=oTable.createTFoot();
	
	//生成标题
	oTCaption.innerText=strCaption;
	
	//设置列宽
	oTHead.insertRow();
	for(var i=0;i<colHeads.length;i++){
		tHeadName=colHeads[i].split(":")[0];
		tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
		theCell=oTHead.rows[0].insertCell();
		theCell.style.width=tHeadWidth;
	}
	theCell=oTHead.rows[0].insertCell();
	theCell.width=20;
	oTHead.rows[0].style.display="none";
	
	//生成表头
	oTHead.insertRow();
	for(var i=0;i<colHeads.length;i++){
		tHeadName=colHeads[i].split(":")[0];
		tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
		theCell=oTHead.rows[1].insertCell();
		theCell.innerText=tHeadName;
		theCell.style.width=tHeadWidth;
	}
	theCell=oTHead.rows[1].insertCell();
	theCell.width=24;
	
	//生成表脚
	oTFoot.insertRow();
	theCell=oTFoot.rows[0].insertCell();
	theCell.innerHTML="<marquee scrollDelay=50 scrollAmount=2>Copy rights 2005. Hutia presents.</marquee>";
	theCell=oTFoot.rows[0].insertCell();
	theCell.colSpan=colHeads.length-1;
	theCell=oTFoot.rows[0].insertCell();
	theCell.width=20;
	
	//生成主体
	oTable.all.tags("Tbody")[0].insertRow();
	theCell=oTable.all.tags("Tbody")[0].rows[0].insertCell();
	theCell.colSpan=colHeads.length+1;
	oMain=document.createElement("DIV");
	theCell.insertBefore(oMain);
	with(oMain.style){
		width="100%";
		height="100%";
		overflowY="auto";
		overflowX="hidden";
		margin="0px";
		marginLeft="-1px";
	}
	
	oTBody=document.createElement("table");
	oMain.insertBefore(oTBody);
	oTable.oTBody=oTBody;
	//禁止选择
	oTCaption.onselectstart=oTHead.onselectstart=oTFoot.onselectstart=function(){return(false);}
	
	//设置class
	oTBody.className="table1";
	with(oTBody.style){
		width=oTable.offsetWidth-15;
		tableLayout="fixed";
		borderCollapse="collapse"
		borderSpacing="0px";
		padding="0px";
		margin="0px";
	}
	
	//初始化列宽
	oTBody.insertRow();
	for(var i=0;i<colHeads.length;i++){
		tHeadWidth=isNaN(parseInt(colHeads[i].split(":")[1]))?"auto":parseInt(colHeads[i].split(":")[1]);
		theCell=oTBody.rows[0].insertCell();
		theCell.style.width=tHeadWidth;
	}
	oTBody.rows[0].style.display="none";
	
	return(oTBody);
}

function insertRow(){
	var intL=oTBody.rows.length;
	theRow=oTBody.insertRow();
	theRow.index=intL;
	theRow.οnmοuseοver=rowOnMouseOver;
	theRow.οnmοuseοut=rowOnMouseOut;
	theRow.οnclick=rowOnClick;
	for(var i=0;i<colHeads.length;i++){
		theCell=theRow.insertCell();
		theCell.tabIndex=0;
		theCell.hideFocus=true;
		theCell.colIndex=i;
		theCell.οnmοuseοver=function(){this.focus();};
		theCell.οnmοuseοut=cellOnBlur;
		theCell.οnfοcus=cellOnFocus;
		theCell.οnblur=cellOnBlur;
	}
	theRow.cells[0].innerText=strGroup?strGroup:"ROOT";
	theRow.cells[1].innerText=strName?strName:"Untitled Document.";
	theRow.cells[2].innerText=strURL?strURL:"Unspecified URL";
	theRow.cells[3].innerHTML=strVisited?"Yes".fontcolor("red"):"Unknow";
	theRow.cells[4].innerHTML=strModify?"Yes".fontcolor("red"):"No".fontcolor("Green");
	theRow.cells[5].innerHTML="Delete".fontcolor("red");
}

</script>
</head>
<body οnlοad="init();">

</body>
</html>

 

<think>我们正在使用ElementUI的el-table组件,并希望修改其滚动条样式,特别是使其粗。根据提供的引用,我们可以通过CSS样式覆盖来实现。主要思路是使用/deep/或>>>来深度选择el-table内部的滚动条元素,并修改其样式。关键点:1.找到滚动条对应的CSS类。根据引用,我们知道el-table的滚动条位于`.el-table__body-wrapper`元素内。2.修改横向和纵向滚动条的宽度(或高度)以实现粗效果。3.同时,我们可能需要调整滚动条的轨道和滑块的样式,以确保美观。根据引用[1]和引用[2],我们可以通过以下方式修改:-纵向滚动条:设置`.el-table__body-wrapper::-webkit-scrollbar`的`width`属性(纵向滚动条的宽度)和`height`属性(横向滚动条的高度)。-横向滚动条:设置`height`属性(横向滚动条的高度)和`width`属性(纵向滚动条的宽度,但横向滚动条中这个属性可能不重要,不过通常一起设置)。注意:引用[1]中直接修改了`.el-scrollbar`的样式,但el-table内部使用的是`.el-table__body-wrapper`,所以我们应该针对这个类来修改。步骤:1.在全局样式文件或当前组件的样式块中(如果使用scoped,则需要使用/deep/或>>>)添样式。2.使用`::-webkit-scrollbar`伪元素选择器来修改滚动条样式。示例代码(使纵向滚动条宽度为14px,横向滚动条高度为14px,从而达到粗效果):```css/*修改滚动条整体样式*//deep/.el-table__body-wrapper::-webkit-scrollbar{width:14px;/*纵向滚动条的宽度*/height:14px;/*横向滚动条的高度*/}/*修改滚动条滑块*//deep/.el-table__body-wrapper::-webkit-scrollbar-thumb{background-color:#909399;/*滑块颜色*/border-radius:7px;/*滑块圆角,为了与粗的滚动条匹配,可以设置为宽度的一半*/opacity:0.6;/*不透明度,可根据需要调整*/}/*修改滚动条轨道*//deep/.el-table__body-wrapper::-webkit-scrollbar-track{background:#f5f5f5;/*轨道背景色*/border-radius:7px;/*轨道圆角*/}```注意:由于不同浏览器的兼容性问题,上述样式主要针对Webkit内核的浏览器(如Chrome、Safari等)。在Firefox中,可以使用`scrollbar-width`和`scrollbar-color`属性,但ElementUI的滚动条在Webkit内核浏览器中更常见。另外,引用[3]和引用[4]提供了更详细的样式定制,包括轨道和滑块的内阴影等,可以根据需要添。如果还需要调整滚动条的位置(如引用[1]中使用了top和left),可以在`.el-table__body-wrapper::-webkit-scrollbar`中调整,但通常不需要。最后,如果修改后样式没有生效,请检查选择器是否正确,以及是否因为scoped的原因需要深度穿透。根据用户需求,我们主要实现粗,所以将滚动条的宽度和高度设置为较大的值(如14px)即可。完整示例:```css<stylescoped>/*使用scoped时,需要深度穿透*//deep/.el-table__body-wrapper::-webkit-scrollbar{width:14px;/*纵向滚动条宽度粗*/height:14px;/*横向滚动条高度粗*/}/deep/.el-table__body-wrapper::-webkit-scrollbar-thumb{background-color:#c1c1c1;border-radius:7px;}/deep/.el-table__body-wrapper::-webkit-scrollbar-track{background:#f0f0f0;border-radius:7px;}</style>```注意:实际项目中,可能需要根据表格的具体情况调整颜色和圆角等,以达到最佳视觉效果。相关问题:1.如何修改ElementUI中el-table滚动条的颜色?2.如何调整el-table滚动条的位置?3.el-table滚动条样式在Firefox浏览器中如何兼容?</think>### Element UI el-table 滚动条粗自定义样式 在 Element UI 的 `el-table` 组件中,修改滚动条样式使其粗需要通过 CSS 覆盖原生样式。以下是具体实现方法: #### 核心步骤 1. **定位滚动条元素** 使用 `::webkit-scrollbar` 伪元素选择器定位滚动条,通过 `!important` 覆盖默认样式。 2. **调整滚动条尺寸** - 纵向滚动条:增 `width` 值 - 横向滚动条:增 `height` 值 3. **优化视觉效果** 配合圆角(`border-radius`)和背景色,使滚动条更美观。 #### 完整代码示例 ```css /* 容器样式 */ .el-table { /* 确保滚动条可见 */ overflow: auto; } /* 滚动条轨道 */ .el-table__body-wrapper::-webkit-scrollbar { width: 14px !important; /* 纵向滚动条粗 */ height: 14px !important; /* 横向滚动条粗 */ } /* 滚动条滑块 */ .el-table__body-wrapper::-webkit-scrollbar-thumb { background-color: #909399 !important; /* 滑块颜色 */ border-radius: 7px !important; /* 圆角匹配粗尺寸 */ opacity: 0.8 !important; } /* 滚动条轨道背景 */ .el-table__body-wrapper::-webkit-scrollbar-track { background: #f5f7fa !important; /* 轨道背景色 */ border-radius: 7px !important; } /* 修复表头右侧空白区域 */ .el-table__cell.gutter { background: #f5f7fa !important; /* 与轨道颜色一致 */ } ``` #### 关键参数说明 | 参数 | 作用 | 推荐值 | |-------------------|-------------------------------|--------| | `width` | 纵向滚动条宽度 | 12-16px | | `height` | 横向滚动条高度 | 12-16px | | `border-radius` | 滑块圆角 (建议设为宽度的一半) | 6-8px | | `background-color`| 滑块颜色 | 建议使用 Element 的灰色系 | #### 浏览器兼容性说明 1. **仅支持 Webkit 内核浏览器**(Chrome/Safari/Edge) 2. Firefox 需使用标准属性: ```css .el-table { scrollbar-width: thick; /* auto | thin | none */ scrollbar-color: #909399 #f5f7fa; } ``` > **注意事项**: > - 使用 `!important` 确保样式覆盖优先级 > - 圆角值建议为滚动条宽度的一半 > - 修改后需检查表格内容是否被遮挡(可调整 `padding`)[^1][^2][^3] --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值