如何让border-radius的背景颜色或图像按预期出现

问题描述 投票:0回答:1

我希望.txt的背景颜色或图像显示为.next的边框半径的背景颜色或图像。 我想知道如何在不更改 .txt 转换的情况下执行此操作。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    body {
      background-color: #f00;
    }
    .wrap {
      position: relative;
      overflow: hidden;
    }
    .txt {
      background-color: #00f;
      height: 300px;
      translate: none;
      rotate: none;
      scale: none;
      transform: translate3d(0px, 150px, 0px);
    }
    .txt img {
      width: 100%;
    }
    .next {
      position: relative;
      height: 1000px;
      background-color: #ccc;
      border-radius: 20px 20px 0 0;
    }
  </style>
</head>
<body>
  <div class="wrap">
    <div class="txt"><img src="https://picsum.photos/640/360" alt=""></div>
  </div>
  <div class="next">next</div>
</body>
</html>

image

current and expected

html css transform
1个回答
0
投票

添加

body
样式:

  background-image: linear-gradient(transparent 150px, #00f 150px);

布局中的红色被设置为

body
的背景。只需将开头的背景设为红色,下一个元素下方的背景设为蓝色即可。

* {
  margin: 0;
  padding: 0;
}

body {
  background-color: #f00;
  background-image: linear-gradient(transparent 150px, #00f 150px);
}

.wrap {
  position: relative;
  overflow: hidden;
}

.txt {
  background-color: #00f;
  height: 300px;
  translate: none;
  rotate: none;
  scale: none;
  transform: translate3d(0px, 150px, 0px);
}

.next {
  position: relative;
  height: 1000px;
  background-color: #ccc;
  border-radius: 20px 20px 0 0;
}
<div class="wrap">
  <div class="txt">text</div>
</div>
<div class="next">next</div>

© www.soinside.com 2019 - 2024. All rights reserved.