划分多个边界以进行纸张模拟

时间:2018-12-11 15:38:20

标签: html css html5

我正在尝试使div具有装饰边框。该div应该是:

  • 响应
  • 进行调整大小操作
  • 并根据嵌入的图像调整其高度和宽度

我已经弄清楚的是这个小提琴示例,最终的解决方案应该完全像这样:

.stack {
  margin-top: 50px;
}

.c1 {
  position: absolute;
  z-index: 10;
  border: 1px solid black;
  width: 300px;
  height: 300px;
  background: red;
}

.c1 img {
  width: 300px;
}

.c2 {
  position: absolute;
  z-index: 5;
  background: bluex;
  border-top: 1px solid black;
  border-right: 1px solid black;
  margin-top: -5px;
  margin-left: 6px;
  width: 300px;
  height: 300px;
}

.c3 {
  position: absolute;
  z-index: 1;
  background: yellowx;
  border-top: 1px solid black;
  border-right: 1px solid black;
  margin-top: -10px;
  margin-left: 11px;
  width: 300px;
  height: 300px;
}
<div class="stack">
  <div class="c1">
    <img src="https://dummyimage.com/300.png/09f/fff" />
  </div>
  <div class="c2"></div>
  <div class="c3"></div>
</div>

任何人都可以帮助我,以扩展或重建它以满足其他要求。

3 个答案:

答案 0 :(得分:2)

您可以尝试多个box-shadow

img {
  border: 2px solid;
  margin: 20px;
  box-shadow:
    6px -6px 0 #fff,
    8px -8px 0 #000,
    12px -12px 0 #fff,
    14px -14px 0 #000;
}
<img src="https://dummyimage.com/300.png/09f/fff" />

答案 1 :(得分:0)

我认为这就是你所需要的。

<div class="stack">
    <div class="c1">

    </div>
    <div class="c2-a"></div>
        <div class="c2-b"></div>
    <div class="c3-a"></div>
</div>


    .stack { 
      margin-top:50px;
      position:relative;
    }
    .c1 { 
      z-index: 10;
      border: 1px solid red;
      width:95%;
      background:red;
      background-image:url('https://dummyimage.com/300.png/09f/fff');
      background-repeat:no-repeat;
      background-size:100% auto;
      padding-top:70%; /*adjust the padding value */ 

    } 

    .c2-a { 
        position:absolute;
        z-index: 5;
        background:bluex;
        border-top: 1px solid black;
      top:-7px;
      right:3%;
      width:90%;
    }

    .c2-b { 
        position:absolute;
        z-index: 5;
        background:bluex;
        border-top: 1px solid black;
      top:-15px;
      right:0;
      width:80%;
    }
    .c3-a { 
        position:absolute;
        z-index: 1;
        background:yellowx;
        border-right: 1px solid black;
      right:0;
      top:-15px;
      padding-top:70%;

    }
    .c3-b {
      /* create the onther line lol */
    }

http://jsfiddle.net/kqjwv48r/4/

答案 2 :(得分:-1)

jquery的不同解决方案:

$(document).ready(function(){
		var width = $(".c1").width();
    $(".c2").css({'width':(width +'px'), 'height':(width +'px')});
    $(".c3").css({'width':(width +'px'), 'height':(width +'px')});
});
.stack {
  margin-top: 50px;
}

.c1 {
  position: absolute;
  z-index: 10;
  display: inline-block;
}

.c1 img {
  box-sizing: border-box;
  border: 1px solid black;
}

.c2 {
  position: absolute;
  z-index: 5;
  background: bluex;
  border-top: 1px solid black;
  border-right: 1px solid black;
  margin-top: -8px;
  margin-left: 8px;
}

.c3 {
  position: absolute;
  z-index: 1;
  background: yellowx;
  border-top: 1px solid black;
  border-right: 1px solid black;
  margin-top: -15px;
  margin-left: 15px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="stack">
  <div class="c1">
    <img src="https://dummyimage.com/200.png/09f/fff" />
  </div>
  <div class="c3"></div>
  <div class="c2"></div>
</div>