绝对图像左侧在容器中

时间:2016-10-28 21:25:51

标签: html css css-position

我使用的是基础网格,但是我需要保留这个网格并制作一个带有全宽图像的绝对左右列,我已经在图像的左侧和左侧的文本和灰色背景。但我无法做出同样的事情,即图像应该在左侧,灰色背景在右侧。

enter code here
<div class="form-banner form-banner--medium form-banner-placement--right">
    <div class="form-banner-container">
      <div class="form-banner-wrapper form-banner-wrapper--original"><img src="https://dummyimage.com/600x400/blue/fff&text=image+here">
        <div class="form-banner-left">
          <div class="row">
            <div class="columns"><span class="tag">recommended</span>
                <div class="spacer-15">&nbsp;</div>
              <h3>Monitoring</h3>
                <div class="spacer-30">&nbsp;</div>
              <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias distinctio explicabo suscipit eligendi ratione asperiores unde amet expedita vero numquam magnam officiis veniam natus tempora in vel, ipsam cupiditate dolorem.</p>
                <div class="spacer-40">&nbsp;</div><a class="button secondary small">Read More</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  .form-banner {
     position: relative;
     background: white;
     overflow: hidden;
      }
  .form-banner img {
     position: absolute;
     top: 0;
     right: 0;
     left: 0;
       bottom: 0;
     }
  .form-banner-container {
     max-width: rem-calc(1200);
     height: 100%;
     margin-left: auto;
     margin-right: auto;
     padding-left: rem-calc(20);
     padding-right: rem-calc(20);
     }
     .form-banner-wrapper {
       height: 100%;
       margin: 0 -9600rem;
       padding-left: 9600rem;
       padding-right: 9600rem;
       position: relative;
       z-index: 0;
        }
      .form-banner-wrapper:before {
       content: "";
       z-index: -1;
       width: 50%;
        background-color: gray;
       }

     .form-banner-placement--right.form-banner .form-banner-wrapper {
        padding-bottom: rem-calc(100);
     }
   .form-banner-placement--right.form-banner .form-banner-wrapper img {
     position: absolute;
      top: 0;
      right: 9600rem;
      left: 50%;
      bottom: 0;
       z-index: -2;
     height: 100%;
     width: 50vw;
     object-fit: cover;
     object-position: 50% 50%;
   }
  .form-banner-placement--right.form-banner .form-banner-wrapper:before {
     position: absolute;
     top: 0;
     right: 0;
     left: 0;
     bottom: 0;
   }
  .form-banner-placement--right.form-banner .form-banner-wrapper:after {
    position: absolute;
    top: 0;
    right: 0;
    left: inherit;
    bottom: 0;
    content: "";
    background-color: #ffffff;
    opacity: 0.8;
    z-index: -1;
    width: 50%;
   }
   .form-banner-placement--right.form-banner .form-banner-wrapper--         original:after {
    opacity: 0;
    z-index: 0;
   }
   .form-banner-placement--right.form-banner .form-banner-left {
    position: absolute;
    top: 0;
    right: 50%;
    left: 9600rem;
    bottom: 0;
    padding-top: 5rem;
   }

   .form-banner--large .form-banner-left {
    padding: rem-calc();
   }

  .form-banner--920px .form-banner-left {
     padding: rem-calc();
     }

   .form-banner--125 {
    height: 85;
    }
   .form-banner--125 .form-banner-left {
     padding: rem-calc(160);
      }

   .form-banner--large {
       height: 920px;
    }

     .form-banner--medium {
      height: 466px;
      }

我在codepen Codepen

上提供了代码

enter image description here

2 个答案:

答案 0 :(得分:1)

编辑的课程

.form-banner-placement--right.form-banner .form-banner-wrapper img {
position: absolute;
top: 0;
right: 50%;
left: 9600rem;
bottom: 0;
z-index: -2;
height: 100%;
width: 50vw;
object-fit: cover;
object-position: 50% 50%;
}

.form-banner-placement--right.form-banner .form-banner-left {
position: absolute;
top: 0;
right: 9600rem;
left: 50%;
bottom: 0;
padding-top: 5rem;
}

.form-banner-placement--right.form-banner .form-banner-wrapper:before {
position: absolute;
top: 0;
right: 9600rem;
left: 50%;
bottom: 0;
}

JSfiddle DEMO

答案 1 :(得分:1)

检查一下,希望它可以帮助你:

&#13;
&#13;
.form-banner {
  position: relative;
  background: white;
  overflow: hidden;
}

.form-banner-wrapper {
  height: 100%;
  margin: 0 -9600rem;
  padding-left: 9600rem;
  padding-right: 9600rem;
  position: relative;
  z-index: 0;
}

.form-banner-container {
  max-width: rem-calc(1200);
  height: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: rem-calc(20);
  padding-right: rem-calc(20);
}

/*=========================================================
  01. #FORM BANNER PLACEMENT RIGHT
=========================================================*/
.form-banner-placement--right.form-banner .form-banner-wrapper {
  padding-bottom: rem-calc(100);
}
.form-banner-placement--right.form-banner .form-banner-wrapper img {
float: left;
z-index: -2;
height: 100%;
width: 50%;
object-fit: cover;
object-position: 50% 50%;
}
.form-banner-placement--right.form-banner .form-banner-wrapper:before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
}
.form-banner-placement--right.form-banner .form-banner-wrapper:after {
  position: absolute;
  top: 0;
  right: 0;
  left: inherit;
  bottom: 0;
  content: "";
  background-color: #ffffff;
  opacity: 0.8;
  z-index: -1;
  width: 50%;
}
.form-banner-placement--right.form-banner .form-banner-wrapper--original:after {
  opacity: 0;
  z-index: 0;
}
.form-banner-placement--right.form-banner .form-banner-left {
width: 45%;
padding: 6rem 2.5%;
float: right;
background-color: gray;
}

/*=========================================================
  03. #FORM BANNER SIZE
=========================================================*/
.form-banner--large .form-banner-left {
  padding: rem-calc();
}

.form-banner--920px .form-banner-left {
  padding: rem-calc();
}

.form-banner--125 {
  height: 85;
}
.form-banner--125 .form-banner-left {
  padding: rem-calc(160);
}

.form-banner--large {
  height: 920px;
}

.form-banner--medium {
  height: 466px;
}
&#13;
<div class="form-banner form-banner--medium form-banner-placement--right">
        <div class="form-banner-container">
          <div class="form-banner-wrapper form-banner-wrapper--original"><img src="https://dummyimage.com/600x400/blue/fff&text=image+here">
            <div class="form-banner-left">
              <div class="row">
                <div class="columns"><span class="tag">recommended</span>
                    <div class="spacer-15">&nbsp;</div>
                  <h3>Monitoring</h3>
                    <div class="spacer-30">&nbsp;</div>
                  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias distinctio explicabo suscipit eligendi ratione asperiores unde amet expedita vero numquam magnam officiis veniam natus tempora in vel, ipsam cupiditate dolorem.</p>
                    <div class="spacer-40">&nbsp;</div><a class="button secondary small">Read More</a>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
&#13;
&#13;
&#13;

How to invert console history order in pycharm for copy pasting?