我需要做一个有偏斜的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>
我将不胜感激任何帮助:) 谢谢, 纳斯
答案 0 :(得分:2)
我认为更好的方法是在<article>
<section><code>grid-column: 1 / 4<br>counts lines</code></section>
<section><code>grid-column: 1 / span 3<br>counts columns</code></section>
<section>3</section>
<section>4</section>
<section>5</section>
</article>
上应用let imageElements = document.querySelectorAll("img[class^='image']");
imageElements.forEach(image => image.addEventListener('click', function(){
definition(this.classList[0], this);
});
。
基本问题是你自己扭曲了每个元素,因此它就地倾斜了。倾斜容器将使其内容物在倾斜外形时也会倾斜。
skew
&#13;
.flex-container
&#13;
答案 1 :(得分:2)
所做的更改:
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>