Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have several pictures of the same button, each one representing it in a different sate: normal, pressed, focused, disabled.
How can I make it into an html button that automatically shows the correct picture (and also has an onClick event) ?
Feel free to use html / css / javascript.
The tag also doesn't need to be a button, it could be an image, , or whatever you want, but hopefully written in a generic enough way for others to use your solution too
Thanks!
Just add a class to a link:
<a href="#" class='styledbutton'>Buttontext</a>
... and some CSS:
.styledbutton {background: url(defaultstate.png); display: inline-block;}
.styledbutton:hover {background: url(hoverstate.png);}
.styledbutton:focus {background: url(focusstate.png);}
You can make use of the CSS pseudo-selectors :hover and :focus to change the state of a button at various different interaction points, and simply tie a function into the onclick event in order to run additional JavaScript if required:
function buttonClick() {
console.log('Button clicked');
}
button { /* Default state */
background: white;
}
button:hover { /* On hover */
background: red;
}
button:focus { /* After a click */
background: blue;
}
<button onclick="buttonClick()">Button</button>
Keep in mind that this can also be done with an image by simply passing the image's path into background-image as a url() value.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
help, I created a card with a button in it, in the card section I used the css property pointer-events: none; so that the button cannot be clicked because of that property, can I click the button without deleting the property pointer-events: none;
thank you
you can do that with the help of bootstrap, you need to give a mentor column class col-sm-12 and rest of the icons class col-sm-6
You can use #media queries to set the width and height of each icon.
#media (max-width: 786px) {
.icon1{
width: 30px;
height: 30px;
}
}
Media queries are useful when you want to modify your site or app depending on a device's screen size. Now the above css will work if the maximum size of the screen is 786px
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have problems activating a simple element in HTML via JavaScript.
So I have a simple Setup:
<a href="example.com">
</a>
<button>Klick</button>
Now I want, that if the button is clicked, some JS Code will be executed, which then "Clicks" the element. Similar to executing the .click() function on a button.
I also use jQuery, if that makes it easier for you. Thanks in advance.
native Js has a click() method on every elements, you just need to call it
let button = document.getElementById("button")
let link = document.getElementById("link")
button.onclick = () => link.click()
<a id="link" href="example.com"></a>
<button id="button">Klick</button>
if your objective is only to have a link looking like a button then using css is better than having 2 elements
as a bonus it allow you to keep all of the <a> default behavior you might lose by using a button
a {
text-decoration: none;
color: inherit;
padding: 2px 25px;
border: 1px solid #b6b6b3;
border-radius: 3px;
background-color: #e0e0df;
}
a:hover {
background-color: #fafafa;
}
I'm a <a>
<button>I'm a <button></button>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to create button effect in which will change its color on click and returns to its original colour after the click.
A conditional was added within the button effect to returns to its original code.
In this case I have four variables storing each color and instantiates for each button id in HTML.
// VARIABLES - ids from DOM instantiated as querySelector().
const btnBlue = document.querySelectorAll("#btnBlue");
const btnGreen = document.querySelectorAll("#btnGreen");
const btnRed = document.querySelectorAll("#btnRed");
const btnYellow = document.querySelectorAll("#btnYellow");
Giving an example of a button here is where I am stuck with the logic.
// Exemple with blue button:
$(btnBlue).click(function() {
$(this).css('background-color', '#00FFFF');
// the play() func does other logic such as join other functions
// together and flash all the buttons in different order.
blueBtnAudio.play();
if(btnBlue == '#00FFFF' ){
$(btnBlue).stop();
}
});
There's no need for any JS here. You can do this with CSS alone by using the :active pseudo-selector:
button {
background-color: #CCC;
border: 0;
border-radius: 5px;
padding: 10px 20px;
outline: 0;
}
button:active {
background-color: #C00;
color: #EEE;
}
<button>Click me</button>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have below issues for my select2 box.
1) I want to change the background-color to white of previously selected item. For eg when you open the select box and then hover on the next item the previous selected item has a background-color grey, which i want to change to white.
2) After an item is selected from the dropdown there are two borders displayed, want to get rid of one border in grey color.
Fiddle - https://jsfiddle.net/w50c4uqf/
Here is the CSS code which changes the color of previous selected item:
.select2-container--default .select2-results__option[aria-selected=true] {
background-color: #ddd; //Change this color
}
You can go inside select2.css file and change this directly like:
.select2-container--default .select2-results__option[aria-selected=true] {
background-color: #fff;
}
Here is the jsfiddle link: https://jsfiddle.net/w50c4uqf/5/
For removing the border you should add this line:
.select2-container--default .select2-selection--single:focus {
border: 0;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My goal is to display text on a screen as a user types it, with an underscore cursor showing after the text. The best way I can describe what I'm trying to do is a similar look to using the command line.
What is the best way to do this? I haven't been able to get it to work using a simple text input with css.
Here's something to get you started with jQuery.
$('input').on('input', function(e){
$('div').empty().text($(this).val());
});
Edit: blinking underscore can be done with CSS
div:after{
content:"_";
opacity:0;
animation:blink .500s linear infinite;
}
#keyframes blink{
from{opacity:0;}
to{opacity:1;}
}
The best way? Read the content on every keyup and then inject it into a destination container to show it to the user. Easy.
Check this: http://jsfiddle.net/VDd6C/8/
Show us your code. We'll help.
A basic one, try this (tested in Chrome and FF)
Play it here
HTML
<div>
<span contenteditable="true">Enter your input: </span><span class="blink">_</span>
</div>
JavaScript
window.setInterval(function(){
$('.blink').toggle();
}, 450);
CSS
body {
background-color: black;
color:white;
font-size: 15px;
font-weight:bold;
font-family: courier;
}
span {
border: none;
}
div {
max-width: 200px;
}
div:focus, span:focus{
outline: 0;
}