How do I render a normal (enabled-looking) button, via HTML/CSS, which doesn't change its appearance upon mouse over or mouse down (for illustration purposes e.g. Press [x] to cancel)?
(i.e. I don't want it to become "highlighted" or "pushed" when you hover the mouse over it or "press" it.)
I know I can use a picture of the button, but under different or future versions of browsers the subsequent real buttons may look different and not match the picture, which is why I'm looking to render it via HTML/CSS.
Maybe you can consider placing an empty <div> with a specified width and height overlapping the button, which will occlude the click on the button?
Depending the positioning modes of your outer elements, you can use the <div> to cover some outer element, or just the <input type="button" ...> itself (in which case JavaScript and DOM can be helpful to determine the actual size of the button and thus the coverage area).
#Navigeteur
just take a screenshot of a normal button and save it as bmp or png image
and render the image instead of button :)
The disabled attribute is supported in all major browsers, so you could use that.
<button type="button" disabled>Click Me!</button>
or, alternatively:
<input type="button" value="Click Me!" disabled />
To make it look like it's enabled, you could then edit its CSS properties for it's disabled state:
input[type="button"]:disabled, button[type="button"]:disabled {
background:#DDD;
color:#000;
}
But, as OP pointed out, this can make it appear completely different to what other buttons look like on certain browsers/systems. You could omit the background property in the CSS rule and they would render as any other disabled buttons, but with font color like enabled buttons. Alternatively, omit the disabled HTML attribute and position these buttons out of context they would normally belong to (being a part of a form).
EDIT: See Antony's answer for better explanation what styles need to be applied to make it appear like you expect them to ;)
You can force a disabled button to look just like a normal one using CSS.
DEMO
Safari: http://jsfiddle.net/9aXW9/2/
Firefox: http://jsfiddle.net/gZtT7/
IE buried its CSS in the registry. But as a general rule, apply color: #000; and other modifications would make it look like a normal button.
HTML
<input type="submit" disabled="disabled" value="I cannot be pressed." />
CSS
/* Safari */
input[type="submit"]:disabled {
-webkit-appearance: push-button;
-webkit-box-align: center;
text-align: center;
cursor: default;
color: ButtonText;
padding: 2px 6px 3px 6px;
border: 2px outset ButtonFace;
background-color: ButtonFace;
box-sizing: border-box;
white-space: pre;
}
/* Firefox */
input[type="submit"]:disabled {
-moz-appearance: button;
padding: 0px 6px 0px 6px;
border: 2px outset ButtonFace;
background-color: ButtonFace;
color: ButtonText;
font: -moz-button;
line-height: normal;
white-space: pre;
cursor: default;
-moz-box-sizing: border-box;
-moz-user-select: none;
-moz-binding: none;
text-align: center;
text-shadow: none;
}
Related
I have an input of type="submit" and I want exist no blue border around this element when I clicked (right or left click) on it.
I added the picture of OK mode and not OK mode in chrome browser below:
OK mode picture is similar to:
And Not OK mode picture is similar to:
I should say this problem exist in Firefox browser too but the style of that extra borders is dotted.
I tried many ways to solve this problem using CSS like:
Setting border:none; or border-width:0; in default mode and :hover mode and :focus mode of the input but it doesn't fix and still remained.
Also I read some articles about it like this but it doesn't work yet and not working for me.
Any advanced help will be great.
You need to set
outline: none;
input[type="submit"]{
background: #0075E9;
border-radius: 50px;
padding: 15px 30px;
color: #FFD400;
outline: none;
font-weight: bold;
}
<input type="submit" value="Go to the next step"/>
I have a login page with two fields:
<select id="operatore" name="operator">
<option disabled selected>Operator</option>
<option>John</option>
<option>Jennifer</option>
<option>Carl</option>
</select>
<input type="password" placeholder="Password" id="search_field" readonly>
I want that all the text appears centred. In Firefox all works fine. But in Chrome the written "Operator" appears on the left, even if the style inspector doesn't cancel the style, as you can see from the image:
In the native app for surf the net in Samsung Tablet, the written "Operator" appears centered, but the placeholder "password" appears on the left. Why? How can I fix all these problems?
HERE is the full CODE.
you can give it a text indent like text-indent: 40px;this won't make it aligned center but it will move it to the middle
and by the way there is a better way of making a placeholder for the select
<option style="display: none;" value="">Operator</option>
this way it won't show up in the drop-down
Taken from: Is it possible to center text in select box?
I'm afraid this isn't possible with plain CSS, and won't be possible to make completely cross-browser compatible.
However, using a jQuery plugin, you could style the dropdown:
http://filamentgroup.com/lab/jquery_ui_selectmenu_an_aria_accessible_plugin_for_styling_a_html_select/
This plugin hides the select element, and creates span elements etc on the fly to display a custom drop down list style. I'm quite confident you'd be able to change the styles on the spans etc to center align the items.
Ok, I believe I have fixed your Operator problem.
Here is the slightly changed code.
form input {/*ADDED*/
width: 250px;
}
form input, #operatore {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
border: 1px solid rgba(255, 255, 255, 0.4);
background-color: rgba(255, 255, 255, 0.2);
border-radius: 3px;
padding: 10px 15px;
margin: 0 auto 10px auto;
padding-left: 90px;/*ADDED*/
padding-right: 80px;/*ADDED*/
/*TOOK AWAY width: 250px; PROPERTY*/
display: block;
text-align: center;
font-size: 18px;
color: white;
-webkit-transition-duration: 0.25s;
transition-duration: 0.25s;
font-weight: 300;
}
For some odd reason in Chrome the selector form input, #operatore is disabling any other changes made to (form) selector, option. Moreover if I were to add an extra selector, for example: #operatore {someCSS}, the (selector) form input, #operatore would STILL take precedence over that selector and I also used !important. Anyway you will have to align the text manually using padding-left and padding-right.
You can't really customise <select> or <option> much. The only way (cross-browser) would be to manually create a drop down with divs and css/js to create something similar.
So I have a basic button class that applies the same styling to various buttons across a site.
I have had to end up putting a form input, and an anchor tag next to each other, and their height and width is different. I have made the inner button text the same on each one just to show the differences like for like (obviously I dont need 2 'Add' buttons next to each other :P)
I dont want to specify the width, or the height in the CSS as the contents will change. Even the font looks slightly different sized, and from the box model it looks like the padding is alright.
http://jsfiddle.net/aeD4Z/2/
Markup
<form id="" method="POST" action="">
<input class="button" type="submit" name="submit" value="Add">
</form>
<a class="button" href="">Add</a>
CSS
.button {
font-family: Arial;
background: linear-gradient(to bottom, #FCB97E 0%, #F07605 100%) repeat scroll 0 0 transparent;
border: 1px solid #F07605;
border-radius: 0.5em 0.5em 0.5em 0.5em;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
color: #FFFFFF;
cursor: pointer;
display: inline-block;
font-size: 13px;
font-weight: bold;
line-height: 13px;
outline: medium none;
padding: 5px 8px !important;
text-align: center;
text-decoration: none;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
vertical-align: baseline;
}
EDIT: As you can see below it is not the padding, as the box models in firebug show the padding is the same for each one, so its something todo with the actual element itself
How do I get both to be the same dimensions from a single CSS class in my js fiddle above?
To fully equalize „button-ish“ <a> anchors, input and more recently button, it is a good idea, to synchronize their box-sizings:
input and button for historical reasons are still in quirks mode (resp. already in modern mode box-sizing: border-box) the rest is in box-sizing: content-box mode... (either way: gotta put in the same mode or compensate for equal heights by differenciating padding)
This is my standard “test”, when I start styling for a site:
__AA__
<button id='button'>plain Button</button>
<a class='button' href='#'>plain Anchor</a>
<a class='button'>linkless Anchor</a>
<input class='button' type='submit' value='Input Button' />
__BB__
this CSS (in stylus notation) is a good boilerplate:
button, a.button, input.button
display inline-block
font-size 12px
font-weight bold
color white
font-family sans-serif
text-decoration none
background #24B345
cursor pointer // also linkless (i.e. js) anchors/buttons should have that
// important to equalize input/button vs. anchor:
box-sizing content-box
border 4px solid green
padding 8px 10px
margin 5px 4px 10px 0
// some of this is default,
// but since input often gets styled elsewhere...
vertical-align middle // a bit subject to taste
min-height 0
&:hover, &:focus // slight hover effect, resp. keyboard use (:focus)
background: #44D365
Live on Codefork
The padding applies differently to the button and anchor. I don't know this as fact, but my guess is a button reserves a little more space around it's value to look more like a button where a link is rendered as text.
You might try this:
a {
padding-top:5px !important;
padding-bottom:5px !important;
padding-left:0px !important;
padding-right:0px !important;
}
Which won't be exactly the same size, but pretty close.
Well, I always add line-height property in button class, like this:
/* HTML */
Go somewhere
<button class="button"> Click here </button>
<input type="submit" class="button" value="Submit">
/* CSS */
.button {
box-sizing: border-box;
display: inline-block;
cursor: pointer;
line-height: inherit; // this property does magic
// rest of the styling
}
And this always work for me.. 😁
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.
I'm wondering what html element to use for buttons on a web page - I'd like to style my 'buttons' like twitter does. For example:
http://twitter.com/twitter
the "more" button at the bottom of the tweet listing - is that a <button> element, or a <div> element? I'd like to know which to use. I think for either <button> or <div> we can supply rollover states and all that stuff to make it look pleasant?
Don't use <div> tags to make clickable elements. Use <a> or <button> elements. This enables browsers with JavaScript disabled to interact with them as expected. Even if your functionality requires JavaScript and there is no reasonable default behaviour you can assign to an <a>, use it regardless - it conveys "clickable" semantics.
In general, choose the tag that most closely describes the function of its content, not the appearance of its content, and avoid unnecessary <div> tags lest your documents suffer from divitis.
The "more" button on Twitter is an <a> with a background-image, CSS3 rounded corners, and a border. Here's the complete CSS (elem is <a class="more round">):
.more {
outline: none;
display: block;
width: 100%;
padding: 6px 0;
text-align: center;
border: 1px solid #ddd;
border-bottom: 1px solid #aaa;
border-right: 1px solid #aaa;
background-color: #fff;
background-repeat: repeat-x;
background-position: left top;
font-size: 14px;
text-shadow: 1px 1px 1px #fff;
font-weight: bold;
height: 22px;
line-height: 1.5em;
margin-bottom: 6px;
background-image: url('/images/more.gif');
}
.more:hover {
border: 1px solid #bbb;
text-decoration: none;
background-position: left -78px;
}
.more:active {
color: #666;
background-position: left -38px;
}
.round {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
Sample Button
You should use <a> or <button>, not <div>.
In general you want to use <a> for navigation and <button> for some action that takes place on that screen.
The best reason I can think of to prefer a <button> or <a> tag to <anything-else> is that during testing, it makes it easier to locate the actionable items. I use Capybara and Rspec for example, and the method click_on works a lot more reliably when it refers to a <button>, the same with the method click_link and <a>.
The other reasons given here are also good: semantics, screen readers, etc.
Pragmatically, your audience will decide if every single element on your page is a really fancy <div> or if you want to play nice with the rest of the web dev ecosystem. It may simply depend on whether your audience all uses X browser or not.
One gotcha: Since a <button> could submit a form or <a> take you to another page, you have to make sure to prevent those default actions. In the JavaScript function that handles the click, you have to specify that it only does the action you program.
function onClickEvent(e)
{
e.preventDefault();
// What you want to do instead
}
Use an a tag instead of button. My reasoning involves compatibility issues with older version of IE (IE6 hates the button tag).
<button> vs. <input type="button" />. Which to use?
I'd suggest <input id="Button1" type="button" value="button" /> with a css style to give the appearance that you're looking for.