首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >*旋转后的单元按调整尺寸移动

*旋转后的单元按调整尺寸移动
EN

Stack Overflow用户
提问于 2015-02-12 10:56:32
回答 1查看 258关注 0票数 0

我有一个:前和安:后元素(为了阴影的目的),有一个转换:旋转应用于它。在调整视口大小时,“前”保持在适当的位置,但“后”则会稍微向上和向下移动。如果旋转被移除,则在调整大小时保持在适当的位置。我怎样才能让它在调整大小的情况下保持原状呢?

我已经把一个z-索引:1放在:前和后为可见性的问题。

是影子#3

http://codepen.io/mildrenben/details/jEYpyP/

HTML:

代码语言:javascript
复制
<h2>Shadow #3</h2>
<div class="row shadow-3">
  <div class="shadow-box">
    <img>
  </div>
  <div class="shadow-box">
    <img>
  </div>
  <div class="shadow-box">
    <img>
  </div>
  <div class="shadow-box">
    <img>
  </div>
</div>

CSS:

代码语言:javascript
复制
html, body {
  width: 100%;
  height: 100%;
}
.row {
  height: 160px;
  width: 80%;
  margin: 0 auto 60px;
  display: block;
    img:nth-of-type(1) {
      content: url(http://marshall.org/wp-content/themes/marshall/img/featured-space-policy.jpg);
    }
    img:nth-of-type(2) {
      content: url(http://i.dailymail.co.uk/i/pix/2014/09/04/1409790551890_wps_28_Astronaut_Reid_Wiseman_po.jpg);
    }
    img:nth-of-type(3) {
      content: url(http://cdn2.collective-evolution.com/assets/uploads/2014/08/life_in_space-728x400.jpg);
    }
    img:nth-of-type(4) {
      content: url(http://s.ngm.com/2007/10/space-travel/img/space_feature.jpg);
    }
}

img {
  width: 23%;
  margin: 0 1% 0 0;
  height: 100%;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
}

.shadow-box {
  width: 23%;
  margin: 0 1% 0 0;
  height: 100%;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  display: inline-block;
  img {
    width: 100%;
    height: 100%;
    &:hover {
      transform: translateY(-4px);
    }
  }
}

.shadow-box:before, .shadow-box:after {
  content: '';
  z-index: 1;
  position: absolute;
  width: 8%;
  height: 110px;
  background: red;
  transform: skew(-10deg) rotate(-6deg) translate(calc(3% + 10px), 31px);
  transition: all 0.2s ease-in-out;
}

.shadow-box:after {
  transform: skew(10deg) rotate(6deg) translate(126%, -146px);
}

.shadow-box:hover:before, .shadow-box:hover:after {
  box-shadow: 0 20px 20px lighten($black, 40%);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-12 11:13:38

我不认为使用平移是在这里的方式,我会设置容器的位置:相对;然后使用绝对定位定位阴影的东西:http://jsfiddle.net/bpma9ko4/

在此,有关部分:

代码语言:javascript
复制
.shadow-box {
  width: 45%;
  margin: 0 1% 0 0;
  height: 100%;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  display: inline-block;
  position: relative;
}

.shadow-box:before, .shadow-box:after {
  content: '';
  z-index: 1;
  position: absolute;
  width: 40%;
  height: 110px;
  background: red;
  transform: skew(-10deg) rotate(-6deg);
  transition: all 0.2s ease-in-out;
  top: 20px;
  left: 20px;
}

.shadow-box:after {
  transform: skew(10deg) rotate(6deg);
  right: 20px;
  left: auto;
}

在您的示例中,当我删除翻译时,右边的红色框在图像下面(在一条新行上),然后尝试用translates拖动它,但对我来说,如果您首先使用顶部/左边/右边的属性将其放置在图像之上,这是一种更为直接的方法。

注意:我的例子很简单,它没有阴影和其他东西,它被缩减到与问题相关的部分。

整个守则:

代码语言:javascript
复制
html, body {
  width: 100%;
  height: 100%;
}
.row {
  height: 160px;
  width: 80%;
  margin: 0 auto 60px;
  display: block;
    img:nth-of-type(1) {
      content: url(http://marshall.org/wp-content/themes/marshall/img/featured-space-policy.jpg);
    }
    img:nth-of-type(2) {
      content: url(http://i.dailymail.co.uk/i/pix/2014/09/04/1409790551890_wps_28_Astronaut_Reid_Wiseman_po.jpg);
    }
    img:nth-of-type(3) {
      content: url(http://cdn2.collective-evolution.com/assets/uploads/2014/08/life_in_space-728x400.jpg);
    }
    img:nth-of-type(4) {
      content: url(http://s.ngm.com/2007/10/space-travel/img/space_feature.jpg);
    }
}

img {
  width: 100%;
  margin: 0 1% 0 0;
  height: 100%;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
}

.shadow-box {
  width: 45%;
  margin: 0 1% 0 0;
  height: 100%;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  display: inline-block;
    position: relative;
}

.shadow-box:before, .shadow-box:after {
  content: '';
  z-index: 1;
  position: absolute;
  width: 40%;
  height: 110px;
  background: red;
  transform: skew(-10deg) rotate(-6deg);
  transition: all 0.2s ease-in-out;
    top: 20px;
    left: 20px;
}

.shadow-box:after {
  transform: skew(10deg) rotate(6deg);
    right: 20px;
    left: auto;
}

.shadow-box:hover:before, .shadow-box:hover:after {
  box-shadow: 0 20px 20px lighten($black, 40%);
}
代码语言:javascript
复制
<h2>Shadow #3</h2>
<div class="row shadow-3">
  <div class="shadow-box">
    <img src="http://placehold.it/466x180">
  </div>
  <div class="shadow-box">
    <img src="http://placehold.it/466x180">
  </div>
  <div class="shadow-box">
    <img src="http://placehold.it/466x180">
  </div>
  <div class="shadow-box">
      <img src="http://placehold.it/466x180">
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28475659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档