梯形响应Div与CSS或jQuery [英] Trapezium responsive Div with CSS or jQuery
本文介绍了梯形响应Div与CSS或jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须建立这个网站,我面临着一个独特的挑战交替梯形Divs。我从来没有遇到过这样的事情,我不知道如何实现这一点。为了使事情更复杂,这将是一个反应迅速的网站。
有任何想法吗?
解决方案
您可以使用SkewX变换:
div {height:50px; display:inline-block;背景:lightgray; padding:10px; line-height:50px; text-align:center;位置:相对; transition:all 0.6s; z-index:1;} div:before {content:; position:absolute; height:inherit;背景:inherit; top:0;左:30%; height:70px;宽度:100%; -webkit-transform:skewX(45deg); -moz-transform:skewX(45deg); transform:skewX(45deg); z-index:-1;} div:hover {background:tomato;}
< div>有些文字在这里< / div>
您可以为许多不同的梯形图执行此操作:
html,body {margin: 0; padding:0; text-align:center;} body {background:blue;} div {height:50px; display:inline-block;背景:lightgray; line-height:50px; text-align:center;位置:相对; transition:all 0.6s; cursor:pointer; z-index:1;}。right:before {content:; position:absolute; height:inherit;背景:inherit; top:0;左:50%;高度:100%;宽度:100%; -webkit-transform:skewX(45deg); -moz-transform:skewX(45deg); transform:skewX(45deg); z-index:-1;} div:hover {background:tomato;} left {margin-left:50px;} right {margin-right:50px;}。 position:absolute; height:inherit;背景:inherit; top:0;左:-50%;高度:100%;宽度:100%; -webkit-transform:skewX(-45deg); -moz-transform:skewX(-45deg); transform:skewX(-45deg); z-index:-1;}
< div class =right>有些文字说< / div>< br />< br />< div class =left>多少我喜欢< / div>< br / < br />< div class =left right> MINIONS!< / div>
I have to build this website and I am faced with a unique challenge of alternating Trapezium Divs. I have never come across anything like this before and I have no idea how to achieve this. To make things more complicated, this is going to be a responsive website.
Any ideas?
解决方案
You could use the SkewX transform to skew a div's before element:
div {
height: 50px;
display: inline-block;
background: lightgray;
padding: 10px;
line-height: 50px;
text-align: center;
position: relative;
transition: all 0.6s;
z-index:1;
}
div:before {
content: "";
position: absolute;
height: inherit;
background: inherit;
top: 0;
left: 30%;
height: 70px;
width: 100%;
-webkit-transform: skewX(45deg);
-moz-transform: skewX(45deg);
transform: skewX(45deg);
z-index: -1;
}
div:hover {
background: tomato;
}
<div>Some text here</div>
You could do this for many different trapeziums:
html,
body {
margin: 0;
padding: 0;
text-align: center;
}
body {
background: blue;
}
div {
height: 50px;
display: inline-block;
background: lightgray;
line-height: 50px;
text-align: center;
position: relative;
transition: all 0.6s;
cursor: pointer;
z-index: 1;
}
.right:before {
content: "";
position: absolute;
height: inherit;
background: inherit;
top: 0;
left: 50%;
height: 100%;
width: 100%;
-webkit-transform: skewX(45deg);
-moz-transform: skewX(45deg);
transform: skewX(45deg);
z-index: -1;
}
div:hover {
background: tomato;
}
.left {
margin-left: 50px;
}
.right {
margin-right: 50px;
}
.left:after {
content: "";
position: absolute;
height: inherit;
background: inherit;
top: 0;
left: -50%;
height: 100%;
width: 100%;
-webkit-transform: skewX(-45deg);
-moz-transform: skewX(-45deg);
transform: skewX(-45deg);
z-index: -1;
}
<div class="right">Some Text saying</div>
<br/>
<br/>
<div class="left">how much I love the</div>
<br/>
<br/>
<div class="left right">MINIONS!</div>
这篇关于梯形响应Div与CSS或jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文