How to make inactive content inside a div? - css

How to make content in some div block inactive using JavaScript?
Let's say there is a button with command "Enable / Disable". And there is one div block with some text. When pushing button "Enable / Disable", is it is "Enable", you can work with content inside, but when "Disable", you can't work with content inside div block.
I imagine in order to make inactive content inside div block, we need to put another layer upon that will prevent from editing content on the content div block.
I'm getting confused how to realize this kind of feature.

Without using an overlay, you can use pointer-events: none on the div using CSS.
div.disabled
{
pointer-events: none;
/* for "disabled" effect */
opacity: 0.5;
background: #CCC;
}
Reference

Set pointer-events as none for the div[disabled] in CSS,
div[disabled]
{
pointer-events: none;
opacity: 0.7;
}
You can make div disabled by adding disabled attributes.
<div disabled>
<!-- Contents -->
</div>

div[disabled]
{
pointer-events: none;
opacity: 0.6;
background: rgba(200, 54, 54, 0.5);
background-color: yellow;
filter: alpha(opacity=50);
zoom: 1;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
-moz-opacity: 0.5;
-khtml-opacity: 0.5;
}

Using jquery you might do something like this:
// To disable
$('#targetDiv').children().attr('disabled', 'disabled');
// To enable
$('#targetDiv').children().attr('enabled', 'enabled');
Here's a jsFiddle example: http://jsfiddle.net/monknomo/gLukqygq/
You could also select the target div's children and add a "disabled" css class to them with different visual properties as a callout.
//disable by adding disabled class
$('#targetDiv').children().addClass("disabled");
//enable by removing the disabled class
$('#targetDiv').children().removeClass("disabled");
Here's a jsFiddle with the as an example: https://jsfiddle.net/monknomo/g8zt9t3m/

if you want to hide a whole div from the view in another screen size. You can follow bellow code as an example.
div.disabled{
display: none;
}

Related

Agm info window custom css

I have created a agm-info-window that has an image and a small text (tittle):
<agm-marker [latitude]="lat3" [longitude]="lng3" [iconUrl]="icon">
<agm-info-window [disableAutoPan]="true" [isOpen]="true">
<div routerLink="/sight/2">
<img src="assets/mesta/tvrdjava.jpg" alt="Image" width="80" height="80"> <br>
<span class="window-title"> Bubanj </span>
</div>
</agm-info-window>
</agm-marker>
This is the result:
I want to change the info window css. - The background color, remove the close button (x) and put the text in the center. Like so:
I get the correct effect when I set the CSS in Chrome's inspector. I set:
/* Remove the X, close button */
.gm-ui-hover-effect {
display: none;
}
.gm-style-iw {
padding: 0;
background-color: #AAAAAA;
text-align: center;
color: white;
}
/* remove overflow scroll */
.gm-style-iw-d {
overflow: none;
}
But when I put this same css in the components css, it doesn't change at all, nothing changes.
I don't have a lot of changes, so I would prefer not to use snazzy info window. I just want these small changes to the window. Is it possible ? Why is the css not working ?
Use this CSS in styles.css as component css is having low priorities
Try to add css in he same page under the div. Maybe there are cinflict b/w that's why it doesn't change anything.

:hover pseudo state not triggering in IE

I have this markup
<button class="toggle" aria-label="Toggle">
<div class="globe-img"></div>
</button>
and this SASS:
.globe-img {
background-image: url('../images/globe.png');
height: 50px;
width: 50px;
&:hover {
background-image: url('../images/globe-hv.png');
}
}
It works in all the latest browsers but IE. The hover pseudo state does not trigger in IE. I have found a number of questions on Stackoverflow about this, but they are all older and have not provided a solution (yet), so I figured it might be worth asking again.
Note that both states have a background image defined. I have added z-index and tried an IMG tag instead of the DIV. I tried display:block and added background colors. I appreciate any new pointers. If nothing else, I will just use Javascript to add a regular CSS class upon hover.
I could be wrong since I don't have IE to test...
I'm guessing the button as a wrapper is the issue. I assume the button's hover state clobbers the div's hover state. Does it work if you remove the <button>?
Alternately does it work if you move the hover to the button?
.globe-img {
background-image: url('../images/globe.png');
height: 50px;
width: 50px;
}
button:hover .globe-img {
background-image: url('../images/globe-hv.png');
}

Changing :hover to touch/click for mobile devices

I've had a look around but can't quite find what i'm looking for.
I currently have a css animation on my page which is triggered by :hover. I would like this to change to 'click' or 'touch' when the page is resized past width 700px using media queries.
Here is what i have at the moment: http://jsfiddle.net/danieljoseph/3p6Kz/
As you can see, the :hover will not work on mobile devices but i still want to ensure it works the same way just by click, not hover.
I would rather use css if possible but happy with JQuery also.
I have a feeling this is very easy to do but i am just missing something very obvious! Any help would be appreciated.
Here is the css animation:
.info-slide {
position:absolute;
bottom:0;
float:left;
width:100%;
background:url(../images/blue-back.png);
height:60px;
cursor:pointer;
overflow:hidden;
text-align:center;
transition: height .4s ease-in-out;
-webkit-transition: height .4s ease-in-out;
-moz-transition: height .4s ease-in-out;
}
.info-slide:hover {
height:300px;
}
If you use :active selector in combination with :hover you can achieve this according to w3schools as long as the :active selector is called after the :hover selector.
.info-slide:hover, .info-slide:active{
height:300px;
}
You'd have to test the FIDDLE in a mobile environment. I can't at the moment.
correction - I just tested in a mobile, it works fine
You can add onclick="" to hovered element. Hover will work after that.
Edit: But you really shouldn't add anything style related to your markup, just posted it as an alternative.
document.addEventListener("touchstart", function() {}, true);
This snippet will enable hover effects for touchscreens
I got the same trouble, in mobile device with Microsoft's Edge browser. I can solve the problem with: aria-haspopup="true". It need to add to the div and the :hover, :active, :focus for the other mobile browsers.
Example html:
<div class="left_bar" aria-haspopup="true">
CSS:
.left_bar:hover, .left_bar:focus, .left_bar:active{
left: 0%;
}
On most devices, the other answers work. For me, to ensure it worked on every device (in react) I had to wrap it in an anchor tag <a> and add the following:
:hover, :focus, :active (in that order), as well as role="button" and tabIndex="0".
I am a CSS noob but I have noticed that hover will work for touch screens so long as it's a "hoverable" element: image, link, button. You can do it all with CSS using the following trick.
Change your div background to an actual image tag within the div or create a dummy link around the entire div, it will then register as a hover when you touch the image.
Doing this will mean that you need the rest of your page to also be "hoverable" so when you touch outside of the image it recognizes that info-slide:hover has ended. My trick is to make all of my other content dummy links.
It's not very elegant but it works.
A CSS only solution for those who are having trouble with mobile touchscreen button styling.
This will fix your hover-stick / active button problems.
body, html {
width: 600px;
}
p {
font-size: 20px;
}
button {
border: none;
width: 200px;
height: 60px;
border-radius: 30px;
background: #00aeff;
font-size: 20px;
}
button:active {
background: black;
color: white;
}
.delayed {
transition: all 0.2s;
transition-delay: 300ms;
}
.delayed:active {
transition: none;
}
<h1>Sticky styles for better touch screen buttons!</h1>
<button>Normal button</button>
<button class="delayed"><a href="https://www.google.com"/>Delayed style</a></button>
<p>The CSS :active psuedo style is displayed between the time when a user touches down (when finger contacts screen) on a element to the time when the touch up (when finger leaves the screen) occures. With a typical touch-screen tap interaction, the time of which the :active psuedo style is displayed can be very small resulting in the :active state not showing or being missed by the user entirely. This can cause issues with users not undertanding if their button presses have actually reigstered or not.</p>
<p>Having the the :active styling stick around for a few hundred more milliseconds after touch up would would improve user understanding when they have interacted with a button.</p>
Well I agree with above answers but still there can be an another way to do this and it is by using media queries.
Suppose this is what you want to do :
body.nontouch nav a:hover {
background: yellow;
}
then you can do this by media query as :
#media(hover: hover) and (pointer: fine) {
nav a:hover {
background: yellow;
}
}
And for more details you can visit this page.
I think this simple method can achieve this goal.
With CSS you can turn off pointer event to 'none' then use jQuery to switch classes.
.item{
pointer-events:none;
}
.item.clicked{
pointer-events:inherit;
}
.item:hover,.item:active{
/* Your Style On Hover Converted to Tap*/
background:#000;
}
Use jQuery to switch classed:
jQuery('.item').click(function(e){
e.preventDefault();
$(this).addClass('clicked')l
});

How do I create CSS only tabs/pages with #hash URLs?

I'm trying to create a single page site that uses CSS to navigate between different content.
I've read about :target and understand that this site will only work in Chrome, Firefox, IE9+, Safari, and Opera 9.5+.
How can I implement a CSS only navigation where only one section is visible at one time?
full demo
uses this menu.
Layout
To do this, first layout your document so that you have multiple .pages, and each has a unique id.
<div class="page" id="home">
<h1>Home</h1>
<div class="body">
</div>
</div>
Then create a menu, or some other structure that contains links. These should have hashes that match your ids. For example id="home" and href="#home".
<ul>
<li>HOME</li>
</ul>
CSS
You now have to decide how you want your pages to transition. I choose to use a combination of top and opacity.
Also note, that it's highly recommended to set your elements initial position to the top of the page. When you click one of those links, the browser will automatically make the top-left of the element visible. If you want it to move horizontally or vertically, place an element inside it, and transition its position (for example, h1 or .body).
.page {
width: 100%;
position: absolute;
top: -500em; left: 0;
max-height: 0;
transition: all .5s ease; /* vendor prefixes recommended */
pointer-events: none;
}
Any styles with :target take effect when the hash in the url is equal to an elements id. For example, this style will become active for #home.page when #home is the URL's hash.
.page:target {
max-height: 300%;
pointer-events: auto;
top: 13em;
}
You can also animate children of an active page, but remember to do .page:target h1 and not .page h1:target (there is only one or zero target elements at any one time).
.page > h1, .page > .body {
transition: all .5s cubic-bezier(1, .38, .70, 0);
opacity: 0;
}
.page:target > h1, .page:target > .body {
opacity: 1;
}
JavaScript (optional)
To help out JavaScript users a bit, we can tell the page to default to #home if there's no hash already set.
location.hash = location.hash || "home";
You could also do a redirect on your server using something like Apache's mod_rewrite.

why doesn't my basic CSS code for hide and display work?

Im using google chrome and i want that profile text with the background to disappear when i hover over it. but alas it doesn't... i'm sure im doing something fundamentally wrong. please explain
HTML
<body>
<div id ="pictures">
profile
</div>
CSS
#pictures {
height: 100px;
width: 200px;
display: block;
background-color:#FCC;
}
#pictures:hover {
display: none;
}
You'd be better off using opacity: 0 to avoid any weirdness (as already explained by Danjah).
http://jsfiddle.net/UenGP/2/
#pictures:hover {
opacity: 0;
filter: alpha(opacity=0);
}
If you hover over the #pictures element, it is then removed, therefore you are no longer hovering over it. In Firefox I see a flicker, in Chrome, perhaps the flicker is so fast you don't see it disappear only to reappear again.

Resources