CSS 仅适用于放大的页面

标签 css

我有一个奇怪的问题。我的 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;
}

谢谢,

最佳答案

您可以通过设置 $("#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>

关于CSS 仅适用于放大的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51469101/

相关文章:

html - CSS/表格 : how to put two versions of a text side-by-side?

jquery - 在 wordpress 中使图像响应?

html - 如何在单行(行)中显示两个 HTML 输入元素

html - Flexbox 不遵守 overflow-x : hidden on body (Safari/iOS webkit)

javascript - WebGL 动画下的 HTML 内容不可点击

javascript - 如何在页面加载时加载隐藏div的JS内容

javascript - 如何在 WP7 中使用固定页脚定位 ·

html - 滚动时固定位置元素在 Chrome 中闪烁

html - 仅使用 CSS,无限时间循环播放 30 张图像,创造出燃烧的火焰效果

jquery - 在继续另一个元素时逐渐填充一个 div