I got a problem with my css in ionic...
I want to change the css, when a radiobutton is clicked. as shown below.
[type=radio]:checked + ion-icon {
background-color: $primaryColor;
color: white;
font-size: 45px;
}
The above css works on for the html tag but in ionic you have a tag called ion-radio. So is there a way to achieve the same, but with the radio button from ionic?
ion-radio:checked + ion-icon {
background-color: $primaryColor;
color: white;
font-size: 45px;
}
As far as I noticed from the docs, once an ion-radio is checked, it gets the class radio-checked.
Inspect your elements, don't they get this class too once they're checked?
I've fixed it by adding a class if a specific radiobutton is checked.
HTML:
<ion-icon [ngClass]="{'active': (gender == 'Female')}" name="female"></ion-icon>
CSS:
/* CHECKED STYLES */
ion-icon.active {
background-color: $primaryColor;
color: white;
font-size: 45px;
}
Related
This question already has answers here:
CSS Selector for <input type="?"
(4 answers)
Closed 4 years ago.
I’m trying to use CSS to make all my buttons this style:
button {
background-color: #4CAF50;
border: none;
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
But now, I have a different type of button where it is <input type=“button>. I tried changing the CSS to make it include buttons AND inputs like this:
button, input {
background-color: #4CAF50;
border: none;
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
The problem with that, it makes ALL inputs, like text fields green. So is there any way that I can make my inputs, ONLY ones that have the button type be styled?
Change
button, input
to
button, input[type="button"]
This uses CSS' attribute selector syntax. Or give your inputs of type button a common CSS class. Ex <input type="button" class="myButton"> and then change your selector to:
button, .myButton {...
Just add a class to whatever elements you want styled in that way, and target the class instead of button. CSS Classes
how could add css style to this button.
Button html:
<html>
<body>
<button onclick="myFunction()">Player</button>
<script>
function myFunction() {
alert('what ever');
}
</script>
</body>
</html>
CSS i want to add
<style>
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
If there is answered question, please send link. Thank you
You could add class="button" to the button to make it work. Cause your CSS .button will be used on every element which has the class="button"
function myFunction() {
alert('what ever')
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
<button class="button" onclick="myFunction()">Player</button>
Read more about how CSS Selectors work here
<button class="button" onclick="myFunction()">Player</button>
As your button class you've set it ".button" add "button" as a class like above
Anything you put after the . will match the name of the class in the element
https://css-tricks.com/the-difference-between-id-and-class/ explains how you use classes, ids and what they do in good detail
In your case, you're two solutions :
First : use classe, if you've differents buttons in your pages :
you can just add class attribute in your HTML element like that :
<html>
<body>
<button class="btn" onclick="myFunction()">Player</button>
<script>
function myFunction() {
alert('what ever');
}
</script>
</body>
</html>
And define the style in your class in your CSS :
<style>
.btn {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
Second : If all buttons are the same style, you can just add style for all element button :
Not change your HTML :
<html>
<body>
<button onclick="myFunction()">Player</button>
<script>
function myFunction() {
alert('what ever');
}
</script>
</body>
</html>
But, in your CSS, just change the reference, for select elements button :
<style>
button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
You can learn more explain about selector (.myClass, #myId, element) here in the mozilla developper website.
Don't forget, for optimize your web code, use as little code as possible, for reduce weight of pages, and to correctly use the different selectors (classes or id as not mandatory for CSS style : that depend to your utility) :)
Instead of declaring class button i.e(.button) you can apply style to all button elements.
Demo- https://jsfiddle.net/akshay193sw/bxm8wdqk/ Refer link
If you want to style a button I recommend adding a class to it and styling it with CSS. Here is an example below.
HTML Below
<button class='button_thing'> My Button </button>
CSS Below
.button_thing {
background-color: blue;
width: 180px;
height: 100px;
border-radius: 10px;
}
So what the CSS and HTML code above will do is it will create a blue button with a curved border and with a height of 100 pixels and width of 180 pixels. Now, the next question you might ask is how do I make an animation on the button when I hover over it?
CSS Hover Animations are a bit tricky at the start but get easier with practice. When I make buttons for my websites I like to use a site called ButtonAnimations because it gets straight to the point and gives me tons of animations (with HTML & CSS code) to choose from. Totally recommend it because it simply provides you with amazing buttons and animations that you can just copy and paste into your code. ButtonAnimations Website Link: ButtonAnimations - Create Spectacular Button Animations with HTML 7 CSS
<a>Link</a>
Can we prevent this element from having any hover effect without usin :hover?
I usually go:
a {
color= white;
}
a:hover {
color= white;
}
I've checked pointer-event= none; but it disabled the entire element and made it text.
You have some syntax error in your CSS, Please update your CSS with following code:
a, a:hover {
color: white;
}
a {
color: white !important;
}
/*
So you can actually see the white link
*/
div {
width: 50px;
height: 50px;
background-color: black;
}
<div>
link
</div>
or if you don't want to use :hover you just add !important in your default CSS
a {
color: white !important;
}
Note: for standard practice we don't use !important frequently. So you can add this css inline. You can check updated code below..
div {
width: 50px;
height: 50px;
background-color: black;
}
<div>
link
</div>
First of all. Don't use = inside CSS but use : instead.
To disable the hover (animation) do this:
a, a:hover {
color: white;
text-decoration: none;
}
a:hover {
cursor: text;
}
However, if you assign a href attribute the link will still be clickable.
This you cant disable by css but you need javascript or jquery for that.
Example
test
I tried this CSS:
html.dark .btn:hover:not(disabled),
html.dark .btn:focus {
color: #ffffff;
background-color: #222222;
*background-color: #151515;
}
html.dark .btn.disabled,
html.dark .btn[disabled] {
color: red;
background-color: #222222;
*background-color: #151515;
}
But still when I hover over the button I see the color change from red to white. Note that it's correctly picking up the fact it's disabled. I am using:
disabled="disabled"
in my button.
Try .btn:hover:not(:disabled),
A small example
Your example didn't work because you are using .btn:hover:not(disabled) you have to use a pseudo class to achieve what you need reference pseudo classes
button:hover:not(:disabled){
color:red;
}
<button>Not disabled</button>
<button disabled>disabled</button>
This question already has answers here:
Can I have an onclick effect in CSS?
(14 answers)
Closed 1 year ago.
How do I set a background color to my <button> when it's clicked using css?
.myBtn {
background-color: #fff;
cursor: pointer;
color: #000;
text-decoration: none;
text-transform: uppercase;
}
html:
<button type="button" class="myBtn">Highlight me when Clicked</button>
Use the active selector for this. Here's a working FIDDLE.
.myBtn:active {
background-color: #dd4814;
}
Check this for reference.
EDIT:
You can use the focus selector also
.myBtn:focus {
background-color: #dd4814;
}
But in this the color will change back again if the focus is lost from the button.
I guess you will need to take the help of Javascript or JQuery for changing the css rules on the click event of the button.
Sorry - but I don't have the rep to comment. But I think this may answer your question: Change background on button click, using CSS only?
EDIT: Oops. That looks like it changes the entire background - but you could probably still use it but change
input[type="checkbox"]:checked + div{
background: #5BC0DE;
}
to target the button by using the button class with something like this:
input[type="checkbox"]:checked + .mybtn{
background: #5BC0DE;
}
Edited answer:
<html>
<head>
<style>
.myBtn:active{
background-color: red;
}
.myBtn:visited{
background-color: red;
}
</style>
</head>
<body>
<button class ="myBtn">Click here to change bgcolor</button>
</body>
</html>
The following code is a snippet of SCSS.
:root {
--b1: beige;
--b2: brown;
--b3: #654321;
}
#check {
display: none;
}
.btn {
background-color: var(--b2);
padding: 5px;
border: 1px solid var(--b3);
font-family: Google Sans;
font-weight: 600;
color: var(--b1);
outline: none;
border-radius: 5px;
cursor: pointer;
}
.btn:hover {
background-color: darken(brown, 5);
border: 1px solid darken(#654321, 10);
}