Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS/JavaScript Use Div to grey out section of page

Tags:

javascript

css

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.

like image 824
ncyankee Avatar asked Oct 01 '08 21:10

ncyankee


People also ask

How do I gray out a div in CSS?

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..

How do you make a div disabled using CSS?

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.

How do I make a div cover the whole page?

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.


2 Answers

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.

like image 135
dacracot Avatar answered Sep 19 '22 15:09

dacracot


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.

like image 23
Mike Avatar answered Sep 21 '22 15:09

Mike