【问题标题】:A vertical div with an image pattern on the left and right side一个垂直的 div,左右两边都有一个图像模式
【发布时间】:2018-07-05 15:39:24
【问题描述】:

所以我正在尝试制作这样的 div

但我希望它是垂直的,因为我希望这两种 div 看起来像纸张样式:这是垂直 div,我希望从上方随机卷曲边缘位于左侧和右侧div 在第二张图片上,您会看到一个蓝色的怪异边框。我尝试使用border-image 来做到这一点,但这似乎并没有真正起作用,因为我尝试使用的边框图像的随机模式。

我现在拥有的 CSS:

bg-section {
border-image: url(../images/test.png) 120 round;
border-right: 40px solid transparent;
border-left: 40px solid transparent;
width: 70%;
margin: auto;
linear-gradient(rgba(199,194,183,0.2), rgba(199,194,183,0));
}

这是我尝试使用的边框:

【问题讨论】:

    标签: html css border border-image


    【解决方案1】:

    您可以使用任何工具旋转图像,然后将其用作背景并依靠重复:

    body {
      min-height:800vh;
      margin:0;
      background:
        url(https://i.stack.imgur.com/rFPJV.png) right repeat-y,
        url(https://i.stack.imgur.com/uMYNC.png) left repeat-y,
        linear-gradient(green,green) center / calc(100% - 138px) 100% no-repeat;
        
    }

    对于相同的图像,您可以使用伪元素并依靠变换来旋转图像。您还可以轻松控制边框的宽度:

    body {
      min-height:800vh;
      margin:0;
      position:relative;  
      background:linear-gradient(green,green) center / calc(100% - 50px) 100% no-repeat
    }
    body:before,
    body:after {
      content:"";
      position:absolute;
      top:0;
      bottom:0;
      width:20px; /*Control the width of the border*/
      background: url(https://i.stack.imgur.com/rFPJV.png) center/contain  repeat-y
    }
    body:before {
      right:10px;
    }
    body:after {
      left:10px;
      transform:scale(-1,1);
    }

    【讨论】:

    • 好吧,所以我让它与你的技术一起工作:link 但我想用两侧的颜色填充背景。当我尝试这样做时,这会发生:link。我用绿色只是为了让你很容易看到它。我正在考虑只为 div 的一部分着色,但我不确定如何做到这一点。
    • @RaytjeKn 好的,检查我的编辑;)您可以使用渐变来创建背景颜色并避免该问题;)
    • 非常感谢!它对我有用。现在有一件事我想问你。我假设您也可以在水平 div 上使用此技术。那我该怎么做呢?像这样:'background:url(../images/links.png) up repeat-x, url(../images/right.png) down repeat-x;'我试过了,但这似乎不起作用,所以我想我忘记了什么或弄错了什么。
    • @RaytjeKn 不是 up/down 而是 top\ bottom ;) ... 所以应该类似​​于 background: url(https://i.stack.imgur.com/rFPJV.png) top/contain repeat-x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多