1

好的,所以如果您查看http://www.marioplanet.com,您会看到我正在尝试为我的菜单栏模仿 apple.com 的设计,包括我的全局搜索栏。

现在,我正在尝试模仿 Apple 的全局搜索栏输入字段,尽可能接近,所以我需要一些帮助。

我希望该字段位于中间,我尝试过使用maring: auto auto;但没有奏效..

我也想使用苹果网站上的圆角技术,但我不知道该怎么做。那是CSS3吗?

我还需要一个灰色的占位符字符串读取Search,但我认为我可以使用 JS 来实现。如果可以使用 HTML 或 CSS,请告诉我。

与输入字段左侧对齐的小聚光灯/放大镜图像很好,但不是必需的:)

好的,您可以查看该站点,但这里也是代码:

索引.htm:

<div id="globalheader" class="apple">
    <!--googleoff: all-->
    <ul id="globalnav">
        <li id="gn-home"><a href="index.htm">Home</a></li>
        <li id="gn-catalog"><a href="catalog.asp">Shop!</a></li>
        <li id="gn-about"><a href="about.htm">About</a></li>
        <li id="gn-contact"><a href="contact.htm">Contact</a></li>
        <li id="gn-media"><a href="media.htm">Media</a></li>

    </ul>
    <div id="globalsearch">
    <form id="searchform">
        <div>
        <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" />
        </div>

        <div id="suggestions"></div>

    </form>
    </div>
    <!--googleon: all-->
</div>

默认.css:

body {
    background-color: #666666;
    font-family:Verdana, Arial, Helvetica, sans-serif;
}
#header {
    background-color: #DDDDDD;
    width: 1130px;
    margin: 0px auto;
}
#content {
    width: 1130px;
    margin: 0px auto;
}
#leftcol {
    background-color:#EBEBEB;
    width: 200px;
    height: 550px;
    font-size:14px;
    clear: both;
    float: left;
}
#detail {
    background-color:#FFFFFF;
    width: 730px;
    height: 550px;  
    font-size:12px;
    float: left;
}
#rightcol {
    background-color:#EBEBEB;
    width: 200px;
    height: 550px;
    font-size:14px;
    float: left;
}
#footer {
    background-color:#DDDDDD;
    width: 1130px;
    height:90px;
    font-size:12px;
    text-align:center;
    clear: both;
    margin: 0px auto;
}
h1 {
    color: #FF0000;
}
h2 {
    color:#FF0000;
}
a:link { 
    color:#FF0000;
}
a:visited { 
    color:#FF0000;
}
a:hover { 
    color:#00FF00;
}
a:active { 
    color:#FF0000;
}
img {
border:none;
}
#eznetseal {
text-align:center;
}
a.trayIcon {
position: relative;
top: 20px;
}
a.trayIcon:hover {
top: 7px;
}
#twittericon {
    left: 0px;  
}
#facebookicon {
    left: 22.5px;;
}
#youtubeicon {
    left: 45px;;
}
#tray {
position:relative;
}
#container {
    position:relative;
    margin-top: -40px;
}
#nav li 
{
 display: inline;
}
#features
{
    vertical-align: top;
}

全局搜索.css:

/* BASIC RESET */

body, div, img, p { padding:0; margin:0; }

a img { border:0 }


/* HTML ELEMENTS */
body { font-family:"Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif; }

/* COMMON CLASSES */
.break { clear:both; }


/* SEARCH FORM */
#searchform { margin:auto auto; font-size:18px; }
#searchform div { color:#eeeeee; }
#searchform div input { font-size:18px; width:120px; }
#suggestions{ position: relative; left:235px; width:320px; display:none; }

/* SEARCHRESULTS */

#searchresults { border-width:1px; border-color:#919191; border-style:solid; width:320px; background-color:#a0a0a0; font-size:10px; line-height:14px; }

#searchresults a { display:block; background-color:#e4e4e4; clear:left; height:56px; text-decoration:none; }

#searchresults a:hover { background-color:#b7b7b7; color:#ffffff; }

#searchresults a img { float:left; padding:5px 10px; }

#searchresults a span.searchheading { display:block; font-weight:bold; padding-top:5px; color:#191919; }
#searchresults a:hover span.searchheading { color:#ffffff; }

#searchresults a span { color:#555555; }
#searchresults a:hover span { color:#f1f1f1; }

#searchresults span.category { font-size:11px; margin:5px; display:block; color:#ffffff; }

#searchresults span.seperator { float:right; padding-right:15px; margin-right:5px;
            background-image:url(../images/shortcuts_arrow.gif); background-repeat:no-repeat; background-position:right; }

#searchresults span.seperator a { background-color:transparent; display:block; margin:5px; height:auto; color:#ffffff; }

谢谢!

4

2 回答 2

1

On the div containing the textbox try text-align: center; border-width: 0px; margin-top: 6px; to do the watermark try a jquery watermark plugin

For the rounded corners apple are inserting images into spans either end. I have seen the magnifying glass done this way or by setting the image as a background-image and adding padding to avoid overwriting it.

If I were you id download firebug for firefox so you can explore the markup and css yourself, it's quite easy.

Hope this helps.

于 2010-08-16T15:31:22.017 回答
1

我使用 Firebug 和 Web Developer 扩展来找到以下...

苹果肯定会使用 javascript(当然还有 css)来让搜索框看起来很漂亮。

如果您使用 noscript 打开 javascript,您将看到一个普通的方形文本框。

您可以检查以下 javascript 和 css 文件以了解发生了什么。

http://images.apple.com/global/scripts/search_decorator.js

http://images.apple.com/global/nav/styles/nav.css

在 css 文件中查看以下规则集

#globalsearch .search-wrapper .left

#globalsearch .search-wrapper .right

以下是用于创建搜索框的图像

http://images.apple.com/global/nav/images/searchfield_leftcap.png

http://images.apple.com/global/nav/images/searchfield_rightcap.png

我发现了以下有趣的事情。

  • 他们有专门的脚本文件只是为了让那个搜索框看起来很漂亮
  • 他们不使用图像精灵。
  • 我试图弄脏上面的一张图片,并且能够弄脏它 15%(它可能看起来微不足道,但是当您查看数百万访问的网站时,这可能会变成一个很大的数字)
于 2010-08-16T15:53:20.677 回答