【发布时间】:2016-02-10 15:05:03
【问题描述】:
如何为我的选择框添加下边距?
我已经试过了
#Selection { margin-bottom:23px; }
但这对我不起作用。有没有办法用 JavaScript 或 jQuery 做到这一点。
JsFiddle
片段如下:-
var startX = 0,
startY = 0,
started = false;
$(document).mousedown(function(e) {
e.preventDefault();
startX = e.pageX;
startY = e.pageY;
started = true;
$('#selection').css({
'top': startY,
'left': startX
});
});
$(document).mousemove(function(e) {
if (started) {
$('#selection').css({
'left': startX > e.pageX ? e.pageX : startX,
'top': startY > e.pageY ? e.pageY : startY
});
$('#selection').css({
'height': Math.abs(e.pageY - startY),
'width': Math.abs(e.pageX - startX)
});
}
});
$(document).mouseup(function() {
$('#selection').css({
'top': 0,
'left': 0,
'height': 0,
'width': 0
});
started = false;
startX = 0;
startY = 0;
});
$(document).on('contextmenu', function() {
return false;
});
body {
background:url(http://www.soyos.net/tl_files/demos/Windows-7-UI-and-Windows-Aero-for-Websites/win7-desktop-bg.jpg) no-repeat bottom center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
margin:0;
}
#container {
position: absolute;
width:100%;
height:90%;
top:0px;
}
#selection {
position: absolute;
background-color: rgba(0, 0, 0, 0.25);
-webkit-box-shadow:inset 0px 0px 0px 2px #f00;
-moz-box-shadow:inset 0px 0px 0px 2px #f00;
-ms-box-shadow:inset 0px 0px 0px 2px #f00;
-o-box-shadow:inset 0px 0px 0px 2px #f00;
box-shadow:inset 0px 0px 0px 2px #f00;
}
#bottom {
position:fixed;
background-color: rgba(255, 0, 0, 0.5);
width:100%;
height:10%;
text-align:center;
bottom:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<div id="selection"></div>
</div>
<div id="bottom">
<font size="+3" color="lime">don't want selection box here!</font>
</div>
【问题讨论】:
-
你想选择框在哪里?
-
@DinoMyte 我想把它放在里面。
标签: javascript jquery html css margin