Css how to make inactive content inside div?

2019-03-17 10:53发布

Could you please help with some examples, 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. Any help will be appreciated.

标签: css layout html
3条回答
劳资没心,怎么记你
2楼-- · 2019-03-17 11:18

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;
}
查看更多
爷的心禁止访问
3楼-- · 2019-03-17 11:22

Without using an overlay, you can use pointer-events: none on the div in CSS, but this does not work in IE or Opera.

div.disabled
{
  pointer-events: none;

  /* for "disabled" effect */
  opacity: 0.5;
  background: #CCC;
}

Reference

查看更多
▲ chillily
4楼-- · 2019-03-17 11:27

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/

查看更多
登录 后发表回答