I have a button on a form;
<button type="button" class="button" onclick="validate_form_newsletter_wide( form )"><img src="index_htm_files/btn_newsletter_wide.png" alt="Send"></button>
It styled using;
<style>
button::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner {
padding: 0 !important;
border: 0 none !important;
}
#form_newsletter_wide .button {
position:relative;
float: right;
cursor:pointer;
border: 0px;
padding: 0px;
margin: 0px;
margin-top: -1px;
z-index:100;
}
</style>
When clicked in Firefox nothing about the button changes, in Chrome I get a highlight border around the button which I can live with but in IE it's more of a pressed effect where the button almost seems to move down and right. Is there anyway to prevent this?
It's a browser behaviour, a simple solution is to use a link tag instead of button (since you're calling a javascript function).
<img src="myimg"/>
If you still want to use the , I've found that there are some characteristics on each browser (in a simple debug):
Chrome adds outline and padding
Firefox adds a whole lot of stuff with the standart button border
IE messes with the inner text position
So to fix them, you have to manipulate the pseudo selectors for the button behaviour. And for IE, a good solution is to envolve your text on a element, and make it relative positioned. Like so:
<button type="button" class="button"><span>Buttom or Image</span></button>
<style>
button,
button:focus,
button:active{
border:1px solid black;
background:none;
outline:none;
padding:0;
}
button span{
position: relative;
}
</style>
Pen
Related
I'm feeling quite frustrated after finding out that the bootstrap button class seems to break the hover function in standard CSS.
I didn't really want to use tooltips, so I decided to try making my own grey box appear next to my button to display why it's disabled on hover. Here's my code:
HTML
<a class="btn btn-danger disabled" disabled="disabled" href="" id="statement-delete" onclick="return false;">Delete
<span id="delete-info"></span>
</a>
CSS
#statement-delete:hover #delete-info {
display: block;
}
#delete-info {
display: none;
background: #C8C8C8;
margin-left: 0px;
padding: 10px;
position: absolute;
z-index: 1000;
width:200px;
height:100px;
}
I thought I surely must be doing something wrong until I used a JSFiddle, and it magically worked (before adding the Bootstrap reference). However, as soon as I added the reference to the Bootstrap, no hover...
Here's the fiddle: http://jsfiddle.net/ga82Lbm5/1/
If you remove the reference to bootstrap at the left, you'll see that it works.
Is it possible to use the Hover function over a Bootstrap button? Or will I have to resort to using some custom jQuery to do this?
Bootstrap adds the rule pointer-events:none to your code for disabled elements to prevent the hover from working. You can undo this by reverting the change with:
a.btn.disabled {
pointer-events: auto;
}
jsFiddle example
I'd suggest you remove the property disabled="disabled" since you want the hover function. Logically, if you think about it, the element must be "enabled" for the hover to work. Similarly, you could also remove the CSS class disabled class for the same reason.
The thing is Bootstrap adds the property pointer-events: none; to the class disabled. The definition of this property (borrowed from Mozilla Developer Network (https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events)) is :
The CSS property pointer-events allows authors to control under what
circumstances (if any) a particular graphic element can become the
target of mouse events.
You solution really is to nullify the effects of this property.Thus, removing the aforementioned properties, this works. See below :
#statement-delete:hover #delete-info {
display: block;
}
#delete-info {
display: none;
background: #C8C8C8;
margin-left: 0px;
padding: 10px;
position: absolute;
z-index: 1000;
width:200px;
height:100px;
top: 48px;
left: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<a class="btn btn-danger" href="" id="statement-delete" onclick="return false;">Delete<span id="delete-info"></span></a>
I have the following style class for button -
.buttonStyleClass {
padding:5px 20px;
}
When I try to focus the button in Firefox, then focus outline is appearing inside the button after padding. But when you verify the same in Chrome you will find the focus to entire button including padding.
In my application focus outline seems to odd in firefox since it is appearing 20 pixels inside of button.
Is there any CSS fix for this issue ?
Thanks,Gopal
Actually in both Firefox and Chrome I see the outline OUTSIDE of the button... Check out this fiddle. You can easily hide the outline though:
.buttonStyleClass { outline: 0; }
If this is not the answer; could you provide us with a fiddle or screenshot of what you mean?
edit
It's probably a bit OS-specific, as I only saw the dotted (inner) outline when I added a explicit border to the button (button { border: 1px solid red; }).
You can remove, or alter, the outline with the :-moz-focus-inner selector, like this:
button::-moz-focus-inner { border:0; padding: 0; }
Also check out the updated fiddle
I realize this is a very old question, but no one has actually answered the question yet, and several people have given bad advice. Given I got here via Google, other people may come here and leave with that bad advice.
For accessible reasons, you should never remove styling like this, unless you replace it with something better.
Instead of:
button::-moz-focus-inner {
border:0;
padding: 0;
}
Try:
button::-moz-focus-inner {
padding: inherit;
}
Try out this
button { padding: 10px; border: 1px solid red;}
button.no-outline { border: 1px solid blue; }
button.no-outline::-moz-focus-inner { outline: none; border:0; padding: 0; }
button.better-outline {border: 1px solid green; }
button.better-outline::-moz-focus-inner { padding: inherit; }
<button>my button</button>
<button class="no-outline">without outline</button>
<button class="better-outline">with better outline</button>
Add this to your CSS.
.buttonStyleClass:active {
outline: 0;
}
Are you viewing this in a web browser? You said 'application' in your query.
If I understand correctly you are saying that:
Chrome : outlines around the button area inside padding.
Firefox : outlines the area outside padding.
This is a browser specific rendering problem.
Two solutions come to mind.
Don't use padding for you button instead use:
.buttonStyleClass {
height:50px;
line-height:50px;
text-align:center;
}
Alternatively use -webkit targeting to write specific browser css markup.
http://jsfiddle.net/JV6MH/4/
This fiddle should render focus outline the same in both firefox and chrome by avoiding the use of padding on buttons.
<- I mean this dotted border (top-left corner is shown).
It supposed to be a button with link. It looks great, but when I click on it, browser draws a border around it. If I remove the <a> from code and click again, border won't be drawn
CSS:
#button{
padding: 0.5em;
margin: 0 auto;
border-radius: 3px;
background-color: #B3C833;
font-family: 'Consolas',monospace;
font-size: 3em;
display: inline-block;
}
HTML:
<a href="#">
<div id="button">
<span id="pref">http://</span><span id="addr">example.com</span>
</div>
</a>
You need to add this porperty:
a {
outline:none;
}
That border is there for accessibility, and shouldn't be removed. It allows people that are disabled and accessing your site via keyboard to see where the focus is.
Check out outlinenone.com
If you don't mind losing a portion of your traffic, you can remove it anyway with:
a {
outline:none;
}
i wanted to make a log-in button with the type="submit" with an image that has an hover image too and :active image also,
well its work fine on firefox and chrome, but on internet explorer its just give the basic image and not giving the hover image and the active image.
and beside that, its make a dotted line on the button when you click on it.
how its show on IE:
http://imageshack.us/photo/my-images/72/ieproblem.jpg/
how its show on chrome and firefox:
http://imageshack.us/photo/my-images/685/chromes.jpg/
.button
{
border:none;
background: url(../img/login.jpg);
width:41px;height:19px;
}
.button:hover
{
background: url(../img/loginhover.jpg) no-repeat top left;
width: 41px;
height: 19px;
}
.button:active {
background: url(../img/loginactive.jpg);
}
the button code on HTML:
<input type="submit" class="button" value=""/>
If you are using earlier versions of IE, it has issues with :hover.
if you are using the ie7 >
you need to add href to your anchor, :hover is not picked up by IE otherwise:
and to remove the outline you can try
a {
outline: 0;
}
I believe this is caused by the outline property within IE.
Check out http://css-tricks.com/removing-the-dotted-outline/ for some tips on how to remove it.
a {
outline: 0;
}
Or apply the outline style to other elements.
I'm trying to style the submit button on the wordpress search widget, but Opera is giving me trouble.
I've set a 1px solid border on the button, and it appears fine until the text input is activated, then the border on the button seems to disappear (or becomes black, i can't tell).
This does not happen in firefox where the button appears the same even if the text field is activated.
This is the css i have now:
li.widget_search #searchform #searchsubmit
{
height: 24px !important;
border-color: #ff9900;
border-width:1px;
border-style: solid;
background-color: #201300;
font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;
font-size: 11px;
letter-spacing: 1px;
color: #FFB100;
padding: 0px 3px 0px 3px;
overflow: hidden;
}
li.widget_search #searchform #searchsubmit:active
{
border: 0px;
}
This is an Opera issue. It always adds a black border if a border is specified on button focus, regardless of the settings of that border (color or style at least). All other browsers display a nice blue border here, inheriting all the settings from the normal button CSS rule.
You can prevent this on your own button by removing the border from the button:focus style.
Try...
a.button:active { border:0px; }
How about this:
I think Mr. David Murdoch's advice is the best for Opera ( here ). I've tried his approach in Opera and I succeeded basically doubling the input tags in this way:
<input type="submit" value="Go" style="display:none;" id="WorkaroundForOperaInputFocusBorderBug" />
<input type="submit" value="Go" />
This way the 1st element is hidden but it CATCHES the display focus Opera would give to the 2nd input element instead. LOVE IT!
Use a button element instead of an input, e.g.
<button type="submit">Submit</button>
and you won't see the black border in Opera.