如何使用CSS实现这种视觉效果

时间:2016-02-16 00:43:54

标签: css css3

enter image description here

我需要仅使用css创建上述视觉效果,并且只需要一个高度和宽度为300px的div。我尝试过渐变但却得不到任何相同的东西。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

渐变是个好主意,你甚至可以添加内容,无论渐变的大小,只要你把它的大小设为正方形:

div {
  background-color: red;
  border-radius: 0 0 50% 50%;
  background-image: 
       linear-gradient(-45deg, transparent 75%, blue 75%), 
       linear-gradient(45deg, transparent 75%, yellow 75%), 
       linear-gradient(to top, green 50%, transparent 50%);
  height: 300px;
  width: 300px;
  transition:0.5s;
}
div:hover {
  height: 150px;
  width: 150px;
}
/* fun */

div {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 2.5em;
  color: white;
  text-shadow: 0 0 1px black, 0 0 1px black, 0 0 1px black, 0 0 1px black, 0 0 1px black, 0 0 1px black;
  box-shadow: 0 0 5px gray, inset 0 0 0 3px white,inset 0 0 5px black;
}
<div>Hover me</div>

答案 1 :(得分:0)

您可以尝试使用几个div,然后将其封装在一个div中。 在JSfiddle上查看我的代码。

.main {
  width: 300px;
  height: 300px;
}
.first {
  width: 300px;
  height: 150px;
}
.blue {
  width:150px;
  height: 150px;
  position: relative;
  float: left;
  background-color: blue;
}
.yellow {
  width:150px;
  height: 150px;
  position: relative;
  float: right;
  background-color: yellow;
}
.green {
  width: 300px;
  height: 150px;
  background-color: green;
  border-radius: 0 0 500px 500px;
}

.red {
  position: relative;
  height: 150px;
  top: -400px;
  border-left: 150px solid transparent;
  border-right: 150px solid transparent;
  border-bottom: 150px solid red;
}



<div class="main">
  <div class="first">
    <div class="blue">
    </div>
    <div class="yellow">
    </div>
  </div>
  <div class="green">
  </div>
  <div class="red">
  </div>
</div>
相关问题