我有一个奇怪的问题。我的CSS仅适用于缩放页面。当页面尺寸为100%,并且我右键单击输入时CSS不起作用时,我必须放大到35%或更低,以便上下文菜单出现。如果我缩小到50%,它会再次消失。 我的代码中导致问题的部分在此JsFiddle http://jsfiddle.net/6ny94/1323/
中这是我完整的CSS:
body {
font-family: Arial, Helvetica, sans-serif;
padding-bottom: 20px;
padding-left: 20px;
width: 1200px;
}
.adCounter {
background: #313131;
border-bottom-right-radius: 3px;
border-top-right-radius: 3px;
color: #fff;
float: right;
font-size: 14px;
padding: 6px 9px;
position: relative;
right: 1px;
top: -33px;
min-width: 34px;
}
.adCounter2 {
background: #313131;
border-bottom-right-radius: 3px;
border-top-right-radius: 3px;
color: #fff;
float: right;
font-size: 14px;
padding: 13px 9px;
position: relative;
right: 1px;
top: -33px;
min-width: 34px;
min-height: 53px;
}
#myBtn {
display: none; /* Hidden by default */
position: fixed; /* Fixed/sticky position */
bottom: 20px; /* Place the button at the bottom of the page */
right: 30px; /* Place the button 30px from the right */
z-index: 99; /* Make sure it does not overlap */
border: none; /* Remove borders */
outline: none; /* Remove outline */
background-color: #000000; /* Set a background color */
color: white; /* Text color */
cursor: pointer; /* Add a mouse pointer on hover */
padding: 8px; /* Some padding */
border-radius: 8px; /* Rounded corners */
font-size: 18px; /* Increase font size */
}
.myBtn1 {
background-color: #3cba54;
color: white;
padding: 5px;
border-radius: 4px;
font-size: 14px;
border-width: inherit;
cursor:pointer;
}
.myBtn2 {
background-color: #879383;
color: white;
padding: 5px;
border-radius: 4px;
font-size: 14px;
border-width: inherit;
cursor:pointer;
}
.myBtn3 {
background-color: #f4c20d;
color: white;
padding: 5px;
border-radius: 4px;
font-size: 14px;
border-width: inherit;
cursor:pointer;
}
.myBtn4 {
background-color: #db3236;
color: white;
padding: 5px;
border-radius: 4px;
font-size: 14px;
border-width: inherit;
cursor:pointer;
}
#description {
width: 350px;
float:left;
min-height: 32px;
}
[id^="description2"] {
width: 350px;
float:left;
min-height: 32px;
}
#previewBox{
float: right;
margin-right: 259px;
margin-top: -311px;
width: 518px;
font-size: 12px;
box-shadow: 1px 1px 2px 2px #ccc;
padding-bottom: 12px;
border-radius: 3px;
}
[id^="previewBox1"]{
float: right;
}
.previewBox1{
width: 466px;
font-size: 12px;
box-shadow: 1px 1px 2px 2px #ccc;
padding-bottom: 12px;
border-radius: 3px;
margin-bottom: 12px;
}
#descriptiontext{
width: 120px;
}
.deleteAd{
background-color: red;
color: white;
padding: 5px;
border-radius: 5px;
border: 0;
margin-left: 18px;
margin-right: 14px;
padding-bottom: -13px;
margin-top: -26px;
}
.duplicateAd{
background-color: #aaa;
color: white;
padding: 5px;
border-radius: 5px;
border: 0;
margin-right: 16px;
padding-bottom: -13px;
margin-top: -26px;
}
/* The snackbar - position it at the bottom and in the middle of the screen */
#DuplicateSuccessMessage {
visibility: hidden; /* Hidden by default. Visible on click */
opacity: 0.7;
filter: alpha(opacity=50); /* For IE8 and earlier */
min-width: 250px; /* Set a default minimum width */
margin-left: -125px; /* Divide value of min-width by 2 */
background-color: #000; /* Black background color */
color: #fff; /* White text color */
text-align: center; /* Centered text */
border-radius: 2px; /* Rounded borders */
padding: 16px; /* Padding */
position: fixed; /* Sit on top of the screen */
z-index: 1; /* Add a z-index if needed */
left: 50%; /* Center the snackbar */
bottom: 50%; /* 30px from the bottom */
}
/* Show the snackbar when clicking on a button (class added with JavaScript) */
#DuplicateSuccessMessage.show {
visibility: visible; /* Show the snackbar */
/* Add animation: Take 0.5 seconds to fade in and out the snackbar.
However, delay the fade out process for 2.5 seconds */
-webkit-animation: fadein 0.5s, fadeout 0.5s 1.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
/* The snackbar - position it at the bottom and in the middle of the screen */
#errorMessage {
visibility: hidden; /* Hidden by default. Visible on click */
opacity: 1;
filter: alpha(opacity=50); /* For IE8 and earlier */
min-width: 250px; /* Set a default minimum width */
margin-left: -125px; /* Divide value of min-width by 2 */
background-color: #f2dede; /* Black background color */
color: #a94442; /* White text color */
text-align: center; /* Centered text */
border-radius: 2px; /* Rounded borders */
padding: 16px; /* Padding */
position: fixed; /* Sit on top of the screen */
z-index: 1; /* Add a z-index if needed */
left: 50%; /* Center the snackbar */
bottom: 50%; /* 30px from the bottom */
}
/* Show the snackbar when clicking on a button (class added with JavaScript) */
#errorMessage.show {
visibility: visible; /* Show the snackbar */
/* Add animation: Take 0.5 seconds to fade in and out the snackbar.
However, delay the fade out process for 2.5 seconds */
-webkit-animation: fadein 0.5s, fadeout 0.5s 1.5s;
animation: fadein 0.5s, fadeout 0.5s 5s;
}
/* Animations to fade the snackbar in and out */
@-webkit-keyframes fadein {
from {bottom: 50%; opacity: 0;}
to {bottom: 50%; opacity: 0.7;}
}
@keyframes fadein {
from {bottom: 50%; opacity: 0;}
to {bottom: 50%; opacity: 0.7;}
}
@-webkit-keyframes fadeout {
from {bottom: 50%; opacity: 0.7;}
to {bottom: 50%; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 50%; opacity: 0.7;}
to {bottom: 50%; opacity: 0;}
}
.ajax-loader {
visibility: hidden;
background-color: rgba(0,0,0,0.2);
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
}
.ajax-loader img {
position: relative;
top:50%;
left:50%;
}
.toggle{
background-color: #4285f4;
color: white;
padding: 5px;
border-radius: 5px;
border: 0;
margin-left: 18px;
}
#items{
list-style:none;
margin:0px;
margin-top:4px;
padding-left:10px;
padding-right:10px;
padding-bottom:3px;
font-size:17px;
color: #333333;
}
hr { width: 85%;
background-color:#E4E4E4;
border-color:#E4E4E4;
color:#E4E4E4;
}
#cntnr{
display:none;
position:fixed;
border:1px solid #B2B2B2;
width:180px;
background:#F9F9F9;
box-shadow: 3px 3px 2px #E9E9E9;
border-radius:4px;
}
#items li{
padding: 3px;
padding-left:10px;
}
#items :hover{
color: white;
background:#284570;
border-radius:2px;
}
谢谢
答案 0 :(得分:0)
您可以通过设置$("#cntnr").css({"left": e.pageX-3, "top": e.pageY-3});
来解决此问题,这样鼠标光标便会出现在上下文菜单和...中。
function setInputSelection(input, startPos, endPos) {
input.focus();
if (typeof input.selectionStart != "undefined") {
input.selectionStart = startPos;
input.selectionEnd = endPos;
} else if (document.selection && document.selection.createRange) {
// IE branch
input.select();
var range = document.selection.createRange();
range.collapse(true);
range.moveEnd("character", endPos);
range.moveStart("character", startPos);
range.select();
}
}
$("[id*='headline']").bind("contextmenu", function(e) {
e.preventDefault();
$("#cntnr").css({"left": e.pageX-3, "top": e.pageY-3});
$("#cntnr").fadeIn(200, startFocusOut);
});
function startFocusOut() {
$(document).on("click", function() {
$("#cntnr").hide();
$(document).off("click");
});
}
$("#items > li").click(function() {
$("#headline1").val($(this).text().replace("fallback", " "));
var input = document.getElementById("headline1");
setInputSelection(input, 9, 10);
});
#items {
list-style: none;
margin: 0px;
margin-top: 4px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 3px;
font-size: 17px;
color: #333333;
}
hr {
width: 85%;
background-color: #E4E4E4;
border-color: #E4E4E4;
color: #E4E4E4;
}
#cntnr {
display: none;
position: fixed;
border: 1px solid #B2B2B2;
width: 180px;
background: #F9F9F9;
box-shadow: 3px 3px 2px #E9E9E9;
border-radius: 4px;
}
li {
padding: 3px;
padding-left: 10px;
}
#items :hover {
color: white;
background: #284570;
border-radius: 2px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Demo<input id="headline11">
<div id='cntnr'>
<ul id='items'>
<li>{Keyword:fallback}</li>
<li>{KeyWord:fallback}</li>
</ul>
</div>