【问题标题】:Bootstrap 4 container with full width image具有全宽图像的 Bootstrap 4 容器
【发布时间】:2017-11-13 05:43:51
【问题描述】:

它不必是引导程序 4。我被卡住了,需要帮助。试图将页面分为 2 个部分。左侧有全宽 bg 图像。这就是问题所在,需要 css 和 html 方面的帮助

我的html代码:

<div class=left-bg-img>
<div class="container">
<div class="col-sm-6">
<p>Left content goes here.</p>
</div>
<div/><!--left-bg-->

<div class="col-sm-6">
<p>Right content goes here.</p>
</div>
</div>

image example

【问题讨论】:

    标签: html css twitter-bootstrap image


    【解决方案1】:

    使用 Bootstrap 4,这可以工作...

    <section>
      <div class="side-image"></div>
      <div class="container">
        <div class="row">
          <div class="col-sm-6 ml-sm-auto">
            <p>Some content over to the right.</p>
          </div>
        </div>
      </div>
    </section>
    
    <style>
    .section-with-side-image {
      position: relative;
    }
    .side-image {
      position:absolute;
      top:0;
      bottom:0;
      right: 50%;
      left: 0;
      background-image: url('http://placehold.it/900/');
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
    }
    </style>
    

    https://codepen.io/Gwapedwink/pen/JOgXJw

    注意:您似乎忘记了列周围的.row。所以你会在我的例子中看到这一点。

    第二个注意事项:我在 col-sm-6 中添加了 .ml-sm-auto 类,因为它不需要 filler 或偏移量,但不是这样Bootstrap 4 有效。

    【讨论】:

      【解决方案2】:

      一个没有引导的例子:

      body {
        padding: 0;
        margin: 0;
        background: #444;
        direction: rtl;
      }
      
      .split-container {
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -webkit-flex-direction: row;
        -ms-flex-direction: row;
        flex-direction: row;
        display: -webkit-box;
        display: -webkit-flex;
        display: -ms-flexbox;
        display: flex;
      }
      
      .split-item {
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        -ms-flex-pack: center;
        justify-content: center;
        
        display: -webkit-box;
        display: -webkit-flex;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -webkit-flex-direction: column;
        -ms-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: center;
        -webkit-align-items: center;
        -ms-flex-align: center;
        align-items: center;
        
        width: 50%;
        padding: 3em 5em 6em 5em;
      }
      
      .split-right {
        -webkit-box-ordinal-group: 0;
        -webkit-order: -1;
        -ms-flex-order: -1;
        order: -1;
        
        color: #7b5a9e;
        background: #fff;
      }
      
      .split-left {
        background: #7b5a9e;
        color: #fff; 
      }
      
      .split-image img {
        border: 5px solid rgba(0,0,0,0.2);
        width: 100%;
        height: auto;
        margin: 2em auto;
        border-radius: 50%;
        max-width: 100px;
        display: block;
      }
      
      .split-item h3 {
        text-align: center;
        margin: 0 0 2em 0;
        font-weight: 700;
      }
      
      .split-item p {
        text-align: center;
        margin: 0 auto;
        max-width: 500px;
        line-height: 1.5;
      }
      
      .split-item a {
        color: currentColor;
        display: block;
        text-align: center;
        margin: 1em 0 0 0;
        width: 100%;
      }
      <div class="split-container">
        <div class="split-item split-left">
          <div class="split-image">
            <img src="http://upload.wikimedia.org/wikipedia/commons/8/89/William.IV.of.Great.Britain.JPG">
          </div>
          <h3>ויליאם הרביעי</h3>
          <p>
            ויליאם הרביעי (נולד בשם ויליאם הנרי; 21 באוגוסט 1765 - 20 ביוני 1837) 
            היה מלך הממלכה המאוחדת של בריטניה הגדולה ואירלנד ומלך הנובר מ-26 
            ביוני 1830 ועד יום מותו.
          </p>
          <a target="_blank" href="http://he.wikipedia.org/wiki/%D7%95%D7%99%D7%9C%D7%99%D7%90%D7%9D_%D7%94%D7%A8%D7%91%D7%99%D7%A2%D7%99,_%D7%9E%D7%9C%D7%9A_%D7%94%D7%9E%D7%9E%D7%9C%D7%9B%D7%94_%D7%94%D7%9E%D7%90%D7%95%D7%97%D7%93%D7%AA">קרא עוד</a>		
        </div>
        <div class="split-item split-right">
          <div class="split-image">
            <img src="http://upload.wikimedia.org/wikipedia/commons/b/ba/King_George_V_1911_color-crop.jpg">
          </div>
          <h3>ג'ורג' החמישי</h3>
          <p>
            ג'ורג' החמישי (3 ביוני 1865 - 20 בינואר 1936), 
            הידוע גם בשמו המלא ג'ורג' פרדריק ארנסט אלברט, היה מלך הממלכה 
            המאוחדת והדומיניונים הבריטים.
          </p>
          <a target="_blank" href="http://he.wikipedia.org/wiki/%D7%92%27%D7%95%D7%A8%D7%92%27_%D7%94%D7%97%D7%9E%D7%99%D7%A9%D7%99,_%D7%9E%D7%9C%D7%9A_%D7%94%D7%9E%D7%9E%D7%9C%D7%9B%D7%94_%D7%94%D7%9E%D7%90%D7%95%D7%97%D7%93%D7%AA">קרא עוד</a>
        </div>
      </div>

      【讨论】:

      • 对不起,我将“不需要引导 4”解释为“不需要引导”。其他答案涵盖了我认为的引导版本
      【解决方案3】:
      .left-bg-img{
          background-image: url("your image url");
          background-size: cover;
          background-repeat: no-repeat;
      } 
      
      <div class="row">
          <div class="col-sm-6 left-bg-img" style="text-align: center">
              <p>Left content goes here.</p>
          </div>
          <div class="col-sm-6" style="text-align: center">
              <p>Right content goes here.</p>
          </div>
      </div>
      

      【讨论】:

        【解决方案4】:

        嘿,我认为您需要添加一个类行来完美划分您的内容:

        <div class="row"> <div class="col-sm-6 bg"></div> <div class="col-sm-6"></div> </div>

        如果您想要页面左侧的背景图片,只需使用:

        background:url("your url of image"); background-size:cover;

        这样就可以得到带有背景图片的左分割,完美分割。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-12-22
          • 1970-01-01
          • 1970-01-01
          • 2014-10-30
          • 1970-01-01
          • 1970-01-01
          • 2021-03-24
          • 2017-01-24
          相关资源
          最近更新 更多