CSS自定义WEB控件

WEB开发有时需要自定义控件,这样更好看,网上已经有很多,收集如下,很多都用到CSS3的功能,下面就列举滚动条,下拉列表,复选框,单选钮进行举例,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>scrollBar</title>
<style type="text/css">
/*==============ScrollBar style==============*/
div.div02{width:300px; height:300px; overflow:scroll; overflow-x:hidden; border:0px solid blue; 
padding:20px; font-family: "Microsoft Yahei"; font-size:14px;
/*--ie core--*/
scrollbar-3dlight-color:#D4D0C8; /*- 最外左 -*/
scrollbar-highlight-color:#fff; /*- 左二 -*/
scrollbar-face-color:#E4E4E4; /*- 面子 -*/
scrollbar-arrow-color:#666; /*- 箭头 -*/
scrollbar-shadow-color:#808080; /*- 右二 -*/
scrollbar-darkshadow-color:#D7DCE0; /*- 右一 -*/
scrollbar-base-color:#D7DCE0; /*- 基色 #D7DCE0 transparent -*/
scrollbar-track-color:transparent;/*- 滑道 -*/
}

/*--webkit core--*/
/* 设置滚动条的样式 */
::-webkit-scrollbar {
    width: 15px;
}
/* 滚动槽 */
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    border-radius: 0px;
	background-color:rgba(110,110,110,1);
	padding:5px 0px;
}
/*定义上下公共按钮的样式*/
::-webkit-scrollbar-button {
	border-radius: 0px;
    background: rgba(110,110,110,1); 
	margin:3px 0px;
	padding:3px 0px;
    /* background-image: url(Images/bgpic01.gif) */
}
	
/*定义增加箭头的样式*/	
::-webkit-scrollbar-button:vertical:increment { 
    background-image: url(Images/up-down-arrow.png);
    background-repeat: no-repeat;
    background-position: center -17px;
}
	
/*定义减少箭头的样式*/	
::-webkit-scrollbar-button:vertical:decrement { 
    background-image: url(Images/up-down-arrow.png);
    background-repeat: no-repeat;
    background-position: center 0px;
}

/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
    border-radius: 6px;
    background: rgba(195,195,195,1); 
    -webkit-box-shadow:intset 0px 0px 6px rgba(0,0,0,0.6); 
}

::-webkit-scrollbar-thumb:window-inactive {
    /* background-color: red; */
}

/*==============combox button style==============*/
select { background-image:url(Images/ComboBoxBG.png.gif); background-color:transparent; background-repeat: no-repeat; 
line-height: 30px; border-radius: 4px; box-shadow: 0px 1px 2px rgba(255,255,255,1); height: 30px; -webkit-appearance: none;
 -moz-appearance: none; padding-right: 34px; background-position: right top; border-left: 1px solid #8d8d8d; 
border-top-style: none; border-right-style: none; border-bottom-style: none; width: auto; min-width:100px;}
select:hover {background-position:right -32px;} /*修改自定义图片的位置*/
select:disabled {background-position:right -64px;}
select:focus {background-position:right -96px; border-color:1px solid #CCC;}

select > option { border: 6px solid black; box-shadow: 0px 1px 2px rgba(0,0,0,0.5); -webkit-appearance: none; 
background-color: #5a5a5a; opacity: 0.1; line-height: 30px; height: 30px; color: #FFF; }
select > option:hover { background: #94a2a2 url(none); color: #666666; }

/*==============Check button style==============*/
label.CheckboxButton { line-height:30px; height:30px; text-align:left; vertical-align:top; font-size:14px; 
font-family: "Microsoft Yahei",verdana,arial;}
input[type="checkbox"] { appearance:none; -webkit-appearance:none; -ms-appearance:none; -moz-appearance:none; 
-o-appearance:none; background:url(Images/CheckBox.png) no-repeat 0px 0px; width:20px; height:30px; margin:0px; 
padding:0px; cursor:pointer; color:#2c2d2e; border:0px; line-height:30px; display:inline-block;}
input[type="checkbox"]:hover { background-position:0px -30px;} /*修改自定义图片的位置*/
input[type="checkbox"]:checked { background-position:0px -60px;}
input[type="checkbox"]:disabled { background-position:0px -90px;}

/*==============Radio button style==============*/
label.RadioButton { line-height:30px; height:30px; text-align:left; vertical-align:top; font-size:14px; 
font-family: "Microsoft Yahei",verdana,arial;}
input[type="radio"] { appearance:none; -webkit-appearance:none; -ms-appearance:none; -moz-appearance:none; 
-o-appearance:none; background:url(Images/RadioButton.png) no-repeat 0px 0px; width:20px; height:30px; 
margin:0px; padding:0px; cursor:pointer; color:#2c2d2e; border:0px; line-height:30px; display:inline-block;}
input[type="radio"]:hover { background-position:0px -30px;} /*修改自定义图片的位置*/
input[type="radio"]:checked { background-position:0px -60px;}
input[type="radio"]:disabled { background-position:0px -90px;}
</style>
</head>
<body>
<p class="title01">
User define scrollBar,combox, checkbox, radio button style
</p>
<p>
<div id="div02" class="div02">
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
<p>自定义滚动条.......</p>
</div>
</p>
<p>
<select name="select1" id="select1">
<option value="item1" selected="selected">selected item1</option>
<option value="item2">item2</option>
<option value="item3">item3</option>
<option value="item4">item4</option>
<option value="item5">item5</option>
<option value="item6">item6</option>
</select>
</p>

<p>
<label for="CheckboxGroup1_0" class="CheckboxButton">
<input type="checkbox" name="CheckboxGroup1" value="复选框1" id="CheckboxGroup1_0" />复选框1 
</label>
<label for="CheckboxGroup1_1" class="CheckboxButton">
<input type="checkbox" name="CheckboxGroup1" value="复选框2" id="CheckboxGroup1_1" />复选框2
</label>
<br />
<label for="CheckboxGroup1_3" class="CheckboxButton">
<input type="checkbox" name="CheckboxGroup1" value="复选框3" id="CheckboxGroup1_3"/>复选框3
</label>
<label for="CheckboxGroup1_4" class="CheckboxButton">
<input type="checkbox" name="CheckboxGroup1" value="复选框4" id="CheckboxGroup1_4" disabled="disabled" />复选框4  [disabled]
</label>
<br />
</p>


</p>
<form name="form1" id="form1" action="#">
<p>
<label for="shuiguo" class="RadioButton"><input type="radio" name="shuiguo" id="shuiguo" value="shuiguo1"/> 水果1 </label>
<label for="shuiguo2" class="RadioButton"><input type="radio" name="shuiguo" id="shuiguo2" value="shuiguo2" />水果2 </label>
<label for="shuiguo3" class="RadioButton"><input type="radio" name="shuiguo" id="shuiguo3" value="shuiguo3" />水果3</label>
<label for="shuiguo4" class="RadioButton"><input type="radio" name="shuiguo" id="shuiguo4" value="shuiguo4" disabled="disabled"/>水果4 [disabled] </label>
</p>
</body>
</html>

图片可以自己根据需要绘制,同时需要注意位置跟CSS中的定义一致即可。

//更新一下新效果的webkit引擎下的scrollbar样式,

/* start: webkit core 设置滚动条的样式 */
::-webkit-scrollbar {width:10px;}
::-webkit-scrollbar:horizontal{ height:10px;}
::-webkit-scrollbar-track { 
    border-radius: 0px;
	background-color:#6e6e6e;
	padding:5px 0px;
}
::-webkit-scrollbar-button {
	border-radius: 0px;
	-ms-border-radius: 0px;
	-webkit-border-radius: 0px;
	-moz-border-radius: 0px;
	-o-border-radius: 0px;
	margin:3px 0px;
	padding:3px 0px;
	background-color:#6e6e6e;
}
/* ::-webkit-scrollbar-button:vertical:start:decrement */
::-webkit-scrollbar-button:vertical:increment {  /* vertical button */
    background-image: url(../../Images/up-down-arrow.png); 
    background-repeat: no-repeat; 
    background-position: center -17px; 
}
::-webkit-scrollbar-button:vertical:decrement { 
    background-image: url(../../Images/up-down-arrow.png);
    background-repeat: no-repeat;
    background-position: center 0px;
}
::-webkit-scrollbar-button:horizontal:increment {  /* horizontal button */
    background-image: url(../../Images/left-right-arrow.png); 
    background-repeat: no-repeat;
    background-position:-17px center ;
}
::-webkit-scrollbar-button:horizontal:decrement { 
    background-image: url(../../Images/left-right-arrow.png); 
    background-repeat: no-repeat;
    background-position:0px center ;
}

::-webkit-scrollbar-thumb {
    border-radius: 5px;
	background: rgba(195,195,195,1); 
    -webkit-box-shadow:intset 0px 0px 6px rgba(0,0,0,0.6);	
	font-size:10px;
	text-align:center; 
	vertical-align:middle;		
}
::-webkit-scrollbar-thumb:horizontal {
background-repeat:repeat-x;
border:2px solid #6e6e6e;
}

::-webkit-scrollbar-thumb:vertical {
background-repeat:repeat-y;
border:2px solid #6e6e6e; 
}
::-webkit-scrollbar-thumb:window-inactive {
  background-color:rgba(195,195,195,1);  /* thumb color when blur */
}
::-webkit-scrollbar-corner{width:10px; height:10px; background-color:#6e6e6e;}

/* end: webkit core 设置滚动条的样式 */


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值