如何将嵌套div与包含div的右侧对齐

lka*_*htz 2 html css jquery

我需要嵌套div体的整个块与包含div的右边界对齐?使用css或jquery都很酷.

Luk*_*uke 6

你试过这个吗?{ float:right }?


Sco*_*own 5

CSS

.div1 { overflow: hidden; width: 500px; } /* this will clear your float. width given for example purposes */
.div2 { float: right; width: 200px; }
Run Code Online (Sandbox Code Playgroud)

HTML

<div class="div1">
  <div class="div2">
    <p>div 2 contents</p>
  </div>
  <p>div 1 contents</p>
</div>
Run Code Online (Sandbox Code Playgroud)


lsu*_*rez 5

如果你想让它保留块显示和静态位置:

.inner { width: ##px, margin-left: auto; margin-right: 0 }
Run Code Online (Sandbox Code Playgroud)