CSS style not affecting child elements (buttons) - html

Right now if i add inactiveLink class to <a> it also affects buttons inside. They cant be clicked anymore. Do i have to make another style activeLink that turns those features back on or is there a way to only affect <a> element without affecting buttons inside?
If there is no other way, what are default cursor and pointer-events for Buttons?
HTML
<a class="text-body selectable-element inactiveLink">
[...]
<button>Click</button>
</a>
CSS
a.inactiveLink {
pointer-events: none;
cursor: default;
}

While the other answer will work (it was deleted as I was typing this), the real question is: If you want the anchor deactivated, should an active button really go inside it?
As the site/app scales, will other developers know what that class does? I think the CSS is fine the way it is, but the HTML could be moved around so those active elements exist outside the inactive anchor (perhaps in a shared parent element). Food for thought!
If you just want the quick fix, add the class "always-active" to the button, and add the following CSS:
.always-active {
cursor: auto;
pointer-events: auto;
}
a.inactiveLink {
pointer-events: none;
cursor: default;
}
button.always-active {
pointer-events: auto;
cursor: auto;
}
<a class="text-body selectable-element inactiveLink">
[...]
<button class="always-active" onClick="alert('it works')">Click</button>
</a>

Related

Hover Effect when over image

I think my classes or ID's are messed up when I try to call it.
CSS:
image#ply : hover .ply-text {
visibility: visible;
}
HTML:
<image id="ply" style="height: 50px; padding:5px;" src="images.png">
<div class="ply-text">
<p>Click for more info!</p>
</div>
Some issues first:
The HTML element for embedding images is called img.
An img element's content model is empty, i.e. it may not have any child elements.
Even if those were not issues, you would not see the effect you're looking for since the text is already visible at the start.
Given that, here's a possible solution:
.ply-text {
visibility: hidden;
}
#ply:hover ~ .ply-text {
visibility: visible;
}
The ~ is a sibling selector that allows one to refer to an element following another.
Images use an <img> tag (not 'image') - that's important to note (as it hasn't been commented on so far). As remarked, you should remove the space between the id and the :hover in your css.
I would advise you remove the inline style and use css or at least add it into your id style/ add extra attributes as a class in the head of the body (css is better!).
In the style, you don't need image/img before the definition of your id, you can just leave #ply{your style} on it's own.
If you want to display the pic on hover, I would use display:block/none instead. Visibility just shows it if it's hidden. (I've done so in the snippet, run and see if it's the desired effect). Also, use an alt tag! I added one. If you want to show/hide the text you could use either but first you have to set the visibility to hidden or display to none... I added a class for ply-text on its own for this.
So your code would read
#ply {
height: 50px;
padding: 5px;
}
.ply-text{
display:none; /* or visibility:hidden*/
}
#ply:hover +.ply-text{
display:block; /* or visibility:visible*/
}
<img id="ply" src="images.png" alt="plyimage">
<div class="ply-text">
<p>Click for more info!</p>
</div>
Hope this helps

Stop anchors from acting like hyperlinks when disabled

My anchor even after applying CSS styles to it when it's disabled still acts like hyperlink. Changes colour when hovered on.
I've spent some time on this already and almost giving up on this one. I want the magnifying glass to not change colour at all after hovering over it.
This is the anchor
<a href="" class="postcode-search-icon clickable"
ng-click="searchPostcode()" ng-disabled="true" title="Search Postcode">
</a href="">
And my current CSS styles attempt to fix it
.postcode-search-icon[disabled], .postcode-search-icon[disabled]:hover {
text-decoration: none;
cursor: not-allowed;
background-color: transparent;
}
What am I doing wrong?
In case you're wondering clickable class is just this so it doesn't matter
.clickable {
cursor: pointer;
}
#edit
Looks like applying color: (original colour) makes a temporary workaround until I find something better.
It seems like your css selector is wrong. The disabled pseudo class only works with input fields and not with anchors.
input[disabled="disabled"], input.disabled {
/* whatever you want */
}
Besides that, idk how you handle the addition of the clickable class, you need to handle that in order to not override styles.
If you are using Angular, you should be able to use a conditional class with the ngClass attribute. Not sure if you are using Angular 2, 3, 4, 5, or JS (here's the JS link for ng-class).
I think I would make the clickable item into a button, as well.
.bright:hover {
color: #0066ff;
cursor: pointer;
}
.dim:hover {
color: #ccc;
cursor: default;
}
<button ng-class="{bright: enabled, dim: disabled}"><i class="search-icon"></i> Search</button>

Override submit button image using css

I am working on a CSS userstyle and the problem is that I can't seem to modify images in buttons coded into a web page's html code:
<button type="submit" class="btn btn-default"><img alt="Ico-plus" src="//s.theoldreader.com/assets/ico-plus-369f50fa00968793b3c2e814f3e55de5.png"><i class="fa fa-spinner fa-spin" style="display:none;"></i></button>
the closest i can get to changing this through CSS is to change the code of the actual button and change its background through .subscribe-button-container .subscribe .dropdown-menu li form .control-group button{background-image:url("http://i.imgur.com/XYHilSy.png");}, rather than replace the image contained within it. It is possible to achieve what I am trying to do, or are such images simply hardcoded into the HTML?
I read these:
How to change an input button image using CSS?
Adding an image to submit button using CSS
Submit Button Image
but they all assume that I can modify the html code, while I can only try to override the css
You cannot modify HTML with CSS, you can only modify the appearance of HTML. Since the image url of an <img> is specified in HTML, you can't change it.
Here's what you can do:
Hide the image (display: none or opacity: 0)
Specify a background image for the button
Using a pseudo element as a sort of "stand-in" image tag may be worth exploring.
This solution will provide you with more flexibility in regards to styling this element in ways that wouldn't be possible with background images.
Think of the :pseudo-elementin this case as your "artificial img element" which serves as the "replacement" for the original img element you have now hidden.
.btn img {
display: none;
}
.btn:before {
content: "";
display: block;
background: url(https://s.theoldreader.com/assets/ico-plus-369f50fa00968793b3c2e814f3e55de5.png);
max-width: 18px;
max-height: 18px;
width: 18px;
height: 18px;
}
<button type="submit" class="btn btn-default"><img alt="Ico-plus" src="//s.theoldreader.com/assets/ico-plus-369f50fa00968793b3c2e814f3e55de5.png"><i class="fa fa-spinner fa-spin" style="display:none;"></i></button>
MDN
::before creates a pseudo-element that is the first child of the
element matched. It is often used to add cosmetic content to an
element by using the content property. This element is inline by
default.
https://developer.mozilla.org/en-US/docs/Web/CSS/::before

Using a label within a bootstrap nav

I have a bootstrap nav:
The highlighted bit is currently a list element of the nav and as such, the color changes on hover over and it is meant to be used as a navigation action. I would like to instead use it as a static label, meant to show the user something about where they are in the application. I know that I can added the class 'disabled' to make it look 'less' clickable, but it still changes slightly on hover over, and displays a cursor other than the default.
I'm hoping to have it display as a simple centered label that doesn't appear to be clickable in any way.
Using pointer-events: none; on the label will disable the element from registering any mouse events, including hover effects and bypassing the issue you had with it.
After writing this question I decided to just override Bootstrap's styles for the particular element in question so that they appear statically.
html:
<ul class="nav nav-tabs">
<li><a><span class="glyphicon glyphicon-menu-left"></span></a></li>
<li class="label-li disabled"></li>
<li href="#"><span class="glyphicon glyphicon-trash"></span> </a></li>
</ul>
css:
.label-li {
width: 80%;
font-weight: bold;
}
.label-li a {
width: 100%;
text-align: center;
cursor: default !important;
border: none !important;
}
the two lines ended by !important are what prevent's bootstrap's style from taking over.
While your solution does work, I would recommend instead looking at the :hover selector (http://www.w3schools.com/cssref/sel_hover.asp). This is what bootstrap does internally to create the various effects, and with it you can override all of the properties it assigns, such as the color and cursor change. Just assign them to the same values as normal using :hover and nothing will change, no need to use the !important.

Show another element when a text is clicked or make :focus display after loosing focus

My aim is to make the p tag with show class get displayed when the span (with Show Me text) is clicked. I had tried to do this using the :focus pseudo-selector but using this method makes the p tag get displayed only till somewhere else is clicked, where the p tag gets hidden again.
Is there any way to make the :focus selector display even after clicking away (or) is there a different/better way (without using JS) to display the p when the Show Me is clicked and make it stay that way even after clicking outside?
Fiddle Demo
HTML CODE
<span class="span1" tabindex="0">Show Me</span>
<p class="show" >This will show on click</p>
CSS CODE
body {
display: block;
}
.show {
display: none;
}
.span1:focus ~ .show {
display: block;
}
The :focus pseudo-class will not work because, as the naming indicates, it is applicable only when the focus is on the element and there is no way to make the focus 'stick' even after we click elsewhere.
An alternate way of achieving this would be to use the :target [1] pseudo-class/selector. This would make the p display whenever the link is clicked, since it is deemed as 'the target'.
body {
display: block;
}
.show {
display: none;
}
#content:target {
display: block;
}
<a class="span1" href='#content'>Show Me</a>
<p class="show" id='content'>This will show on click</p>
[1] - :target selector is not supported by IE <= 8.