Disable text selection onclick button - html

How can I avoid that there is a dotted selection rectangle around the text when the user clicks the button, see image below. I already tried to add the css rule user-select: none;, which I saw in another question, but this doesn't seem to work.
Any suggestions?
EDIT: The issue only appears in Firefox (tested with version 47.0)
.button {
background-color: #1a1a1a;
border: none;
color: #f8f8f8;
padding: 10px 40px;
text-align: center;
display: inline-block;
font-size: 16px;
border-radius: 4px;
user-select: none;
-webkit-transition-duration: 0.3s;/* Safari */
transition-duration: 0.3s;
}
.button:hover {
background-color: #595959;
/* Green */
color: white;
}
<button class="button">Button</button>

For remove the dotted border in buttons in Firefox:
button::-moz-focus-inner {
border: 0;
}

Simply put this in your CSS :
.yourclass
{
outline:none;
}
Hope it helps.

button.button:focus {
outline: 0;
}

Related

How to get a round outline on a round <button> with css in Safari

I'm trying to get a round button which has a an outline in the same color but that doesn't seem to be possible. The outline always ends up squared. Is there a method to achieve that with a or does it maybe only work with a ?
button {
width: 40px;
height: 40px;
border: none;
border-radius: 40px;
cursor: pointer;
background-color: black;
display: inherit;
outline: 5px solid black;
outline-offset: 5px;
}
<button></button>
I have added a picture since this only seems to happen on Safari...Screenshot from Safari snippet
I need it to work in all browsers especially on mobile though.
You can use this "hack".
INFO: In Brave Browser we got a square too with your snippet;
button {
position: relative;
width: 40px;
height: 40px;
border: none;
border-radius: 40px;
cursor: pointer;
background-color: black;
display: inherit;
margin:10px 2px;
}
button::after {
position: absolute;
top: -10px;
content: '';
left: -10px;
width: 50px;
height: 50px;
border: 5px solid black;
border-radius: 40px;
background-color: transparent;
display: inherit;
}
<button></button>
Safari fixed this bug on Safari Technology Preview 157. Source: https://webkit.org/blog/13575/release-notes-for-safari-technology-preview-157/
According to your question and code snippet that you have provided. From my browser when I ran both the button and the outline was Circle.
I would suggest you to clear your cache and run the code again OR try changing the browser.
Or please update your question with a screenshot as well, so that we can understand better.

Trouble styling range input thumb

I'm trying to do some basic styling in an html range input with the follow:
HTML
<input type="range" min="0" value="50" max="100" step="1" />
CSS
input[type=range]::-webkit-slider-thumb {
-webkit-appearance : none;
background : red;
height : 20px;
width : 20px;
}
I also made a Codepen you can look at.
You'll notice that if you comment out the background, height and width styles the thumb does dissapear. So something is working. But with the styles applied I'd expect it to be a 20px X 20px red square. But alas, I just see the default thumb styling.
Please check with the below answer
input[type=range] {
-webkit-appearance: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 300px;
height: 5px;
background: #ddd;
border: none;
border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: goldenrod;
margin-top: -4px;
}
input[type=range]:focus {
outline: none;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #ccc;
}
input[type=range] {
/* fix for FF unable to apply focus style bug */
border: 1px solid white;
/*required for proper track sizing in FF*/
width: 300px;
}
input[type=range]::-moz-range-track {
width: 300px;
height: 5px;
background: #ddd;
border: none;
border-radius: 3px;
}
input[type=range]::-moz-range-thumb {
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: goldenrod;
}
/*hide the outline behind the border*/
input[type=range]:-moz-focusring {
outline: 1px solid white;
outline-offset: -1px;
}
input[type=range]:focus::-moz-range-track {
background: #ccc;
}
/* for ie */
input[type=range]::-ms-track {
width: 300px;
height: 5px;
/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
background: transparent;
/*leave room for the larger thumb to overflow with a transparent border */
border-color: transparent;
border-width: 6px 0;
/*remove default tick marks*/
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #777;
border-radius: 10px;
}
input[type=range]::-ms-fill-upper {
background: #ddd;
border-radius: 10px;
}
input[type=range]::-ms-thumb {
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: goldenrod;
}
input[type=range]:focus::-ms-fill-lower {
background: #888;
}
input[type=range]:focus::-ms-fill-upper {
background: #ccc;
}
<input type="range" min="0" value="50" max="100" step="1" />
If you are able to edit the track, but NOT the thumb, then be sure that you have -webkit-appearance: none; in these two places to override default behavior.
input[type=range] {
-webkit-appearance: none; <------------------------------------ REQUIRED
}
input[type=range]::-webkit-slider-runnable-track {
background: /* ...change color with background property... */;
/* ...my custom edits...*/
}
input[type=range]:hover::-webkit-slider-runnable-track {
background: /* ...change color with background property... */;
/* ...my custom edits... */
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none; <------------------------------------ REQUIRED
height: /* ..manually set height greater than 0... */ <-------- REQUIRED
width: /* ..manually set width greater than 0... */ <---------- REQUIRED
background: /* ...change color with background property... */;
/* ...my custom edits... */
}
input[type=range]:hover::-webkit-slider-thumb {
background: /* ...change color with background property... */;
/* ...my custom edits... */
}
(Note that this works in Chrome, but you can comma separate other properties like input[type=range]::-moz-range-thumb and input[type=range]::-ms-thumb as needed to account for other browsers)
It would seem the following selector is causing the issue and your styles aren't working because of that, please remove it and the styles will apply:
::-webkit-slider-thumb
Here is an updated Codepen.
Updated Answer
Several styles need to be applied to range inputs in all browsers to override their basic appearance. After declaring the below styles you will be able to style the range toggler.
Please see the below and add it to your code:
input[type=range] {
-webkit-appearance: none; /* Hides the slider so that custom slider can be made */
width: 100%; /* Specific width is required for Firefox. */
background: transparent; /* Otherwise white in Chrome */
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type=range]:focus {
outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}
input[type=range]::-ms-track {
width: 100%;
cursor: pointer;
/* Hides the slider so custom styles can be added */
background: transparent;
border-color: transparent;
color: transparent;
}
Please see this link to the updated Codepen.
So the issue why the styles didn't get applied to the thumb is that you also have to add
input[type=range] {
-webkit-appearance: none;
}
.. The thumb is now a red square.
Hide the input - this hides thumb and track
Style the thumb as you'd like
Style the track
caveat: the track aligns with the top of the thumb. I used a negative margin to correct this. If someone has a better way of doing this that would be nice...
input[type=range] {
-webkit-appearance: none;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
background: red;
height: 20px;
width: 20px;
margin-top: -8px;
}
input[type=range]::-webkit-slider-runnable-track {
width: 300px;
height: 5px;
background: #ddd;
}
<input type="range" min="0" value="50" max="100" step="1" />
CODEPEN
Good resource here for ensuring browser compatibility.

Vertical slider for chrome and moz

Im styling a vertical slider using -moz and -webkit.
With mozilla i declare it vertical using orient="vertical" and all the styling works fine.
With chrome since im using -webkit-appearance: none; for styling i can't use -webkit-appearance: slider-vertical, this forces me to use -webkit-transform: rotate(90deg);
The issue is that in mozilla i can use height to declare the real height of the slider instead by rotating it with chrome i'm forced to use width.
#sens[type=range]{
-webkit-appearance: none;
height: 220px; //in chrome is width since it is rotated
}
How can i solve this?
ok, I think you need something like this.
For first you need to read about ::-webkit-slider-runnable-track and ::webkit-slider-thumb. link1 and link2 very useful properties.
And now you can do that like that:
input[type=range] {
-webkit-appearance: none;
-webkit-transform: rotate(90deg);
margin-top: 50px;
}
input[type=range]::-webkit-slider-runnable-track {
width: 300px;
height: 5px;
background: #ccc;
border: none;
border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: red;
margin-top: -5px;
}
input[type=range]:focus {
outline: none;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #ddd;
}
<input type="range" />

CSS hover not changing correctly on chrome

Ok, so I'm developing some sort of gallery/meal picker for some web application. When I hover over those fields, those white ones, meal should appear in the middle. That works great, but when I hover over those white fields in Chrome, I can't see the :hover effect on them. It still works, but without the effect. While on Firefox and IE-11 works perfectly. Here is the code link.
http://codepen.io/anon/pen/yyjKBQ
Code:
.dorucak {
display: none;
}
.dorucak + label {
bottom: 0px;
margin-right: 2px;
padding: 5px;
border: 1px solid black;
width: 10%;
background: white;
/*font-size: 24px;*/
display: inline-block;
}
.dorucak:hover + label {
color: white;
background: black;
cursor: pointer;
}
.dorucak:checked + label {
color: white;
background: purple;
}
.dorucak + label:hover {
color: white;
background: black;
cursor: pointer;
}
.dorucak:hover + label:hover {
color: white;
background: black;
cursor: pointer;
}
For Chrome I had to add :hover on both radio button class and label, and now it works. Sorry for posting this and fixing it a minute later.

Placeholder text input on IOS

I have a little issue at the moment, the text placeholder in the textbox doesn't seem to be showing when viewing on IOS device but works fine on desktop and android...
This is just a simple div with an input field in it.
This is the code I am using :
<div id="em_inputs" class="hidden clearfix">
<input type="text" name="first_name" id="first_name" placeholder="First Name">
</div>
#mixin Opacity($value){
$IEValue: $value*100;
opacity: $value;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity="+$IEValue+")";
filter: alpha(opacity=$IEValue);
}
#em_inputs{
-webkit-appearance: none;
-webkit-border-radius:0;
border-radius:0;
overflow: hidden;
position: relative;
top: 127px !important;
width: 100%;
input {
overflow: hidden;
-webkit-appearance: none;
-webkit-border-radius:0;
border-radius:0;
border: none;
width: 100%;
padding: 12px 5px 11px 10px;
color: $text-white;
background: url("../img/bg_input.png") repeat 0 0;
margin: 10px 0 0 0;
#include Opacity(0);
position: relative;
top: -10px;
height: 3px;
overflow: hidden;
&:focus{
border: 2px solid $text-white;
}
}
I am also using this code that makes the placeholder text white color in case a browser uses special rules.
::-webkit-input-placeholder {
color: white;
}
:-moz-placeholder { /* Firefox 18- */
color: white;
}
::-moz-placeholder { /* Firefox 19+ */
color: white;
}
:-ms-input-placeholder {
color: white;
}
::-webkit-scrollbar {
display: none;
}
Does someone have any idea what I going on ? I am not only interested in getting the code fixed but also know if someone experienced the same issues with IOS placeholders in general being a bit picky ?
Could it be because of the background image too ?
I found answers.
The text of the placeholder appears when changing the orientation of the device. That is changing the float.
What I do is just before the page fully loads I do a reset of the float and it works.
This is the source that helped me out.
http://www.456bereastreet.com/archive/201301/the_mysterious_webkit_placeholder_overflow_bug/