Does anybody know a way with JavaScript or CSS to basically grey out a certain part of a form/div in HTML?
I have a 'User Profile' form where I want to disable part of it for a 'Non-Premium' member, but want the user to see what is behind the form and place a 'Call to Action' on top of it.
Does anybody know an easy way to do this either via CSS or JavaScript?
Edit: I will make sure that the form doesn't work on server side so CSS or JavaScript will suffice.
You will have to call $('#messages-box'). children(). attr("disabled", "disabled"); This allows the input the be disable. and then you could just use other user "grey out css thing" to get the effect..
To disable div element and everything inside with CSS, we set the pointer-events CSS property of the div to none . to disable pointer events on the div with pointer-events set to none with CSS.
position:absolute You can also use position absolute as well as set all the viewport sides (top, right, bottom, left) to 0px will make the div take the full screen.
Add this to your HTML:
<div id="darkLayer" class="darkClass" style="display:none"></div>
And this to your CSS:
.darkClass { background-color: white; filter:alpha(opacity=50); /* IE */ opacity: 0.5; /* Safari, Opera */ -moz-opacity:0.50; /* FireFox */ z-index: 20; height: 100%; width: 100%; background-repeat:no-repeat; background-position:center; position:absolute; top: 0px; left: 0px; }
And finally this to turn it off and on with JavaScript:
function dimOff() { document.getElementById("darkLayer").style.display = "none"; } function dimOn() { document.getElementById("darkLayer").style.display = ""; }
Change the dimensions of the darkClass to suite your purposes.
You might try the jQuery BlockUI plugin. It's quite flexible and is very easy to use, if you don't mind the dependency on jQuery. It supports element-level blocking as well an overlay message, which seems to be what you need.
The code to use it is as simple as:
$('div.profileform').block({ message: '<h1>Premium Users only</h1>', });
You should also keep in mind that you may still need some sort of server-side protection to make sure that Non-Premium users can't use your form, since it'll be easy for people to access the form elements if they use something like Firebug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With