开发者

How to create button containing image & text

I want to create a button in my rai开发者_如何学Pythonls 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.


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.)."


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.


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.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜