利用css制作搜索框输入内容直接跳转到百度搜索的内容

html-css07

利用css制作搜索框输入内容直接跳转到百度搜索的内容,第1张

<form action="http://www.baidu.com/baidu" target="_blank">

<div align="center">

<img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/search/img/baidulogo_clarity_80_29.gif" alt="Baidu" border="0" align="bottom"><input type=text name=word size=30>

<input type="submit" value="百度搜索">

</div>

</form>

把代码放在<body></body>标签之间运行一下。

1、按钮的margin-left:-10px这样的负值。或者学度娘,取消input边框另作。

2、css里面font-size:16pxfont-family:"Times New Roman",Georgia,Serif这样。

3、可以设置input的type为image,然后加背景图片。

给出一个例子

<!DOCTYPE HTML>

<html lang="en">

<head>

    <meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" />

    <meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">

    <title>test</title>

    <link rel="stylesheet" href="css.css" type="text/css" media="screen">

    <script src="http://libs.baidu.com/jquery/1.7.0/jquery.min.js"></script>

</head>

<body>

    <div class="search">

        <input id="search" type="text" autofocus="autofocus" >

        <div class="submit">搜索</div>

    </div>

    <style type="text/css">

        .search{width:300pxoverflow: hiddenborder:1px solid #dddfont-size:16pxheight:2emline-height: 2em}

        .search:hover{border:1px solid #00af60}

        .search input#search{padding-left: 10pxoutline: nonewidth:230pxborder:0}

        .search .submit{cursor:pointerfloat: rightpadding:0 10pxcolor: #00af60border-left: 1px solid #ddd}

        .search:hover .submit{background: #00af60color:#FFFborder:0/*background:url(1.jpg)*/}

    </style>

    <script type="text/javascript">

        $(function(){

            $('.search').hover(function(){$('#search')[0].focus()})//

            $('.search .submit').click(function(){

                alert("在此检查然后js提交")

            })

        })

    </script>

</body>

</html>

<!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/htmlcharset=gb2312" />

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

<style type="text/css">

#dv1

{margin:0px autowidth:200pxheight:80px}

#dv2

{

background:url(91529822cd5685b7d7cae2f9.jpg)

width160px height:33px

float:left

width: 174px

overflow: hidden

text-align:center

left: 459px

top: 13px

}

#dv3

{

width:34px

height:33px

float:left

position:absolute

left: 497px

top: 16px

overflow: hidden

}

</style>

</head>

<body><form id="form1" name="form1" method="post" action="">

<div id="dv1"><div id="dv2">

<label>

<input type="text" name="textfield" style="width:100pxheight:20px" />

</label>

</div><div id="dv3"><a href="#" ><img src="aaa.jpg" style="border:0px"/></a></div>

</div> </form>

</body>

</html>

你试下把