【问题标题】:Background left and other background right considering bootstrap columns [duplicate]考虑引导列的背景左侧和其他背景右侧[重复]
【发布时间】:2018-12-19 05:46:19
【问题描述】:

这就是我要做的:

我不知道如何才能实现这一点。以前的方法如下:

nav{
    background-image: -webkit-linear-gradient(156deg, #83817e 31%, #504e4b 31%);
    height: 50px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
      <nav>
        <div class="container">
            <div class="row">
                <div class="col-sm-9">
                  Left
                </div>
                <div class="col-sm-3">
                  Right
                </div>
            </div>
        </div>
    </nav>

我也尝试使用 after an before,但最大的问题是考虑到列的容器外部左右的背景

不幸的是,响应式的行为不正确,有人知道如何优雅地响应式地做到这一点?

【问题讨论】:

  • 嗨,Kamil,欢迎来到该网站。请在您的帖子中包含minimal reproducible example;您当前拥有的代码没有任何实际内容。
  • 为什么是-1?请正确阅读这个问题,我找不到这个问题的解决方案,它很棘手。也许提供帮助比按下拇指更好。
  • 这不是重复的,我有一个完全不同的问题。
  • 编辑您的问题以添加所有相关代码
  • 我正在编辑问题,所有相关代码都在那里

标签: html css


【解决方案1】:

您可以使用伪元素来添加除数。设置左侧为一种颜色,右侧为另一种颜色。然后,伪元素将包含实际的渐变。

nav{
    width: 100%;
    height: 30px;
}

nav .left {
 background-color: #504e4b;
 
}

nav .left::after {
  content: '';
  display: block;
  position: absolute;
  width: 30px;
  height: 100%;
  background-color: red;
  right: 0;
  background-image: -webkit-linear-gradient(156deg, #83817e 46%, white 46%, white 54%, #504e4b 54%);
}

nav .right {
  background-color: #83817e;
}

.row, .container, .right, .left {
  height: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<nav>
    <div class="container">
        <div class="row">
            <div class="col-sm-9 col left"></div>
            <div class="col-sm-3 col right"></div>
        </div>
    </div>
</nav>

【讨论】:

  • 谢谢,我觉得我的问题不太好。问题不是对角线,问题是容器外左右的背景。在您的示例中是容器中的背景,这很容易;)但我需要完整导航的背景。
猜你喜欢
  • 2012-11-28
  • 1970-01-01
  • 2015-05-05
  • 1970-01-01
  • 1970-01-01
  • 2016-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多