css 我怎样才能使divs rorate,但没有它的内容?

beq87vna  于 2023-01-14  发布在  其他
关注(0)|答案(2)|浏览(122)

我可以旋转div或在其上实现clip-path属性。但我的方法没有得到理想的结果。我已经搜索了codepen和谷歌搜索的其他结果,但nada。
我已经在div上使用了clip-path和skew属性,但是我再次认为我没有遵循正确的方法。我想让我的div以适当的间距彼此靠在一起,并且处于skew状态,正如你所看到的。
我想要这样的...... here is what i want

mftmpeh8

mftmpeh81#

我想你需要这样的东西,我用transform属性来做:

.flexContainer {
  width: 500px;
  display: flex;
  flex-wrap: wrap;
}

.flexContainer>* {
    flex: 0 0 33%;
}

.theContainer {
    margin: 0 0.5em;
    padding: 2em 2em 7em 2em;
    color: #000;
    display: block;
    width: 100px;
    height: 30px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 2px 2px 2px 2px #ededed;
    transform: skew(0, -5deg);
}

.theContainer.first {
  margin-top: 1.5em;
}

.theContent {
  position: absolute;
  transform: skew(0, 5deg);
}
<div class="flexContainer">
  <div class="theContainer first">
    <div class="theContent">
      <h2> Title </h2>
      <p> Content test </p>
    </div>
  </div>

  <div class="theContainer second">
    <div class="theContent">
      <h2> Title </h2>
      <p> Content test </p>
    </div>
  </div>

  <div class="theContainer first">
    <div class="theContent">
      <h2> Title </h2>
      <p> Content test </p>
    </div>
  </div>
  
  <div class="theContainer second">
    <div class="theContent">
      <h2> Title </h2>
      <p> Content test </p>
    </div>
  </div>
</div>
628mspwn

628mspwn2#

希望这能帮上忙...

<div class="container">
  <div class="item">
    <h1>1</h1>
  </div>
  <div class="item">
    <h1>2</h1>
  </div>
  <div class="item">
    <h1>3</h1>
  </div>
  <div class="item">
    <h1>4</h1>
  </div>
</div>
<style>
  .container {
    display: flex;
    flex-wrap: wrap;
    transform: skew(0, -6deg);
  }
  .container .item {
    text-align: center;
    width: 40%;
    margin: 10px;
    padding: 50px;
    border-radius: 10px;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  }
  .container .item h1 {
    transform: skew(0, 6deg);
  }
</style>

相关问题