html - 当在内部 DIV 上使用 top 属性时,父 DIV 垂直调整大小

标签 html css

我有一个非常简单的示例,其中外部 DIV 未根据内容完全调整大小。问题是内部 DIV 的顶级属性,这使得它从父级中滑出。有没有办法垂直调整外部 DIV 的大小,无论是否使用 top 属性?我知道我可以为此使用 jQuery,但是否可以仅使用 CSS?

<div id="divPTX_01" style="position:relative;min-height:1px;overflow:hidden;min-width:1px; border: 1px solid red;">    			    	 
    <div style="position:relative;float:left;border:2px solid blue;top:130px;">
      <span>Test</span><br/>
      <span>Test</span><br/>
      <span>Test</span><br/>
      
      
      <span>Test 6</span><br/>
      <span>Test 7</span><br/>
      <span>Test</span><br/>
      <span>Test</span><br/>
      <span>Test</span><br/>
      
      
      <span>Test 6</span><br/>
      <span>Test 7</span><br/>
    </div>
      
</div>

最佳答案

尝试使用 margin-top 而不是 top

<div id="divPTX_01" style="position:relative;min-height:1px;overflow:hidden;min-width:1px; border: 1px solid red;">    			    	 
    <div style="position:relative;float:left;border:2px solid blue;margin-top:130px">
      <span>Test</span><br/>
      <span>Test</span><br/>
      <span>Test</span><br/>
      
      
      <span>Test 6</span><br/>
      <span>Test 7</span><br/>
      <span>Test</span><br/>
      <span>Test</span><br/>
      <span>Test</span><br/>
      
      
      <span>Test 6</span><br/>
      <span>Test 7</span><br/>
    </div>
      
</div>

关于html - 当在内部 DIV 上使用 top 属性时,父 DIV 垂直调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46094869/

相关文章:

asp.net - 复选框周围的空间

html - 我不明白绝对路径如何与本地/远程主机一起工作

php - 上传 Wordpress 站点

html - CSS3 : Width and margin transition simultaneously

javascript - 如何在 Angular Material 设计中包含网格布局?

JQuery 仅使用 html() 抓取特定文本

css - 为什么选择框默认在 WordPress 管理面板中滚动而不是下拉?

html - 左右交替 div 与包含一行的公共(public) div

html - 在 css 中重新创建动态表的最佳方法

css - 仅当当前字体没有某些字符时才使用自定义字体