How to achieve this visual using CSS

前端 未结 2 904
滥情空心
滥情空心 2021-01-27 23:56

I need to create the above visual using only css and only one div having 300px height and width. I tried gradient but could not get anything same. Anyone can help pleas

相关标签:
2条回答
  • 2021-01-28 00:36

    You can try having a few divs and then have it encapsulated inside one div. Check out my code on 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>
    
    0 讨论(0)
  • 2021-01-28 00:37

    gradient is a fine idea, you could even add content, no matter the size for the gradient, as long as you size it to be a square:

    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>

    0 讨论(0)
提交回复
热议问题