Monday, September 24, 2012

Grails: Changing button background image

Such a simple thing, and it drove me crazy. How do I change the boring Grails button (actionSubmit), so it has an image background?
I created two new entries, for the button and the hover setting.

In MAIN.CSS

 .custombuttons input.browse {
  display:inline-block;
  padding:5px;
  border:1px #D7D7D7 solid;
  text-align:center;
  text-decoration:none;
  color:#666666;          
  background-image: url(../images/button.png);
  background-repeat: repeat-x;

}


.custombuttons input.browse:hover, .buttons input.browse:focus {
  display:inline-block;
  padding:5px;
  border:1px #D7D7D7 solid;
  text-align:center;
  text-decoration:none;
  color:#666666;  
  background-image: url(../images/button_hover.png);
  background-repeat: repeat-x;
}

The items in red of course deal with the background image. The image was a thin image file that I had repeat across the face of the button to create a gradient.


I reference the CSS in order to create my browse button.
In BROWSE.GSP

 <g:form controller="Output" action = "browse">
   <span class ="custombuttons">
      <g:actionSubmit class="browse" value="Browse..." action="browse"/>
   </span>
 </g:form>
 

And that did the trick.




No comments:

Post a Comment