#testdiv{ cursor:not-allowed; /* cursor:none;//例如视频界面隐藏鼠标 */ }
.testdiv{ width: 100px; height: 40px; position: relative; cursor: move; } .testdiv::before{ content: ''; position: absolute; top: -10px; left: -10px; right: 10px; bottom: 10px; cursor: move; }
利用伪元素。浏览器
<div class="testdiv"> <input type="checkbox" id="awesome"> <label for="awesome">Awesome</label> </div> input[type="checkbox"]+label::before{ content: '\a0'; display: inline-block; vertical-align: .2em; //vertical-align 属性设置元素的垂直对齐方式 width: .8em; height: .8em; margin-right: .2em; border-radius: .2em; background: silver; text-indent: .15em; //text-indent 属性规定文本块中首行文本的缩进。 line-height: .65; } input[type="checkbox"]:checked+label::before{ content: '\2713'; background: yellowgreen; } input[type="checkbox"]{ position: absolute; clip: rect(0,0,0,0) //clip 属性剪裁绝对定位元素。 }
定义和用法 <label> 标签为 input 元素定义标注(标记)。label 元素不会向用户呈现任何特殊效果。不过,它为鼠标用户改进了可用性。若是您在 label
元素内点击文本,就会触发此控件。就是说,当用户选择该标签时,浏览器就会自动将焦点转到和标签相关的表单控件上。spa<label> 标签的 for 属性应当与相关元素的 id 属性相同。3d
.overlay{ position: fixed; top: 0; bottom: 0; left: 0; right: 0; background: rgba(0, 0, 0, .8); } main{ background: blueviolet; } .lightbox{ position: absolute; z-index: 1; width: 200px; height: 100px; border: 1px solid red; background: yellowgreen; } <main><p>the backgroung</p></main> <div class="overlay"></div> <div class="lightbox"> <p>the lightbox</p> </div>
box-shadow: 0 0 0 50vmax rgba(0,0,0,.8);
*:有2个缺点:code
因为遮罩层的尺寸是与视口相关,而不是与页面相关的,当咱们滚动页面时,遮罩层的边缘就露出来了,除非给它加上position: fixed;
boxshadow 并无这种能力,所以它只能在视觉上起到引导注意力的做用,没法阻止鼠标交互。
main.de-emphasized { filter: blur(5px); word-wrap: break-word; }
.testdiv{ margin: 200px; overflow: auto; width: 10em; height: 8em; border: 1px solid silver; background: linear-gradient(white 15px,rgba(255,255,255,0)) , radial-gradient(at top,rgba(0,0,0,.2),transparent 70%) , linear-gradient(to top,white 15px,rgba(255,255,255,0)) , radial-gradient(at bottom,rgba(0,0,0,.2),transparent 70%); background-position: 0 0,0 0,100% 100%,100% 100%; background-size: 100% 50px,100% 15px,100% 50px,100% 15px; background-repeat: no-repeat; background-attachment: local,scroll,local,scroll; }
.testdiv{ position: relative; display: inline-block; } .testdiv>div{ position: absolute; top: 0; bottom: 0; left: 0; width: 50%; overflow: hidden; resize: horizontal; max-width: 100%; } .testdiv>div::before{ content: ''; position: absolute; bottom: 0; right: 0; width: 12px; height: 12px; padding: 5px; background: linear-gradient(-45deg,white 50% ,transparent 0); background-clip: content-box; cursor: ew-resize; } .testdiv img{ display: block; user-select: none; } <div class="testdiv"> <div> <img src="./2.jpg" alt="before"> </div> <img src="./2_1.jpg" alt="after"> </div>
function change() { var x=document.getElementById("range").value; document.getElementById("beImg").style.width=x+"%"; } #testdiv{ position: relative; display: inline-block; } #testdiv>div{ position: absolute; top: 0; left: 0; width: 50%; overflow: hidden; margin: 0; } #testdiv img{ display: block; user-select: none; } #range{ position: absolute; left: 0; bottom: 10px; width: 50%; margin: 0; filter: contrast(.5); mix-blend-mode: luminosity; transform: scale(2); transform-origin: left bottom; }