html - 没有图像的 CSS3 多边形,如何?

标签 html css polygon css-shapes

我正在建立一个网站,它是这样的 without expansion

顶部的两个结构是静态的,底部的四个是动态的,当我说动态时,我的意思是可扩展的,像这样

with expansion

因为这些只是颜色、形状和阴影,我相信可以使用 CSS3 来创建它们。但是我很难这样做。我什至尝试使用 CSSHat,但结果很糟糕。

这是示例形状 individual shape

这是生成的代码:

width: 1920px;
height: 341px;
-moz-border-radius: 0 1920px 1920px / 0 181px 56px;
-webkit-border-radius: 0 1920px 1920px / 0 181px 56px;
border-radius: 0 1920px 1920px / 0 181px 56px; /* border radius */
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box; /* prevents bg color from leaking outside the border */
background-color: #3b0f1d; /* layer fill content */

结果是这样的: converted shape 可以在这里找到一个实例 http://codepen.io/seraphzz/pen/mgDwd

实现此目标的最佳方式是什么?

最佳答案

您可以使用 CSS transforms 来旋转 div。

我已将底部 div 设为动态,并向黄色绿色 div 添加了一些内容。

body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}
.top, .top2, .yellow, .green, .bottom, .bottom2 {
    height: 200px;
    width: 140%;
    position: relative;
    left: -10%;
    transform-origin: 0% 100%;
    transition: 0.6s ease;
}
.top {
    top: -180px;
    background: #3C101D;
    transform: rotate(4deg);
}
.top2 {
    background: #931930;
    transform: rotate(-1.5deg);
}
.yellow {
    background: #F0810E;
    top: -200px;
    transform: rotate(0.6deg);
}
.content {
    display: block;
    width: 65%;
    position: relative;
    top: 10%;
    left: 10%;
}
.yellow .content {
    transform: rotate(-0.6deg);
}
.green {
    background: #425949;
    top: -320px;
    transform: rotate(-1.4deg);
}
.green .content {
    transform: rotate(1.4deg);
}
.bottom {
    background: #501B2B;
    top: -480px;
    transform: rotate(1.4deg);
}
.bottom2 {
    background: #3C101D;
    top: -600px;
    transform: rotate(-0.6deg);
}
.yellow:hover, .green:hover, .bottom:hover, .bottom2:hover {
    height: 400px;
}
<div class="top"></div>
<div class="top2"></div>
<div class="yellow">
    <div class="content">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div>
</div>
<div class="green">
<div class="content">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div>
</div>
</div>
<div class="bottom"></div>
<div class="bottom2"></div>

关于html - 没有图像的 CSS3 多边形,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16813560/

相关文章:

javascript - 我可以使用 Raphael.js 之类的东西在 HTML 窗口上方绘制矢量吗?

java - 坐标点在jmapviewer多边形中?

javascript - 使用javascript使用经度和纬度计算多边形的面积

html - 我怎样才能摆脱表格单元格之间的这个像素空间?

html - Bootstrap 响应式网格 : Column 1 - image on top and text vertically aligned middle, 第 2 列 - 2 张大图

javascript - 无论我水平滚动多少,如何让一个 div 卡在页面的左侧?

javascript - 将具有颜色的变量分配给 CSS 中的背景属性

jquery - 根据 Ruby on Rails 中的当前数据库记录更改元素内容

sql - 从最小和最大纬度/经度创建多边形(矩形)

html - 为什么这个简单的嵌套 DIV 在 Chrome 和 FireFox 中呈现不同?