2017-02-19 7 views
0

位置決めdivに問題があります。私はここでは次のCSS設定体の幅がdivの絶対位置を変更します

.popup{ 
    display: none; 
    text-align: center; 
    background: #eee; 
    max-width: 200px; 
    font-size: 2em; 
    color: #ff0000; 
    position: absolute; 
    border-radius: 10px; 
    z-index: 2;  
} 

はjavascriptのですしている:ここ

$("#main").click(function(event){ 
$("#popup").css({'left':event.pageX, 'top':event.pageY, 'display':'block'}); 
}); 

はHTML

<!DOCTYPE html> 


     <html> 
      <head> 
       <title>TODO supply a title</title> 
       <meta charset="UTF-8"> 
       <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" href="css/bootstrap.min.css"> 
     <link rel="shortcut icon" href="img/favicon-ksu.ico" type="image/x-icon"> 
     <link rel="stylesheet" href="css/bootstrap-theme.min.css"> 
     <link rel="stylesheet" href="css/main2.css"> 
      </head> 
      <body>  
      <div class="container"> 
       <div class="row">    
        <div class="col-md-12">     
         <h1 class="h1">Something Goes arround here <span style="color: red;">Something More here</span></h1> 
        </div> 
       </div> 
       <div class="row">   
       <div class="col-md-12">    

        <div class="helper" id="helper"> 
         Click Here! 
        </div> 
        <div class="popup" id="popup"> 
        oops! You clicked at wrong place. Try again! 
        </div>      
        <div class="workspace" id="workspace" contenteditable="true"></div> 
        <div id="main" class="main"> 

        </div>    

       </div>   
       </div> 
     </div><!-- /container --> 


     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
       <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script> 

       <script src="js/vendor/bootstrap.min.js"></script> 

      <script src="js/main2.js"></script>     
      </body> 
     </html> 

すべてはここまで細かいアップ働きに行きます!私は次のように指定する場合、

body { 
    padding: 0px; 
    width: 1230px; 
    margin: 0 auto;  
} 

のdivをクリックした場所に配置されていない。しかし、divがどこかに表示されます。私は何が間違っているのだろうかと思います!誰かが助けることができたら!

+0

が固定に位置を変更してみてください – Chiller

答えて

0

絶対位置から固定への位置変更はこの問題を解決します。これに代えて

.popup{ 
    display: none; 
    text-align: center; 
    background: #eee; 
    max-width: 200px; 
    font-size: 2em; 
    color: #ff0000; 
    position: absolute; 
    border-radius: 10px; 
    z-index: 2;  
} 

使用この:

.popup{ 
    display: none; 
    text-align: center; 
    background: #eee; 
    max-width: 200px; 
    font-size: 2em; 
    color: #ff0000; 
    position: fixed; 
    border-radius: 10px; 
    z-index: 2;  
} 
関連する問題