Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coding a search bar with icon inside it

Tags:

html

css

I am trying to code the following layout. I have messed up the code and not sure what's the best way to do it.

alt text

<div class="search-wrapper">
        <form action="search.php" method="get" name="search">
          <div class="search-box"><img class="search-icon" src="images/search-icon.png" width="21" height="18" alt="search icon" />
            <input name="seach" type="text" value="Search for dishes or restaurants" />
          </div>
          <input class="submit-button" name="Go" type="submit" />
        </form>
      </div>



#search {
    height:125px;
    overflow:hidden;
}
.search-wrapper {
    width:465px;
    height:45px;
    background-color:#f0f0f0;
    margin:43px auto 0;
    border:1px solid #e9e9e9;
    -moz-border-radius: 5px; /* FF1+ */
    -webkit-border-radius: 5px; /* Saf3-4 */
    border-radius: 5px; /* Opera 10.5, IE 9, Saf5, Chrome */
    position:relative;
}
.search-box {
    width:375px;
    height:32px;
    background-color:#fff;
    margin:5px 7px;
    border:1px solid #cfcfcf;
    -moz-border-radius: 5px; /* FF1+ */
    -webkit-border-radius: 5px; /* Saf3-4 */
    border-radius: 5px; /* Opera 10.5, IE 9, Saf5, Chrome */
    position:relative;
}
.search-box img.search-icon {
    margin:8px 0 0 5px;
}
.search-box input {
    border:none;
    height:30px;
    width:332px;
    margin:0;
    position:absolute;
    font-size:16px;
    padding-left:5px;
    padding-right:5px;
}
input.submit-button {
    background:url(../images/go-button.png) no-repeat;
    text-indent:-9999px;
    border:none;
    height:32px;
    width:68px;
    position:absolute;
    top:6px;
    left:390px;
    cursor:pointer;
 //right:15px;
}

Here is the code @ paste bin:

http://pastebin.com/KQR3mPiW

Images:

http://bayimg.com/IAPcpAACi

http://bayimg.com/JapcBaAci

like image 939
Harsha M V Avatar asked Oct 02 '10 12:10

Harsha M V


People also ask

How do I put the Search icon inside input?

To add icon inside the input element the <i> tag and <span> tag are used widely to add icons on the webpages. To add any icons on the webpages or in some specific area, it needs the fontawesome link inside the head tag. The fontawesome icon can be placed by using the fa prefix before the icon's name.

How do I add an icon to a code?

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons. All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)


2 Answers

Here yo go: http://jsfiddle.net/SjafT/

Preview:

alt text

You might change the value of 'readjust in jsfiddle' part.

like image 93
Jeaf Gilbert Avatar answered Sep 28 '22 05:09

Jeaf Gilbert


Why do you use

position: absolute;

? Use

position: relative; float: left; 

with the search box and the same with the button. No margin specification would be required either.

like image 33
bogatyrjov Avatar answered Sep 28 '22 07:09

bogatyrjov