【问题标题】:How to set margin for elements in my case在我的情况下如何为元素设置边距
【发布时间】:2015-10-28 06:24:24
【问题描述】:

我正在尝试为我的应用创建响应视图。

目前我有两列

左边的应该是灵活的,取决于浏览器的宽度,右边的宽度设置为 120px。

html

<div class="wrapper row">
    <div class="left col-xs-9">
        This is the left column
    </div>
     <div class="right col-xs-3">
         Right column
     </div>
</div>

CSS

.wrapper {
    background-color: blue;
    color: #fff;
}
.left {
    margin-right:20px;
    background-color: red;
}
.right {
    width: 120px;
    background-color: green;
}

问题是无论浏览器宽度是多少,我都需要在这两列之间留出 20px 的边距,而右边的则保持 120px 的宽度。我该怎么做呢?谢谢。

http://jsfiddle.net/4ufk1xxc/2/

【问题讨论】:

  • 它不是已经在做你想做的事了吗?
  • 否,如果缩小浏览器宽度,右栏会被推到第二行
  • 下面的呢? jsfiddle.net/4ufk1xxc/3

标签: html css twitter-bootstrap-3


【解决方案1】:

将包装器更改为 flexbox 即可解决问题:

.wrapper {
  display: flex;
}

Updated Fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2013-01-31
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    相关资源
    最近更新 更多