2013-11-14 46 views
0

我是新来的,所以我不知道它是如何工作的。 我正在尝试调整div,但不能调整父母的尺寸 这里我正在尝试。你能帮我吗。我想调整完整的父div中的蓝色div。 我没有得到我在代码中缺少的东西。 在此先感谢。可调整大小的遏制对我来说不起作用

<html> 
     <head> 
     <script src="http://code.jquery.com/jquery-1.8.2.js"></script> 
    <link href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet" /> 
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script> 
     <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
     <title>JS Bin</title> 
     <style type="text/css"> 
      * { 
      margin: 0px; 
      padding: 0px; 
      } 

      #Container { 
      position: absolute; 
      top: 0px; 
      left: 264px; 
      width: 312px; 
      height: 512px; 
      background-color: silver; 
      } 

      #Parent { 
      position: absolute; 
      top: 0px; 
      left: 0px; 
      width: 0px; 
      height: 0px; 
      } 

      #resizable { 
      position: absolute; 
      top: 0px; 
      left: 0px; 
      width: 256px; 
      height: 256px; 
      background-color: blue; 
      } 
     </style> 
     </head> 
     <body> 
     <div id="resizableContainer1" style="top: 6px; left: 0px; width: 256px; height: 512px; background-color: red;"> 
     </div> 
     <div id="Container"> 
      <div id="Parent"> 
      <div id="resizable"></div> 
      </div> 
     </div> 
     </body> 
<script> 
    $(document).ready(function() { 
     $("#resizable").resizable({ 
     "containment": "#Container" 
     }); 
    });</script> 
    </html> 
+0

为什么你有**#**家长有** 0像素**的宽度和高度。然后你试图调整其内部的孩子? –

+0

我试图改变身高,但它不起作用 – user2993331

回答

0

了解这个什么:

  • 除去宽度:0;高度:0;#Parent
  • 使#Parent相对
  • 变化遏制到#Parent
  • 移除CSS 位置:绝对;left:0;top:0;#resizable

例如:http://jsbin.com/aDUMelI/1/edit

$("#resizable").resizable({ 
    containment: "#Parent" 
}); 

CSS:

#Parent { 
     position: relative; 
     top: 0px; 
     left: 0px; 
     width:auto; 
     height:100%; 
} 

#resizable { 
     display:block; 
     width: 256px; 
     height: 256px; 
     background-color: blue; 
} 
+0

爱你乔纳森。感谢您的帮助。 – user2993331

0

刚刚起飞的双引号"containment"和你妈格不#Container,它是#Parent

你的脚本应该是,

$(document).ready(function() { 
     $("#resizable").resizable({ 
     containment: "#Parent" 
     }); 
    }); 
相关问题