使div自动展开宽度向左而不是向右

cra*_*bin 6 html css

我的网站上有一个div,其中包含一个用作菜单的项目列表.我设置了CSS,width:auto以便在菜单项太长时重新调整大小.目前,这将扩展到右侧,并将其余内容"推"到右侧.

这很难解释,所以如果你去http://redsquirrelsoftware.co.uk/点击支持菜单项,你可以看到正在推送的内容.我想要发生的是div扩展到菜单左侧的空白区域.

我目前为div提供的CSS是:

.sidebar1 {
    float: left;
    width: auto;
    min-width: 25%;
    max-width: 29%;
    margin-top: 65px;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    border-radius: 12px;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让它扩展另一种方式?提前致谢.

Ian*_*Ian 9

我发现在不使用浮点数或绝对定位的情况下执行此操作的另一种方法是direction: rtl在父项上使用,然后在子项上重置它:

.parent { direction: rtl; }
.parent > * { direction: ltr; }
.child { width: 200px; }
.child:hover { width: 400px; }
Run Code Online (Sandbox Code Playgroud)

代码笔:http://codepen.io/heisters/pen/gMgboJ

(对不起,我无法将示例建立在OP的网站上,因为链接似乎已经死了).


thi*_*dot 3

这个想法需要测试,但它至少在 Chrome 中有效:

  • .content和更改.sidebar1为。float: rightfloat: left
  • 在 HTML 中,.sidebar1移到.content.