html - 带 Angular 边框的 IMG 尺寸

标签 html css

我想将 2 个 img 用斜 Angular 边框分开。我第一次设法调整大小。我尝试了第二个,但到目前为止对我没有任何帮助。 到目前为止我的工作: 即使我尝试单独制作,第二个 img 也没有得到倾斜的边框 背景看起来像这样,我希望图像与 Angular 相匹配。

.left,
.right {
  background: #000;
  position: relative;
  height: 100px;
  width: 45%;
  float: left;
  margin-top: 10px;
  opacity: 10%;
}

.right,
.right img {
  margin-left: 0px;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

.left,
.left img {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

.left:after {
  content: '';
  line-height: 0;
  font-size: 0;
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-bottom: 100px solid #fff;
  border-left: 30px solid transparent;
  border-right: 0px solid #fff;
  position: absolute;
  top: -50px;
  right: 0;
}

.right:before,
{
  content: '';
  line-height: 0;
  font-size: 0;
  width: 0;
  height: 0;
  border-top: 100px solid #fff;
  border-bottom: 50px solid transparent;
  border-left: 0px solid transparent;
  border-right: 30px solid transparent;
  position: absolute;
  top: 0;
  left: 0;
}

.left img,
.right img {
  position: relative;
  width: 100%;
  height: 100%;
  opacity: 0.5;
}

.left img:hover,
.right img:hover {
  opacity: 1;
  cursor: pointer;
}
<div class="left"><img src="./img/chu.jpg"></div>
<div class="right"><img src="./img/chu.jpg"></div>

最佳答案

你可以尝试使用clip-path:

.left,
.right {
  display: inline-block;
  overflow: hidden;
  position: relative;
}

.left {
  border-radius: 10px 0 0 10px;
  -webkit-clip-path: polygon(0 0, 100% 0%, 80% 100%, 0% 100%);
  clip-path: polygon(0 0, 100% 0%, 80% 100%, 0% 100%);
}

.right {
  border-radius: 0 10px 10px 0;
  -webkit-clip-path: polygon(21% 0, 100% 0%, 100% 100%, 0% 100%);
  clip-path: polygon(21% 0, 100% 0%, 100% 100%, 0% 100%);
  margin-left: -40px;
}

img {
  display: block;
}
<div class="left">
  <img src="https://picsum.photos/200/100?image=1069">
</div>
<div class="right">
  <img src="https://picsum.photos/200/100?image=1065">
</div>

这是另一个比使用倾斜变换的 clip-path 更受支持的想法:

.container {
  display: inline-block;
  border-radius: 10px;
  overflow: hidden;
}

.left,
.right {
  display: inline-block;
  vertical-align:top;
  width: 200px;
  height: 100px;
  position: relative;
  transform: skew(-20deg);
  overflow: hidden;
}

.left,
.right img {
  margin-left: -20px;
}

.right {
  margin-right: -20px;
  margin-left: 5px;
}

img {
  display: block;
  transform: skew(20deg);
  width: 110%;
}
<div class="container">
  <div class="left">
    <img src="https://picsum.photos/200/100?image=1069">
  </div>
  <div class="right">
    <img src="https://picsum.photos/200/100?image=1065">
  </div>
</div>

关于html - 带 Angular 边框的 IMG 尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51266545/

相关文章:

HTML 选择元素不响应使用 IE7/WinXP 的 SSL iframe 中的鼠标点击

html - 并排两张图片,上面有文字

javascript - 使用 Knockout.js 更改列表中 div 的类

html - Vuetify Offset 不创建任何偏移量

html - 单击时禁用 ng-mouseover

html - 使用 WAI-ARIA 的可访问错误处理 - 最佳实践?

javascript - React CSSTransitionGroup 不为高度、宽度或顶部设置动画

css - HTML 旁白标记 : is it OK to use for form error message?

javascript - jquery通过随机生成的div选择 child

css - 在 Bootstrap 输入文本上对齐输入文件