gpt4 book ai didi

html - CSS网格体育场形状

转载 作者:行者123 更新时间:2023-12-03 16:11:04 25 4
gpt4 key购买 nike

我一直在尝试使用CSS Grid上的下图,但事实证明这非常具有挑战性
enter image description here
该图像代表体育场,但要使其看起来像所附的图像,它正在变得非常困难。一些注意事项

  • Angular 是三 Angular 形,因此最难的部分是使它们具有该形状并具有响应能力。
  • 我可以使用CSS mask 来处理形状和间距,但是会切掉一些圆圈。

  • 我做了我的尝试,一次又一次的错误,并且半途而废。知道如何使它起作用吗?也许如果有人采用不同的方法也会帮助我
    https://jsfiddle.net/rodboc/9psa4bg3/1/
    有什么想法吗?
    .grid {
    max-width: 80vw;
    min-height: 90vh;
    display: grid;
    grid-gap: 5px;
    grid-template-columns: 30% [main-start] 40% [main-end] 30%;
    grid-template-rows: 20% [main-start] 30% [main-end] 20%;
    margin: 0 auto;
    }

    [class^="item"] {
    background-color: blue;
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    align-items: flex-start;
    align-content: flex-start;
    justify-content: center;
    }

    .item1 {
    background-color: red;
    grid-area: main;
    }
    .circle {
    width: 5px;
    height: 5px;
    overflow: hidden;
    background: #ccc;
    border-radius: 50%;
    margin: 1px;
    padding: 0;
    }

    .circle:hover {
    background: blue;
    }

    <div class="grid">
    <div class="item1">
    </div>
    <div class="item2">
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    <div class="circle"></div>
    </div>
    <div class="item3"></div>
    <div class="item4"></div>
    <div class="item5"></div>
    <div class="item6"></div>
    <div class="item7"></div>
    <div class="item8"></div>
    <div class="item9"></div>
    </div>

    最佳答案

    shape-outside是您所需要的。
    这是顶部的基本思想,您可以轻松地复制底部的思想:

    body {
    width:780px;
    }

    .top {
    height:150px;
    text-align:justify;
    }
    i {
    display:inline-block;
    width:30px;
    height:30px;
    margin:2px;
    background:red;
    border-radius:50%;
    }
    .top::before {
    content:"";
    height:100%;
    width:150px;
    float:left;
    shape-outside:linear-gradient(to bottom left,transparent 49%,#fff 50%);
    }
    .top span::before {
    content:"";
    height:100%;
    width:150px;
    float:right;
    shape-outside:linear-gradient(to bottom right,transparent 49%,#fff 50%);
    }

    .left,
    .right{
    width:150px;
    height:150px;
    float:left;
    transform:translateY(-90%);
    clip-path:polygon(0 0,100vh 100vh,0 100vh );
    }
    .left::before,
    .right::before{
    content:"";
    height:100%;
    width:100%;
    float:right;
    shape-outside:linear-gradient(to bottom left,#fff 49%,transparent 50%);
    }
    .right {
    float:right;
    text-align:right;
    clip-path:polygon(-100vh 100vh,100vh 100vh,100% 0);
    }
    .right::before{
    float:left;
    shape-outside:linear-gradient(to bottom right,#fff 49%,transparent 50%);
    }

    i:hover{
    background:blue;
    }
    <div class="top"><span></span>
    <i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
    </div>

    <div class="left">
    <i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
    </div>

    <div class="right">
    <i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
    </div>

    更新
    体育场形状的完整示例:

    var t = document.querySelector('.top');
    var tl = document.querySelector('.top-left');
    var tr = document.querySelector('.top-right');
    var b = document.querySelector('.bottom');
    var bl = document.querySelector('.bottom-left');
    var br = document.querySelector('.bottom-right');
    var sl = document.querySelector('.side-left');
    var sr = document.querySelector('.side-right');
    for (var i = 0; i < 5000; i++) {
    var l = document.createElement("i");
    t.appendChild(l);
    l = document.createElement("i");
    tl.appendChild(l);
    l = document.createElement("i");
    tr.appendChild(l);
    l = document.createElement("i");
    b.appendChild(l);
    l = document.createElement("i");
    bl.appendChild(l);
    l = document.createElement("i");
    br.appendChild(l);
    l = document.createElement("i");
    sl.appendChild(l);
    l = document.createElement("i");
    sr.appendChild(l);
    }
    body {
    margin: 0;
    }

    .stadium {
    display: grid;
    min-width:600px;
    min-height:500px;
    grid-template-columns: 20% 1fr 20%;
    grid-template-rows: 150px 1fr 150px;
    row-gap:10px;
    height: 100vh;
    line-height: 0;
    }

    .top,
    .bottom{
    height: 100%;
    grid-column: 1/-1;
    grid-row: 1;
    text-align: justify;
    overflow: hidden;
    }
    .bottom {
    grid-row: 3;
    }

    .top::before,
    .bottom::before{
    content: "";
    height: 100%;
    width: 20%;
    float: left;
    shape-outside: linear-gradient(to bottom left, transparent 49%, #fff 50%);
    }
    .bottom::before{
    shape-outside: linear-gradient(to top left, transparent 49%, #fff 50%);
    }

    .top span::before,
    .bottom span::before {
    content: "";
    height: 100%;
    width: 20%;
    float: right;
    shape-outside: linear-gradient(to bottom right, transparent 49%, #fff 50%);
    }
    .bottom span::before {
    shape-outside: linear-gradient(to top right, transparent 49%, #fff 50%);
    }

    .top-left,
    .top-right,
    .bottom-left,
    .bottom-right{
    width: 100%;
    height: 100%;
    float: left;
    grid-row: 1;
    grid-column: 1;
    overflow: hidden;
    clip-path: polygon(0 0, 100% 100%, 0 100%);
    }

    .bottom-left {
    grid-row: 3;
    grid-column: 1;
    clip-path: polygon(0 0, 100% 0,0 100%);
    }


    .top-left::before,
    .top-right::before,
    .bottom-left::before,
    .bottom-right::before{
    content: "";
    height: 100%;
    width: 100%;
    float: right;
    shape-outside: linear-gradient(to bottom left, #fff 49%, transparent 50%);
    }
    .bottom-left::before {
    shape-outside: linear-gradient(to top left, #fff 49%, transparent 50%);
    }
    .top-right,
    .bottom-right{
    float: right;
    text-align: right;
    grid-column: 3;
    clip-path: polygon(0 100%, 100% 100%, 100% 0);
    }
    .bottom-right {
    grid-row: 3;
    clip-path: polygon(0 0, 100% 0,100% 100%);
    }

    .top-right::before {
    float: left;
    shape-outside: linear-gradient(to bottom right, #fff 49%, transparent 50%);
    }
    .bottom-right::before {
    float: left;
    shape-outside: linear-gradient(to top right, #fff 49%, transparent 50%);
    }

    .side-right,
    .side-left {
    height:100%;
    overflow:hidden;
    }
    .side-right {
    grid-column:3;
    text-align:right;
    }

    i {
    display: inline-block;
    vertical-align: top;
    width: 8px;
    height: 8px;
    margin: 1px;
    background: red;
    border-radius: 50%;
    }

    i:hover {
    background: blue;
    }
    <div class="stadium">
    <div class="top-left"></div>
    <div class="top"><span></span></div>
    <div class="top-right"></div>

    <div class="bottom-left"></div>
    <div class="bottom"><span></span></div>
    <div class="bottom-right"></div>

    <div class="side-left"></div>
    <div class="side-right"></div>
    </div>

    关于html - CSS网格体育场形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62461163/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com