0

What I'm trying to do: Add the search icon in the right of the textbox

enter image description here

The code im using in [css] is this:

.tb4 {
background: #3f4c6b; /* Old browsers */
background: -moz-linear-gradient(top,  #3f4c6b 0%, #3f4c6b 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3f4c6b), color-stop(100%,#3f4c6b)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #3f4c6b 0%,#3f4c6b 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #3f4c6b 0%,#3f4c6b 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #3f4c6b 0%,#3f4c6b 100%); /* IE10+ */
background: linear-gradient(to bottom,  #3f4c6b 0%,#3f4c6b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3f4c6b', endColorstr='#3f4c6b',GradientType=0 ); /* IE6-9 */
 background: url(web.png) top right no-repeat;
 padding: 4px 4px 4px 22px;
 height: 18px;
 border: 1px solid #494949;
}

The result I get is :

enter image description here

  • I do have web.png in my main folder. *
MethodManX
  • 949
  • 1
  • 8
  • 16

3 Answers3

0
background: url(web.png) top right no-repeat;

This is over-ruling the other background settings. You've tried background-image but I suspect that this conflicts with the gradient settings, which are effectively using an image-property of the background.

Added: This SO topic indicates that it is possible to combine gradients with an image.

I would add the button immediately after the search box, and use positioning, perhaps a negative left-margin, to bring it back over the textbox. If the textbox is an input element then I would probably use the image as a background to a label, and bring this label back across to the left, perhaps with a z-index to place it above the textbox.

Community
  • 1
  • 1
Andy G
  • 19,232
  • 5
  • 47
  • 69
0

The gradients and the background image are going to conflict. Try:

.tb4 {
  /* as above but without the background line for web.png */
  position: relative; /* and add this line */
}
.tb4:after { /* and this rule */
  content: "";
  display: block;
  width: 20px; /* change dimensions as needed to match image */
  height: 20px;
  background: url(web.png) top right no-repeat;
  position: absolute;
  top: 0;
  right: 0;
}
Skrivener
  • 1,003
  • 6
  • 11
  • Will the icon still be clickable (separately from the textbox) if you use :after? – Andy G Jun 16 '13 at 02:04
  • Hmm, it depends, but I would hazard a guess not for your purposes. Can you post the html around and including the searchbox? Also if you could confirm if you can add/change that html. -- edit -- Sorry, thought you were OP. If :after (or :before) is used with an anchor/link tag then it is considered part of the clickable link space, but I don't think you can bind JS events to it for example. So it depends what the OP needs and what the html is as to whether it matters. – Skrivener Jun 16 '13 at 02:29
0

the right way to right this would be :

background: #3f4c6b url(web.png) top right no-repeat;/* Old browsers */
background: url(web.png) top right no-repeat,-moz-linear-gradient(top,  #3f4c6b 0%, #3f4c6b 100%); /* FF3.6+ */
background: url(web.png) top right no-repeat, -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3f4c6b), color-stop(100%,#3f4c6b)); /* Chrome,Safari4+ */
background: url(web.png) top right no-repeat, -webkit-linear-gradient(top,  #3f4c6b 0%,#3f4c6b 100%); /* Chrome10+,Safari5.1+ */
background: url(web.png) top right no-repeat ,-o-linear-gradient(top,  #3f4c6b 0%,#3f4c6b 100%); /* Opera 11.10+ */
background: url(web.png) top right no-repeat ,-ms-linear-gradient(top,  #3f4c6b 0%,#3f4c6b 100%); /* IE10+ */
background:url(web.png) top right no-repeat , linear-gradient(to bottom,  #3f4c6b 0%,#3f4c6b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3f4c6b', endColorstr='#3f4c6b',GradientType=0 ); /* IE6-9 */

So image can sit on top of gradient.
Are top right the good coordinates to give ?

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129