mandar.gokhale
mandar.gokhale

Reputation: 1875

How to create button containing image & text

I want to create a button in my rails web application. It Should contain an image & text. Also that button should call a link. I am using button_to tag to create button for a link.The link must be processed as html request not js call.My problem is how to add image in that button? Please help.Thank you.

Upvotes: 2

Views: 344

Answers (3)

Graeme Leighfield
Graeme Leighfield

Reputation: 2985

Here is a working example using HTML and CSS in JS Fiddle

http://jsfiddle.net/G3x8p/

Ive used almost all the attributes you need to get it working how you want, just change them to suit your needs.

Keeping it in an external CSS keeps it neat and tidy, and removes the need for messy inline CSS code.

Upvotes: 1

jovhenni19
jovhenni19

Reputation: 450

Try this:

<%= button_to("TEXT",question_path,:style=>"background-image: url('/images/image.extension');") %>

And yes Yuri's right, "Button always should do an action, link should always redirect somewhere (except pseudo-links, which could do some average — i.e. open hidden blocks, etc.)."

Upvotes: 1

YuS
YuS

Reputation: 2045

On the one hand you can style an A tag to looks like button with CSS or use BUTTON tag, but, on the other hand, remember, you should avoid to use buttons with the link behavior. Button always should do an action, link should always redirect somewhere (except pseudo-links, which could do some average — i.e. open hidden blocks, etc.).

Upvotes: 0

Related Questions