CSS之文本框样式和水平居中

article/2025/10/31 1:55:07

文章目录

  • 1 CSS使用
    • 1.1 文本框样式
      • 1.1.1 鼠标一上去变成浅绿色
      • 1.1.2 文本框提示样式,鼠标点击获得焦点时提示内容消失
      • 1.1.3 input文本框样式
      • 1.1.4 只有下划线的文本框
      • 1.1.5 软件序列号式的输入框
      • 1.1.6 输入框景背景透明
      • 1.1.7 鼠标划过输入框,输入框背景色变色
      • 1.1.8 输入字时输入框边框闪烁(边框为小方型)
      • 1.1.9 输入字时输入框边框闪烁(边框为虚线)
      • 1.1.10 自动横向廷伸的输入框
      • 1.1.11 自动向下廷伸的文本框
    • 1.2 按钮和框样式
      • 1.2.1 蓝色按钮
      • 1.2.2 红色按钮
      • 1.2.3 选择按钮
      • 1.2.4 绿色按钮
      • 1.2.5 图像按钮
      • 1.2.6 页面正文
      • 1.2.7 下拉选择框
      • 1.2.8 线条文本编辑框
      • 1.2.9 多行文本框
      • 1.2.10 阴影风格的表单
      • 1.2.11 只显一条横线的输入框
      • 1.2.12 没有边框的输入框
  • 2 六种实现元素水平居中
    • 2.1 引言
    • 2.2 各个不同方式居中
      • 2.2.1 margin和width实现水平居中
      • 2.2.2 inline-block实现水平居中方法
      • 2.2.3 浮动实现水平居中的方法
      • 2.2.4 绝对定位实现水平居中
      • 2.2.5 CSS3的flex实现水平居中方法
      • 2.2.6 CSS3的fit-content实现水平居中方法

1 CSS使用

1.1 文本框样式

1.1.1 鼠标一上去变成浅绿色

<html>
<head>
<title>css-文本框</title>
<style type="text/css">
<!--
.box1,.box2 { width:144px; height:22px; line-height:22px; border:1px solid #A9BAC9;background:url
(http://cn.yimg.com/i/mail/06/bg_box1.gif) no-repeat #fff; padding:0 3px; font-size:12px; }
.box2 { border:1px solid #9ECC00;}
-->
</style>
</head>
<body>
<INPUT class=box1 id=login
onmouseover="this.className='box2'" onMouseOut="this.className='box1'"
name=login>
</body>
</html>

1.1.2 文本框提示样式,鼠标点击获得焦点时提示内容消失

<!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=gb2312" />
<title>文本框提示样式</title>
<style type="text/css">
<!--
.a1 {
color: #CCCCCC;
}
.a2 {
color: #000;
}
-->
</style>
</head>
<body>
<input name="n" type="text"/>
<input name="n1" type="text"/>
<script language="javascript">
window.onload=function(){
s('n','Your message1');s('n1','Your message2')
}
function g(a){return document.getElementByIdx_x(a)}
function s(n,v){
with(g(n)){
className='a1';value=v;
onfocus=function(){if(value==v)value='';className='a2'}
onblur=function(){if(value==''){value=v;className='a1'}}
}
}
</script>
</body>
</html>

1.1.3 input文本框样式

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<style>
<!--
.username { width:130px; background:#FFFFFF url("/article/upimages/ico_username.gif") 2px 2px no-repeat; padding-
left:18px;BORDER-RIGHT: #E7AD01 1px solid; BORDER-TOP: #E7AD01 1px solid; FONT-SIZE: 13px; BORDER-LEFT: #E7AD01
1px solid; COLOR: #000000; BORDER-BOTTOM: #E7AD01 1px solid; HEIGHT: 20px }
-->
</style>
</head>
<body>
<table cellSpacing="0" cellPadding="0" width="100%" border="0" id="table1">
<tr><form name="myform" method="post" action=""><td class="login_td">用户名:<input class="username"
onmouseover="this.style.borderColor='#99E300'" onmouseout="this.style.borderColor='#A1BCA3'" maxLength="12"
name="UserName"></td></form>
</tr>
</table>
</body>
</html>

1.1.4 只有下划线的文本框

<input style="border:0;border-bottom:1 solid black;background:;">

1.1.5 软件序列号式的输入框

<script for="T" event="onkeyup">
if(value.length==3)document.all[event.srcElement.sourceIndex+1].select();
</script>
<input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T7" size="5" maxlength="3">

软件序列号式的输入框(完整版):

<script for="T" event="onkeyup">
if(value.length==maxLength)document.all[event.srcElement.sourceIndex+1].focus();
</script>
<script for="T" event="onfocus">select();</script>
<script for="Submit" event="onclick">
var sn=new Array();
for(i=0;i<T.length;i++)
sn=T.value;
alert(sn.join("—"));
</script>
<input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3"><input name="T" size="5" maxlength="3">
<input type="submit" name="Submit">

1.1.6 输入框景背景透明

<input style="background:transparent;border:1px solid #ffffff">

1.1.7 鼠标划过输入框,输入框背景色变色

<INPUT value="Type here" NAME="user_pass" TYPE="text" SIZE="29" onmouseover="this.style.borderColor='black';this.style.backgroundColor='plum'"
style="width: 106; height: 21"
onmouseout="this.style.borderColor='black';this.style.backgroundColor='#ffffff'" 
style="border-width:1px;border-color=black">

1.1.8 输入字时输入框边框闪烁(边框为小方型)

<Script Language="JavaScript">
function borderColor(){
if(self['oText'].style.borderColor=='red'){
self['oText'].style.borderColor = 'yellow';
}else{
self['oText'].style.borderColor = 'red';
}
oTime = setTimeout('borderColor()',400);
}
</Script>
<input type="text" id="oText" style="border:5px dotted red;color:red" onfocus="borderColor(this);" onblur="clearTimeout(oTime);">

1.1.9 输入字时输入框边框闪烁(边框为虚线)

<style>
#oText{border:1px dotted #ff0000;ryo:expression_r(οnfοcus=function light (){with(document.all.oText){style.borderColor=(style.borderColor=="#ffee00"?"#ff0000":"#ffee00");timer=setTimeout(light,500);}},οnblur=function(){this.style.borderColor="#ff0000";clearTimeout(timer)})};
</style>
<input type="text" id="oText">

1.1.10 自动横向廷伸的输入框

<input type="text" style="huerreson:expression_r(this.width=this.scrollWidth)" value="abcdefghijk">

1.1.11 自动向下廷伸的文本框

<textarea name="content" rows="6" cols="80" onpropertychange="if(this.scrollHeight>80) this.style.posHeight=this.scrollHeight+5">输入几个回车试试</textarea>
<!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>文本框输入提示</title>
<style type="text/css">...
<!--
.keyword {...}{width:150px; height:20px; border:#0066FF 1px solid;}
#keytishi {...}{width:150px; height:auto; border:#0066FF 1px solid; position:absolute; display:none;}
#keytishi ul {...}{ margin:0;}
#keytishi ul li{...}{margin:0;list-style-type:none; line-height:16px; height:16px; font-size:12px; padding:2px;}
#keytishi ul li a {...}{display:block; width:150px; height:16px; text-decoration:none;}
#keytishi ul li a:hover {...}{background-color:#0099FF;}
-->
</style>
<script type="text/javascript">...
<!--
//建立XMLHttpRequest对象
var xmlhttp;
try...{xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e)...{try...{xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');}catch(e)...{try...{xmlhttp= new XMLHttpRequest();}catch(e)...{}}
}
function getKeyWord()...{var obj = document.getElementById("search");//获取文本域对象if(obj.value=="")...{return;}var top=0;var left=0;while(obj)...{//此循环得到文件域对象在页面中的绝对位置top += obj["offsetTop"];left += obj["offsetLeft"];objobj = obj.offsetParent;}xmlhttp.open("get","input.asp?keyword="+document.getElementByIdx_x("search").value,true);xmlhttp.onreadystatechange = function()...{if(xmlhttp.readyState == 4)...{if(xmlhttp.status == 200)...{if(xmlhttp.responseText!="")...{document.getElementByIdx_x("keytishi").innerHTML =(xmlhttp.responseText);//把后台返回的数据填充到提示层document.getElementByIdx_x("keytishi").style.left = left + "px";//设置提示层的位置,左document.getElementByIdx_x("keytishi").style.top = (top + 25) + "px";//设置提示层的位置,上document.getElementByIdx_x("keytishi").style.display ="block";//设置提示层可见}else...{document.getElementByIdx_x("keytishi").innerHTML = "";//清空提示层document.getElementByIdx_x("keytishi").style.display ="none";//设置提示层不可见}}else...{}}}xmlhttp.setRequestHeader("If-Modified-Since","0");xmlhttp.send(null);
}
function input(str)...{document.getElementByIdx_x("search").value=str;//从提示层选择你需要的数据填充到文本框document.getElementByIdx_x("keytishi").innerHTML = "";//清空提示层document.getElementByIdx_x("keytishi").style.display = "none";//设置提示层不可见
}
//-->
</script>
</head>
<body>
<input type="text" class="keyword" id="search" name="search"οnkeyup="getKeyWord();" οnclick="getKeyWord();" />
<div id="keytishi"></div><!--提示层-->
</body>
</html>

后台文件 [input.asp]

<%...@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="conn.asp"-->
<%...dim rsdim sqldim keyWordskeyWrods = Request("keyword")Set rs = Server.CreateObject("ADODB.Recordset")sql = "select * from king_test where keyword like '%"&keyWrods&"%'"rs.open sql,conn,1,1if not (rs.bof and rs.eof) thenResponse.Write("<ul>")do while not rs.eof
%>
<li><a href="javascript:void(null);"οnclick="input('<%Response.Write(escape(rs("keyword")))%>');"><%...Response.Write(escape(rs("keyword")))%></a></li>
<%...rs.movenextloopResponse.Write("<ul>")end ifrs.closeset rs = nothingconn.closeSet conn = nothing
%>.buttoncss {font-family: "tahoma", "宋体";font-size:9pt; color: #003399;border: 1px #003399 solid;color:#006699;border-bottom: #93bee2 1px solid;border-left: #93bee2 1px solid;border-right: #93bee2 1px solid;border-top: #93bee2 1px solid;background-image:url(../images/bluebuttonbg.gif);background-color: #e8f4ff;cursor: hand;font-style: normal ;width:60px;height:22px;
}

1.2 按钮和框样式

1.2.1 蓝色按钮

.bluebuttoncss {font-family: "tahoma", "宋体";font-size: 9pt; color: #003366;border: 0px #93bee2 solid;border-bottom: #93bee2 1px solid;border-left: #93bee2 1px solid;border-right: #93bee2 1px solid;border-top: #93bee2 1px solid;*/background-image:url(../images/blue_button_bg.gif);background-color: #ffffff;cursor: hand;font-style: normal ;
}

1.2.2 红色按钮

.redbuttoncss {font-family: "tahoma", "宋体";font-size: 9pt; color: #0066cc;border: 1px #93bee2 solid;border-bottom: #93bee2 1px solid;border-left: #93bee2 1px solid;border-right: #93bee2 1px solid;border-top: #93bee2 1px solid;background-image:url(../images/redbuttonbg.gif);background-color: #ffffff;cursor: hand;font-style: normal ;
}

1.2.3 选择按钮

.selectbuttoncss{font-family: "tahoma", "宋体";font-size: 9pt; color: #0066cc;border: 1px #93bee2 solid;border-bottom: #93bee2 1px solid;border-left: #93bee2 1px solid;border-right: #93bee2 1px solid;border-top: #93bee2 1px solid;background-image:url(../images/blue_button_bg.gif);background-color: #ffffff;cursor: hand;font-style: normal ;
}

1.2.4 绿色按钮

.greenbuttoncss {font-family: "tahoma", "宋体";font-size: 9pt; color: #0066cc;border: 1px #93bee2 solid;border-bottom: #93bee2 1px solid;border-left: #93bee2 1px solid;border-right: #93bee2 1px solid;border-top: #93bee2 1px solid;background-image:url(../images/greenbuttonbg.gif);background-color: #ffffff;cursor: hand;font-style: normal ;
}

1.2.5 图像按钮

.imagebutton{cursor: hand;    
}

cursor: handcursor:hand都是手型的光标,但是还是有一丢丢的区别。
cursor:hand IE完全支持,但是在Firefox是不支持的,木有效果。
cursor:pointer 是CSS2.0的标准,所以Firefox是支持的,但是IE5.0及之前的版本不支持。IE6开始支持。

1.2.6 页面正文

body {scrollbar-face-color: #ededf3;scrollbar-highlight-color: #ffffff;scrollbar-shadow-color: #93949f;scrollbar-3dlight-color: #ededf3;scrollbar-arrow-color: #082468;scrollbar-track-color: #f7f7f9;scrollbar-darkshadow-color: #ededf3;font-size: 9pt;color: #003366;overflow:auto;
}td { font-size: 12px }
th {font-size: 12px;
}

1.2.7 下拉选择框

select{border-right: #000000 1px solid;border-top: #ffffff 1px solid;font-size: 12px;border-left: #ffffff 1px solid;color:#003366;border-bottom: #000000 1px solid;background-color: #f4f4f4;
}

1.2.8 线条文本编辑框

.editbox{background: #ffffff;border: 1px solid #b7b7b7;color: #003366;cursor: text;font-family: "arial";font-size: 9pt;height: 18px;padding: 1px;
}

1.2.9 多行文本框

.multieditbox{background: #f8f8f8;border-bottom: #b7b7b7 1px solid;border-left: #b7b7b7 1px solid;border-right: #b7b7b7 1px solid;border-top: #b7b7b7 1px solid;color: #000000;cursor: text;font-family: "arial";font-size: 9pt;padding: 1px;
}

1.2.10 阴影风格的表单

.shadow {position:absolute;z-index:1000;top:0px;left:0px;background:gray;background-color:#ffcc00;filter : progidximagetransform.microsoft.dropshadow(color=#ff404040,offx=2,offy=2,positives=true);
}

1.2.11 只显一条横线的输入框

.logintxt{border-right: #ffffff 0px solid;border-top: #ffffff 0px solid;font-size: 9pt;border-left: #ffffff 0px solid;border-bottom: #c0c0c0 1px solid;background-color: #ffffff
}

1.2.12 没有边框的输入框

.noneinput{text-align:center;width:99%;height:99%;border-top-style: none;border-right-style: none;border-left-style: none;background-color: #f6f6f6;border-bottom-style: none;}

2 六种实现元素水平居中

2.1 引言

水平居中的实现方案,大家最熟悉的莫过开给元素定一个显示式的宽度,然后加上margin的左右值为auto。如:

.center {width: 960px;margin-left: auto;margin-right: auto;} 

这种方法给知道了宽度的元素设置居中是最方便不过的了,但有很多情况之下,我们是无法确定元素容器的宽度。换句话说,未有明确宽度的时候,上面的方法无法让我们实现元素水平居中。那要怎么办呢?这也就是我们今天需要讨论的问题。
为了更好的说明问题,我们来看一个制作分页效果的代码:

<div class="pagination"><ul><li><a href="#">Prev</a></li><li><a href="#">1</a></li><li><a href="#">2</a></li><li><a href="#">3</a></li><li><a href="#">4</a></li><li><a href="#">5</a></li><li><a href="#">Next</a></li></ul></di

给分页加上样式:

.pagination li {line-height: 25px;}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

这是一个极普通的样式代码,初步的效果:
在这里插入图片描述

这很显然不是我们需要的效果,接下来我们分几种方案来制作:

2.2 各个不同方式居中

2.2.1 margin和width实现水平居中

第一种方法是最古老的实现方案,也是大家最常见的方案,在分页容器上定义一个宽度,然后配合margin的左右值为auto实现效果:

.pagination {width: 293px;margin-left: auto;margin-right: auto;}.pagination li {line-height: 25px;display: inline;float: left;margin: 0 5px;}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

代码中绿色部分是为了实现分页居中效果而添加的代码。(下文中没有特殊声明,绿色部分代码表示新增加的代码。),先来看看效果:
在这里插入图片描述

效果是让我们实现了,但其扩展性那就不一定强了。示例中只显示了五页和向前向后的七个显项,但往往我们很多情况下是不知道会有多少个分页项显示出来,而且也无法确定每个分页选项的宽度是多少,也就无法确认容器的宽度。
优点:实现方法简单易懂,浏览器兼容性强;
缺点:扩展性差,无法自适应未知项情况。

2.2.2 inline-block实现水平居中方法

inline-block属性是无法让元素水平居中,关键之处要在元素的父容器中设置text-align的属性为center,这样才能达到效果:

.pagination {text-align: center;font-size: 0;letter-spacing: -4px;word-spacing: -4px;}.pagination li {line-height: 25px;margin: 0 5px;display: inline-block;*display: inline;zoom:1;letter-spacing: normal;  word-spacing: normal;font-size: 12px;}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

效果如下:
在这里插入图片描述

这个方法相对来说也是简单易懂,但使用了inline-block解决了水平居中的问题
做点:简单易懂,扩展性强;
缺点:需要额外处理inline-block的浏览器兼容性。

2.2.3 浮动实现水平居中的方法

刚看到标题,大家可能会感到很意外,元素都浮动了,他还能水平居中?大家都知道,浮动要么靠左、要么靠右,还真少见有居中的。其实略加处理就有了。

.pagination {float: left;width: 100%;overflow: hidden;position: relative;}.pagination ul {clear: left;float: left;position: relative;left: 50%;/*整个分页向右边移动宽度的50%*/text-align: center;}.pagination li {line-height: 25px;margin: 0 5px;display: block;float: left;position: relative;right: 50%;/*将每个分页项向左边移动宽度的50%*/}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

效果如下所示:
在这里插入图片描述

这种方法实现和前面的与众不同,使用了浮动配合position定位实现。下面简单的介绍了一下这种方法实现原理。
大家都知道div是一个块元素,其默认的宽度就是100%,如图所示:
在这里插入图片描述

如果div设置了浮动之后,他的内容有多宽度就会撑开有多大的容器(除显式设置元素宽度值之外),这也是我们实现让分页导航居中的关键所在:
在这里插入图片描述

接下来使用传统的制作方法,我们会让导航浮动到左边,而且每个分页项也进行浮动,就如下图所示一样:
在这里插入图片描述

现在要想的办法是让分页导航居中的效果了,在这里是通过position:relative属性实现,首先在列表项“ul”上向右移动50%(left:50%;),看到如下图所示:
在这里插入图片描述

如上图所示一样,整个分页向右移动了50%的距离,紧接着我们在li上也定义position:relative属性,但其移动的方向和列表“ul”移动的方向刚好是反方向,而其移动的值保持一致:
在这里插入图片描述

这样一来就实现了float浮动居中的效果。

优点:兼容性强,扩展性强;
缺点:实现原理较复杂。

2.2.4 绝对定位实现水平居中

绝对定位实现水平居中,我想大家也非常的熟悉了,并且用得一定不少,早期是这样使用的:

.ele {position: absolute;width: 宽度值;left: 50%;margin-left: -(宽度值/2);} 

但这种实现我们有一个难题,我并不知道元素的宽度是多少,这样也就存在如方法一所说的难题,但我们可以借助方法三做一点变通:

.pagination {position: relative;}.pagination ul {position: absolute;left: 50%;}.pagination li {line-height: 25px;margin: 0 5px;float: left;position: relative;/*注意,这里不能是absolute,大家懂的*/right: 50%;}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

优点:扩展性强,兼容性强;
缺点:理解性难。

2.2.5 CSS3的flex实现水平居中方法

CSS3flex是一个很强大的功能,她能让我们的布局变得更加灵活与方便,唯一的就是目前浏览器的兼容性较差。那么第五种方法,我们就使用flex来实现

.pagination {display: -webkit-box;-webkit-box-orient: horizontal;-webkit-box-pack: center;display: -moz-box;-moz-box-orient: horizontal;-moz-box-pack: center;display: -o-box;-o-box-orient: horizontal;-o-box-pack: center;display: -ms-box;-ms-box-orient: horizontal;-ms-box-pack: center;display: box;box-orient: horizontal;box-pack: center;}.pagination li {line-height: 25px;margin: 0 5px;float: left;}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

优点:实现便捷,扩展性强
缺点:兼容性差。

2.2.6 CSS3的fit-content实现水平居中方法

fit-contentCSS中给width属性新加的一个属性值,配合margin可以让我轻松的实现水平居中的效果:

.pagination ul {width: -moz-fit-content;width:-webkit-fit-content;width: fit-content;margin-left: auto;margin-right: auto;}.pagination li {line-height: 25px;margin: 0 5px;float: left;}.pagination a {display: block;color: #f2f2f2;text-shadow: 1px 0 0 #101011;padding: 0 10px;border-radius: 2px;box-shadow: 0 1px 0 #5a5b5c inset,0 1px 0 #080808;background: linear-gradient(top,#434345,#2f3032);}.pagination a:hover {text-decoration: none;box-shadow: 0 1px 0 #f9bd71 inset,0 1px 0 #0a0a0a;background: linear-gradient(top,#f48b03,#c87100);} 

优点:简单易懂,扩展性强;
缺点:浏览器兼容性差


http://chatgpt.dhexx.cn/article/PdYl4jVB.shtml

相关文章

【Css】input输入文本框的样式大全和搜索框实例(图文和完整源码)

一、默认显示信息 <input type"text" required"required" placeholder" 请输入金额" name"u"onfocus"if(placeholder 请输入金额){placeholder}"onblur"if(placeholder){placeholder 请输入金额}"v-model:v…

文本框输入的样式

文本框文字的输入样式设计&#xff0c;这里分四种样式&#xff1a; 1、从左到右 2、从右到左 3、从中间到两边 4、两端对齐 效果如下&#xff1a; TextAlignAt.css文件&#xff1a; .left {text-align: left;border: 1px dotted black;width: 50%;}.right {text-align: r…

HTML滚动条

由于四象限中可能会有很多任务&#xff0c;可能会超出象限大小&#xff0c;所以需要加上滚动条。 一般是&#xff1a;overflow:auto这个属性; 同时简单介绍几种HTML滚动条代码&#xff1a; 1、向右滚动代码&#xff1a; <div id"colee_right" style"overf…

html中设置滚动条的样式

一、效果图 二、css ::-webkit-srollbar-track-piece{background:none;-webkit-border-radius:0;} ::-webkit-scrollbar{width:8px;height:8px;} ::-webkit-scrollbar-thumb:vertical{height:50px;background-color:#bbbbbb;-webkit-border-radius:4px;outline:0px solid #…

(css)滚动条样式

(css)滚动条样式 效果&#xff1a; /*滚动条整体样式*/ ::-webkit-scrollbar {width: 2px;/*高宽分别对应横竖滚动条的尺寸*/height: 10px; } ::-webkit-scrollbar-thumb {/*滚动条里面小方块*/border-radius: 10px;width: 2px;height: 60px;background: linear-gradient(0deg,…

vue修改滚动条样式的方法

这篇文章主要介绍了vue修改滚动条样式,首先要知道&#xff0c;修改滚动条样式&#xff0c;利用伪元素-webkit-scrollbar。下面来看看文章内容的具体实现吧 目录 首先要知道&#xff0c;修改滚动条样式&#xff0c;利用伪元素-webkit-scrollbar。 注意&#xff0c; ::-webkit-…

CSS自定义滚动条样式

CSS自定义滚动条样式 测试html内容 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"viewport" content&…

CSS 滚动条: 自定义滚动条样式

CSS 滚动条: 自定义滚动条样式 文章目录 CSS 滚动条: 自定义滚动条样式前言正文overflow & ::-webkit-scrollbar实际效果&#xff08;自定义滚动条、隐藏滚动条&#xff09; 结语其他资源参考连接完整代码示例 前言 本篇来介绍如何为自己的网页定制化自己的滚动条 正文 …

css如何修改滚动条样式

默认滚动条样式如下: 那如何修改呢?如下代码: <div class="inner"> <div class="innerbox"> <p style="height:200px;">这是内容111</p> <p style="height:400px;">这里是…

浏览器自定义滚动条样式

当一段文本过长&#xff0c;使用overflow:auto属性后&#xff0c;这段文本所在区域将会出现滚动条。有时候&#xff0c;我们需要自定义浏览器的滚动条样式&#xff0c;可以使用css3的scrollbar-thumb属性来实现。 首先看一下这个属性的兼容性。 可见这个属性在pc端支持的并不…

overflow产生的滚动条样式设置

修改overflow产生的滚动条样式&#xff0c;主要可以通过如下三个伪元素设置&#xff1a; 1)-webkit-scrollbar&#xff1a;设置水平滚动条的高度&#xff0c;垂直滚动的宽度 2)-webkit-scrollbar-thumb&#xff1a;设置滚动条里面的滑块样式 3)-webkit-scrollbar-track&…

滚动条样式美化

之前做的项目中客户觉得滚动条的样式样式很丑&#xff0c;让我们优化一下。既然客户有要求那肯定得满足啊&#xff0c;但是因为我也没有做过&#xff0c;也不知道咋搞&#xff0c;于是就在网上搜索了一下。发现可以通过 ::-webkit-scrollbar CSS伪类选择器来美化滚动条样式。使…

Css实现漂亮的滚动条样式(转载)

转载于 https://www.jianshu.com/p/c2addb233acd 第一种 <div class"test test-1"><div class"scrollbar"></div> </div>.test {width : 50px;height : 200px;overflow: auto;float : left;margin : 5px;border : none;}.…

css修改滚动条样式

css自定义滚动条样式 自定义滚动条实例代码&#xff1a; 有时候觉得浏览器自带的滚动条&#xff0c;实在是太丑了&#xff0c;一点点内容超出比例&#xff0c;就是多大的一个滚动条就来了&#xff0c;实在是遭不住&#xff0c;所以我就动手了&#xff01;&#xff01;&#xff…

CSS-滚动条样式设置

注意&#xff1a;滚动条设置的width、height&#xff0c;分别是对应纵向滚动条 宽度、横向滚动条 高度&#xff0c;无法修改纵向滚动条高度、横向滚动条宽度数值只介绍Google浏览器滚动条样式&#xff0c;常用属性如下&#xff1a; 注意&#xff1a;滚动条设置的width、height&…

滚动条基本样式设置

::-webkit-scrollbar 系列属性 详细使用说明 ::-webkit-scrollbar注意&#xff1a;如果没有设置滚动溢出的相关属性&#xff0c;滚动条样式系列属性不会生效&#xff08;resize 除外&#xff09;。属性 ::-webkit-scrollbar 整个滚动条。::-webkit-scrollbar-button 滚动条上的…

修改滚动条样式

修改滚动条样式 如果给父元素固定了宽高&#xff0c;子元素设置overflow:auto时&#xff0c;就会出现滚动条&#xff0c;而浏览器默认的滚动条样式并不是很美观&#xff0c;如下图所示 为了让显示的滚动条更好看些&#xff0c;可以对滚动条样式进行设置&#xff0c;关键css代…

CSS设置滚动条样式

今天在写一个项目的时候遇到了&#xff0c;这样一个小难点 要设置一个类似于页面的滚动条&#xff0c;查阅了相关文档之后&#xff0c;我会了 一、我们可以使用overflow属性设置是否出现滚动条overflow:scroll /* x y 方向都会*/ 或者 overflow-x:scroll /只是x方向/ 或者…

修改webkit内核浏览器滚动条样式(修改element-ui table样式)

webkit浏览器css设置滚动条主要有下面7个属性 1. ::-webkit-scrollbar 滚动条整体部分&#xff0c;可以设置宽度啥的 2. ::-webkit-scrollbar-button 滚动条两端的按钮 3. ::-webkit-scrollbar-track 外层轨道 4. ::-webkit-scrollbar-track-piece 内层滚动槽 5. ::-webkit-s…

css修改滚动条的样式

滚动条的默认样式是这样的&#xff1a; 大灰块做背景&#xff0c;内嵌小灰块做滚动距离的展示。 再加上贴边的宽度&#xff0c;对于内容本身就比较窄的区域来说&#xff0c;这种样式笨重感十足&#xff01; 单调且无趣&#xff01; 而像这种样式的滚动条就比较可以了。 滚动…