如何向上增加物体的大小并保持其形状?
How to increase size of object upwards and maintain its shape?
我有 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>
当我将它添加到我的地图时,它会生成以下内容:
当我尝试通过 CSS 增加尺寸时,尺寸向后调整(向下而不是向上)。
我试图通过位置和 height
修复它,但仍然得到相同的向下结果。
问题:
- 怎样才能向上调整
- 保持圆柱体的形状不变(底部和
top
应该是圆的)。
- 是否可以让 'dynamic adjustment' 说
<div class="tank-20"></div>
(表示 20 height
)和 <div class="tank-80"></div>
(= 80 in height
)。
当您增加 .tank
的 height
时,您也应该在 .tank:after
处增加 top
属性,因为您无法增加高度 .tank
和尺寸向上添加 .tank
唯一的解决方案是使用 right
、left
、top
和 bottom
调整你的 .tank
应该在哪里 看看我如何增加 .tank
的 height
的例子,但仍然有圆柱形状
I increase height
of .tank
from 180px
to 225px
and top of .tank:after
from 155px
to 200px
例子
.tank {
position: relative;
margin: 50px;
width: 120px;
height: 225px;
background-color: #444;
}
.tank:before {
width: 120px;
height: 50px;
background-color: #666;
-moz-border-radius: 60px / 25px;
-webkit-border-radius: 60px / 25px;
border-radius: 60px / 25px;
position: absolute;
content: '';
top: -25px;
}
.tank:after {
width: 120px;
height: 50px;
background-color: #444;
-moz-border-radius: 60px / 25px;
-webkit-border-radius: 60px / 25px;
border-radius: 60px / 25px;
position: absolute;
content: '';
top: 200px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75);
z-index: -1;
}
<div class="tank"></div>
您可以像下面这样更新您的代码:
.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>
我有 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>
当我将它添加到我的地图时,它会生成以下内容:
当我尝试通过 CSS 增加尺寸时,尺寸向后调整(向下而不是向上)。
我试图通过位置和 height
修复它,但仍然得到相同的向下结果。
问题:
- 怎样才能向上调整
- 保持圆柱体的形状不变(底部和
top
应该是圆的)。 - 是否可以让 'dynamic adjustment' 说
<div class="tank-20"></div>
(表示 20height
)和<div class="tank-80"></div>
(= 80 inheight
)。
当您增加 .tank
的 height
时,您也应该在 .tank:after
处增加 top
属性,因为您无法增加高度 .tank
和尺寸向上添加 .tank
唯一的解决方案是使用 right
、left
、top
和 bottom
调整你的 .tank
应该在哪里 看看我如何增加 .tank
的 height
的例子,但仍然有圆柱形状
I increase
height
of.tank
from180px
to225px
and top of
.tank:after
from155px
to200px
例子
.tank {
position: relative;
margin: 50px;
width: 120px;
height: 225px;
background-color: #444;
}
.tank:before {
width: 120px;
height: 50px;
background-color: #666;
-moz-border-radius: 60px / 25px;
-webkit-border-radius: 60px / 25px;
border-radius: 60px / 25px;
position: absolute;
content: '';
top: -25px;
}
.tank:after {
width: 120px;
height: 50px;
background-color: #444;
-moz-border-radius: 60px / 25px;
-webkit-border-radius: 60px / 25px;
border-radius: 60px / 25px;
position: absolute;
content: '';
top: 200px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75);
z-index: -1;
}
<div class="tank"></div>
您可以像下面这样更新您的代码:
.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>