gpt4 book ai didi

html - 如何向上增加物体的尺寸并保持其形状?

转载 作者:行者123 更新时间:2023-12-03 21:10:51 24 4
gpt4 key购买 nike

我有 following CSS:

.tank {
position:relative;
width:12px;
height:18px;
background-color:#444;
}
.tank:before {
width: 12px;
height: 5px;
background-color:#666;
-moz-border-radius: 6px / 2.5px;
-webkit-border-radius: 6px / 2.5px;
border-radius: 6px / 2.5px;
position:absolute;
content:'';
top:-2.5px;
}
.tank:after {
width: 12px;
height: 5px;
background-color:#444;
-moz-border-radius: 6px / 2.5px;
-webkit-border-radius: 6px / 2.5px;
border-radius: 6px / 2.5px;
position:absolute;
content:'';
top:15.5px;
box-shadow:0px 0px 10px rgba(0, 0, 0, 0.75);
z-index: -1;
}


</style>
当我将它添加到我的 map 时,它会产生以下内容:
enter image description here
当我尝试通过 CSS 增加大小时,大小会向后调整(向下而不是向上)。
enter image description here
我试图通过位置和 height 修复它但仍然得到相同的下降结果。
问题:
  • 我怎样才能让它向上调整
  • 保持圆柱体的形状相同(底座和 top 应该是圆形的)。
  • 是否可以进行“动态调整”,例如 <div class="tank-20"></div> (意味着 20 height )和 <div class="tank-80"></div> (= 80 在 height )。

  • jsfiddle

    最佳答案

    您可以像下面这样更新您的代码:

    .tank {
    position: relative;
    display:inline-block; /* this will make them stay at the bottom */
    margin: 40px 10px;
    width: 120px;
    height: var(--w,180px);
    background-color: #444;
    border-radius: 60px / 25px;
    }

    .tank:before,
    .tank:after{
    border-radius: inherit;
    position: absolute;
    content: '';
    width:100%;
    height: 50px;
    }
    .tank:before {
    background-color: #666;
    top: 0;
    }

    .tank:after {
    background-color: #444;
    bottom:0;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75);
    z-index: -1;
    }
    <div class="tank"></div>
    <div class="tank" style="--w:100px"></div>
    <div class="tank" style="--w:200px"></div>
    <div class="tank" style="--w:80px"></div>

    另一个想法。悬停以查看增长效果:

    .tank {
    position: relative;
    display:inline-block;
    margin: 40px 10px;
    width: 120px;
    /* big height here to illustarte,
    you don't need it if you will place your element using position:absolute */
    height: 300px;
    }

    .tank:before,
    .tank:after{
    position: absolute;
    content: '';
    width:100%;
    height: 50px;
    bottom: 0;
    border-radius: 60px / 25px;
    }
    .tank:after {
    background:
    radial-gradient(50% 50%,#666 98%,transparent 100%) top/100% 50px no-repeat,
    #444;
    bottom:25px;
    height:var(--w,180px);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    transition:0.5s;
    }

    .tank:before {
    background-color: #444;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75);
    }

    .tank:hover::after {
    height:calc(1.5*var(--w,180px));
    }
    <div class="tank"></div>
    <div class="tank" style="--w:100px"></div>
    <div class="tank" style="--w:200px"></div>
    <div class="tank" style="--w:80px"></div>

    关于html - 如何向上增加物体的尺寸并保持其形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63960884/

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