修复倾斜的 Flexbox
Fix skewed Flexboxes
我需要做一个倾斜 css 设计的网站。目标是一些类似的设计:
经过一些编码后我的结果如下:
在黑框中你可以看到问题所在:ABC 容器不在正确的位置。我该如何解决?
html, body {
margin: 0px;
padding: 0px;
width: 100%;
font-family: sans-serif;
font-size: 20px;
}
a {
text-transform: uppercase;
font-family: sans-serif;
font-size: 30px;
text-decoration: none;
margin-left: auto;
margin-right: auto;
font-weight: bold;
color: white;
}
.flex-container {
display: flex;
align-self: left;
flex-direction: row;
width: 70%;
height: 100%;
background-color: white;
overflow: hidden;
flex-wrap: wrap-reverse;
float: right;
}
.flex-content {
transform: skew(-5.5deg);
background-color: red;
height: 33%;
text-align: center;
width: 45%;
margin: 5px 5px 5px 50px;
display: flex;
align-items: center;
}
.underlay-box {
position: absolute;
width: 20%;
height: 100%;
background-color: red;
}
.overlay-box {
width: 30%;
height: 100%;
background-color: red;
transform: skew(-5.5deg);
float: left;
}
.gmk {
height: 100%;
width: 100%;
border: 2px red solid;
/*background: url('bild1.jpg'); */
background-size: cover;
}
<div class="underlay-box"></div>
<div class="overlay-box"></div>
<div class="flex-container">
<div class="flex-content">
<div class="gmk"><a href="mediothek.html">A</a></div>
</div>
<div class="flex-content"><a href="mediothek.html">B</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">F</a></div>
</div>
我将不胜感激任何帮助:)
谢谢,
乔纳斯
我认为更好的方法是在 .flex-container
上应用 skew
。
基本问题是您正在单独倾斜每个元素,因此它就地倾斜。倾斜容器将允许其内容物在遵循外部形状时也被倾斜。
html, body {
margin: 0px;
padding: 0px;
width: 100%;
height:100%;
font-family: sans-serif;
font-size: 20px;
}
a {
text-transform: uppercase;
font-family: sans-serif;
font-size: 30px;
text-decoration: none;
margin-left: auto;
margin-right: auto;
font-weight: bold;
color: white;
}
.flex-container {
display: flex;
align-self: left;
flex-direction: row;
width: 70%;
height: 100%;
background-color: white;
overflow: hidden;
flex-wrap: wrap-reverse;
float: right;
transform: skew(-5.5deg);
}
.flex-content {
background-color: red;
height: 33%;
text-align: center;
width: 45%;
margin: 5px 5px 5px 15px;
display: flex;
align-items: center;
}
.underlay-box {
position: absolute;
width: 20%;
height: 100%;
background-color: red;
}
.overlay-box {
width: 30%;
height: 100%;
background-color: red;
transform: skew(-5.5deg);
float: left;
}
.gmk {
height: 100%;
width: 100%;
border: 2px red solid;
/*background: url('bild1.jpg'); */
background-size: cover;
box-sizing:border-box;
}
<div class="underlay-box"></div>
<div class="overlay-box"></div>
<div class="flex-container">
<div class="flex-content">
<div class="gmk"><a href="mediothek.html">A</a></div>
</div>
<div class="flex-content"><a href="mediothek.html">B</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">F</a></div>
</div>
所做的更改:
- 倾斜弹性容器而不是倾斜每个元素。
- 使用 skewX() 而不仅仅是 skew()。
- 通过减少边框大小和每个弹性项目的分隔宽度来计算组件的弹性基础。
- 只需利用左侧面板的底层框,将其倾斜并将其转换为左侧的 -5%。
- 增加 flex 容器的宽度,使其溢出主体到右侧。
- 隐藏 body 标签的 overflow-x 以禁用滚动。
html,
body {
margin: 0px;
padding: 0px;
width: 100%;
font-family: sans-serif;
font-size: 20px;
overflow-x:hidden;
}
a {
text-transform: uppercase;
font-family: sans-serif;
font-size: 30px;
text-decoration: none;
margin-left: auto;
margin-right: auto;
font-weight: bold;
color: white;
}
.flex-container {
display: flex;
align-self: left;
flex-direction: row;
width: 80%;
height: 100%;
transform: skewX(-5.5deg);
background-color: white;
overflow: hidden;
flex-wrap: wrap-reverse;
position: absolute;
left: 25%;
}
.flex-content {
background-color: red;
border:2px solid black;
flex: 0 1 calc(32% - 2px);
display: flex;
align-items: center;
text-align: center;
}
.flex-content:hover{
background-color:gray;
transition:all 0.3s ease-in-out;
}
.underlay-box {
position: absolute;
left: -5%;
width: 30%;
height: 100%;
background-color: red;
transform: skewX(-5.5deg);
}
.gmk {
height: 100%;
width: 100%;
border: 2px red solid;
/*background: url('bild1.jpg'); */
background-size: cover;
}
<div class="underlay-box"></div>
<div class="overlay-box"></div>
<div class="flex-container">
<div class="flex-content">
<div class="gmk"><a href="mediothek.html">A</a></div>
</div>
<div class="flex-content"><a href="mediothek.html">B</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">F</a></div>
</div>
我需要做一个倾斜 css 设计的网站。目标是一些类似的设计:
经过一些编码后我的结果如下:
在黑框中你可以看到问题所在:ABC 容器不在正确的位置。我该如何解决?
html, body {
margin: 0px;
padding: 0px;
width: 100%;
font-family: sans-serif;
font-size: 20px;
}
a {
text-transform: uppercase;
font-family: sans-serif;
font-size: 30px;
text-decoration: none;
margin-left: auto;
margin-right: auto;
font-weight: bold;
color: white;
}
.flex-container {
display: flex;
align-self: left;
flex-direction: row;
width: 70%;
height: 100%;
background-color: white;
overflow: hidden;
flex-wrap: wrap-reverse;
float: right;
}
.flex-content {
transform: skew(-5.5deg);
background-color: red;
height: 33%;
text-align: center;
width: 45%;
margin: 5px 5px 5px 50px;
display: flex;
align-items: center;
}
.underlay-box {
position: absolute;
width: 20%;
height: 100%;
background-color: red;
}
.overlay-box {
width: 30%;
height: 100%;
background-color: red;
transform: skew(-5.5deg);
float: left;
}
.gmk {
height: 100%;
width: 100%;
border: 2px red solid;
/*background: url('bild1.jpg'); */
background-size: cover;
}
<div class="underlay-box"></div>
<div class="overlay-box"></div>
<div class="flex-container">
<div class="flex-content">
<div class="gmk"><a href="mediothek.html">A</a></div>
</div>
<div class="flex-content"><a href="mediothek.html">B</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">F</a></div>
</div>
我将不胜感激任何帮助:) 谢谢, 乔纳斯
我认为更好的方法是在 .flex-container
上应用 skew
。
基本问题是您正在单独倾斜每个元素,因此它就地倾斜。倾斜容器将允许其内容物在遵循外部形状时也被倾斜。
html, body {
margin: 0px;
padding: 0px;
width: 100%;
height:100%;
font-family: sans-serif;
font-size: 20px;
}
a {
text-transform: uppercase;
font-family: sans-serif;
font-size: 30px;
text-decoration: none;
margin-left: auto;
margin-right: auto;
font-weight: bold;
color: white;
}
.flex-container {
display: flex;
align-self: left;
flex-direction: row;
width: 70%;
height: 100%;
background-color: white;
overflow: hidden;
flex-wrap: wrap-reverse;
float: right;
transform: skew(-5.5deg);
}
.flex-content {
background-color: red;
height: 33%;
text-align: center;
width: 45%;
margin: 5px 5px 5px 15px;
display: flex;
align-items: center;
}
.underlay-box {
position: absolute;
width: 20%;
height: 100%;
background-color: red;
}
.overlay-box {
width: 30%;
height: 100%;
background-color: red;
transform: skew(-5.5deg);
float: left;
}
.gmk {
height: 100%;
width: 100%;
border: 2px red solid;
/*background: url('bild1.jpg'); */
background-size: cover;
box-sizing:border-box;
}
<div class="underlay-box"></div>
<div class="overlay-box"></div>
<div class="flex-container">
<div class="flex-content">
<div class="gmk"><a href="mediothek.html">A</a></div>
</div>
<div class="flex-content"><a href="mediothek.html">B</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">F</a></div>
</div>
所做的更改:
- 倾斜弹性容器而不是倾斜每个元素。
- 使用 skewX() 而不仅仅是 skew()。
- 通过减少边框大小和每个弹性项目的分隔宽度来计算组件的弹性基础。
- 只需利用左侧面板的底层框,将其倾斜并将其转换为左侧的 -5%。
- 增加 flex 容器的宽度,使其溢出主体到右侧。
- 隐藏 body 标签的 overflow-x 以禁用滚动。
html,
body {
margin: 0px;
padding: 0px;
width: 100%;
font-family: sans-serif;
font-size: 20px;
overflow-x:hidden;
}
a {
text-transform: uppercase;
font-family: sans-serif;
font-size: 30px;
text-decoration: none;
margin-left: auto;
margin-right: auto;
font-weight: bold;
color: white;
}
.flex-container {
display: flex;
align-self: left;
flex-direction: row;
width: 80%;
height: 100%;
transform: skewX(-5.5deg);
background-color: white;
overflow: hidden;
flex-wrap: wrap-reverse;
position: absolute;
left: 25%;
}
.flex-content {
background-color: red;
border:2px solid black;
flex: 0 1 calc(32% - 2px);
display: flex;
align-items: center;
text-align: center;
}
.flex-content:hover{
background-color:gray;
transition:all 0.3s ease-in-out;
}
.underlay-box {
position: absolute;
left: -5%;
width: 30%;
height: 100%;
background-color: red;
transform: skewX(-5.5deg);
}
.gmk {
height: 100%;
width: 100%;
border: 2px red solid;
/*background: url('bild1.jpg'); */
background-size: cover;
}
<div class="underlay-box"></div>
<div class="overlay-box"></div>
<div class="flex-container">
<div class="flex-content">
<div class="gmk"><a href="mediothek.html">A</a></div>
</div>
<div class="flex-content"><a href="mediothek.html">B</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">C</a></div>
<div class="flex-content"><a href="mediothek.html">D</a></div>
<div class="flex-content"><a href="mediothek.html">E</a></div>
<div class="flex-content"><a href="mediothek.html">F</a></div>
</div>