I need to make a button look like a link using CSS. The changes are done but when I click on it, it shows as if it's pushed as in a button. Any idea how to remove that, so that the button works as a link even when clicked?
相关问题
- Adding a timeout to a render function in ReactJS
- React Native Inline style for multiple Text in sin
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- Set BaseUrl of an existing Pdf Document
try using the css pseudoclass
:focus
edit as for links and onclick events use (you shouldn’t use inline javascript eventhandlers, but for the sake of simplicity i will use them here):
with this.href you can even access the target of the link in your function.
return false
will just prevent browsers from following the link when clicked.if javascript is disabled the link will work as a normal link and just load
some/page.php
—if you want your link to be dead when js is disabled usehref="#"
You can achieve this using simple css as shown in below example
If you don't mind using twitter bootstrap I suggest you simply use the link class.
I hope this helps somebody :) Have a nice day!
The code of the accepted answer works for most cases, but to get a button that really behaves like a link you need a bit more code. It is especially tricky to get the styling of focused buttons right on Firefox (Mozilla).
The following CSS ensures that anchors and buttons have the same CSS properties and behave the same on all common browsers:
The example above only modifies
button
elements to improve readability, but it can easily be extended to modifyinput[type="button"], input[type="submit"]
andinput[type="reset"]
elements as well. You could also use a class, if you want to make only certain buttons look like anchors.See this JSFiddle for a live-demo.
Please also note that this applies the default anchor-styling to buttons (e.g. blue text-color). So if you want to change the text-color or anything else of anchors & buttons, you should do this after the CSS above.
The original code (see snippet) in this answer was completely different and incomplete.
You can't style buttons as links reliably throughout browsers. I've tried it, but there's always some weird padding, margin or font issues in some browser. Either live with letting the button look like a button, or use onClick and preventDefault on a link.
HTML
CSS
See Demo (on JSfiddle)