搜索框css样式

html-css011

搜索框css样式,第1张

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

<html xmlns="

<head>

<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

<title>无标题文档</title>

<script type="text/javascript" src="jquery.js"></script>

<style>

.{ padding:0 margin:0 list-style:none}

.htmlBox{ width:100% min-width:500px height:500px border:1px solid #A349A4 border-radius:5px}

.sskBox{ width:100% height:35px margin-top:150px border:1px solid #000 border-left:0 border-right:0}

.zc{ width:100px height:35px float:left}

.zj{ width:250px height:35px float:left border-left:1px solid #000 border-right:1px solid #000}

.yc{ height:35px float:right}

</style>

</head>

<body>

<div class="htmlBox">

 <div class="sskBox">

 <div class="zc">左边100</div>

 <div class="zj">中间250</div>

 <div class="yc">右边自适应</div>

</div>

</div>

</body>

<script>

tmntH()//加载的时候执行一次

$(window).resize(function() {tmntH()})//浏览器窗口变化时执行

function tmntH()

{

    var ycw=$(".sskBox").width()-352+'px'//yc的宽度等于sskBox宽度-350-2(边框线)

    //alert(div3)

    $(".yc").css("width",ycw)

    

}

</script>

</body>

</html>

无论是网站还是web应用,都会为了增强用户体验而添加它,那么你是不是也想过设计一个别致的搜索框?在今天的文章中,大家将会学到如何使用伪元素来创建一个超酷的CSS3搜索框。当然在开始介绍前你也可以下载源代码或者查看在线演示。HTML举例:正如接下来你所看到的,标记很少,并且很容易理解:<form class=“cf form-wrapper”><input type=“text” placeholder=“Search here.。.” required><button type=“submit”>Search</button></form>你可能注意到了HTML5的特殊属性,像placeholder和required,简介如下:.placeholder-基本上,这个属性的作用在于当文本框获得焦点之前,先在文本框里显示一个域的信息,直到获得焦点后,域的信息被隐藏。.required-这个属性说明了当前元素是表单提交中的一个必需属性。HTML5也给我们带来了一个新的type属性:type="search"。小贴士:HTML 元素像img 和input 都没有内容,所以,像before这样的伪元素不会为我们的搜索框呈现任何箭头。我的解决方案是使用button type=“submit” 元素代替普通的input type=“submit”。这样,我们就可以用ENTER键来提交表单。CSS举例接下来,你将会看到demo里必要的样式:清除浮动.cf:before, .cf:after{content:“”display:table}.cf:after{clear:both}.cf{zoom:1}表单元素有前缀的属性像-moz、-box、-shadow 不包括在内,我只想让下面的代码保持干净。/* Form wrapper styling */.form-wrapper {width: 450pxpadding: 15pxmargin: 150px auto 50px autobackground: #444background: rgba(0,0,0,.2)border-radius: 10pxbox-shadow: 0 1px 1px rgba(0,0,0,.4) inset, 0 1px 0 rgba(255,255,255,.2)}/* Form text input */.form-wrapper input {width: 330pxheight: 20pxpadding: 10px 5pxfloat: leftfont: bold 15px ‘lucida sans’,‘trebuchet MS’,‘Tahoma’border: 0background: #eeeborder-radius: 3px 0 0 3px}.form-wrapper input:focus {outline: 0background: #fffbox-shadow: 0 0 2px rgba(0,0,0,.8) inset}.form-wrapper input::-webkit-input-placeholder {color: #999font-weight: normalfont-style: italic}.form-wrapper input:-moz-placeholder {color: #999font-weight: normalfont-style: italic}.form-wrapper input:-ms-input-placeholder {color: #999font-weight: normalfont-style: italic}/* Form submit button */.form-wrapper button {overflow: visibleposition: relativefloat: rightborder: 0padding: 0cursor: pointerheight: 40pxwidth: 110pxfont: bold 15px/40px ‘lucida sans’,‘trebuchet MS’,‘Tahoma’color: #ffftext-transform: uppercasebackground: #d83c3cborder-radius: 0 3px 3px 0text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3)}.form-wrapper button:hover{background: #e54040}.form-wrapper button:active,.form-wrapper button:focus{background: #c42f2foutline: 0}.form-wrapper button:before { /* left arrow */content: ‘’position: absoluteborder-width: 8px 8px 8px 0border-style: solid solid solid noneborder-color: transparent #d83c3c transparenttop: 12pxleft: -6px}.form-wrapper button:hover:before{border-right-color: #e54040}.form-wrapper button:focus:before,.form-wrapper button:active:before{border-right-color: #c42f2f}.form-wrapper button::-moz-focus-inner { /* remove extra button spacing for Mozilla Firefox */border: 0padding: 0}希望大家能喜欢这个教程,并且期待你们的反馈。

.search/*整个搜索框*/{

width:300px

height:30px

background-image: url(../images/search.gif)/*这是这个搜索框的背景*/

background-repeat: no-repeat

background-position: 50%

margin-top: 10px

margin-right: 0px

margin-bottom: 0px

margin-left: 15px

padding: 0px

overflow: hidden

clear: both

}

.search input/*用来去掉搜索框里的文本框和按钮的背景和边框,并设置并列排放*/{

border:none

background:none

float:left

}

.search_box/文本框样式/{

width:150px

height:26px

line-height:26px

padding:0px

color:#999999

text-align:left

margin-top: 2px

margin-right: 15px

margin-bottom: 0px

margin-left: 10px

float: left

}

.search_button/*按钮样式*/{

width:45px

height:27px

cursor:pointer

color:#000000

font-size: 14px

}

具体样式可根据自己的需要调整。

希望对你有所帮助。