【发布时间】:2016-08-19 19:48:58
【问题描述】:
所以我得到了我正在处理的英雄布局的以下设计:
我已经制作了两个图像,如图所示,图像旁边的描述并对齐图像。我也查看了剪辑路径,但不幸的是它不支持 IE。所以我使用变换旋转选项将 div 旋转 -15 度,并将 div 内的图像旋转 15 度。但是,我遇到的问题是,当使用浏览器进行缩放时,两个必须保持对齐的图像之间会出现间隙。 (平板电脑和手机有另一种状态,但那是另一回事了)。
我创建了一个 codepen:http://codepen.io/adamk22/pen/zBLBAL,它的布局包括 css。浏览器缩放时如何保持两个图像对齐?我没有考虑到什么?
HTML:
<nav> Test Nav </nav>
<div class="container">
<div class="hero-container-top">
<div class="hero-img-box-container">
<div class="hero-img-box-left">
<div class="hero-img-box">
<img class="hero-img" src="http://gyproc.dev/themes/custom/drywall/images/hero_img1.jpeg">
</div>
</div>
</div>
<div class="hero-text-box">
<div class="hero-text-box-cta">
<h1>Hello World</h1>
<h3>Phasellus tempus. Quisque ut nisi. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mollis tellus ac sapien.</h3>
</div>
</div>
</div>
<div class="hero-container-bottom">
<div class="hero-text-box">
<div class="hero-text-box-cta">
<h2> Hello world</h2>
<h3>Phasellus tempus. Quisque ut nisi. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mollis tellus ac sapien.</h3>
</div>
</div>
<div class="hero-img-box-container">
<div class="hero-img-box-right">
<div class="hero-img-box">
<img class="hero-img" src="http://gyproc.dev/themes/custom/drywall/images/hero_img2.jpeg">
</div>
</div>
</div>
</div>
</div>
CSS:
body {
background: white;
font-family: 'Helvetica', sans-serif;
display: flex;
flex-direction: row;
}
h1 {
font-size: 36px;
line-height: 46px;
font-weight: 100;
}
h2 {
font-size: 24px;
font-weight: 100;
}
h3 {
font-size: 16px;
line-height: 30px;
font-weight: 100;
}
nav {
flex: 0 0 235px;
background: #0569C8;
display: inline-block;
}
.container {
flex: 1 0 auto;
margin: 36px;
overflow: hidden;
background: white;
}
.hero-img-box-container {
width: 60%;
}
.hero-container-top {
display: flex;
flex-direction: row;
height: 767px;
background: white;
.hero-text-box {
width: 40%;
position: relative;
}
.hero-text-box-cta {
position: absolute;
top: 40%;
left: 40%;
transform: translateX(-50%) translateY(-50%);
}
}
.hero-container-bottom {
display: flex;
flex-direction: row;
position: relative;
top: -256px;
height: 751px;
.hero-text-box {
width: 40%;
position: relative;
}
.hero-text-box-cta {
position: absolute;
top: 60%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
}
.hero-img-box-left {
background: lightgrey;
display: inline-block;
height: 1023px;
width: 100%;
transform: rotate(15deg);
transform-origin: top;
position: relative;
top: -165px;
overflow: hidden;
.hero-img-box {
transform: rotate(-15deg);
display: inline-block;
}
.hero-img {
height: 765px;
width: auto;
position: relative;
top: 140px;
left: 10px;
}
}
.hero-img-box-right {
background: lightgrey;
display: inline-block;
height: 1000px;
width: 100%;
transform: rotate(15deg);
transform-origin: top;
position: relative;
overflow: hidden;
right: -21.8%;
top: 0;
.hero-img-box {
transform: rotate(-15deg);
display: inline-block;
}
.hero-img {
height: 628px;
width: auto;
position: relative;
top: 80px;
left: -130px;
}
}
【问题讨论】:
-
感谢您的努力,但也许您应该考虑尝试 SVG。
-
@golezTrol 不使用 svg 掩码使用剪辑路径,而 IE 又不支持?
-
我会使用伪元素来解决这个问题。不要旋转 Div,而是在伪元素之前旋转,并使用 z-index 属性调整可见性
-
@Berdesdan 它确实解决了特定视口的问题,但不幸的是缩放时没有解决
-
@MarouenMhiri 当您将它们相互对齐时,它们不会相互覆盖吗?