Open zhaobinglong opened 3 years ago
<style>
#cont {
display: inline-block;
max-width: 50px; // 借助max-width
line-height: 50px;
background-color: green;
color: #FFF;
padding: 6px 10px;
transition: all 1s;
}
</style>
<body>
<div id="cont">
dkkdkkdncnksk
</div>
<div>
<button onclick="test()">点击测试 </button>
</div>
</body>
<script type="text/javascript">
function test() {
document.getElementById('cont').innerHTML='dkddkllaslslslslslkxkkkkdldldldldlldllslsl'
// 点击后变更元素的max-width
document.getElementById("cont").style.maxWidth = "1000px";
}
</script>
<style>
#cont {
display: inline-block;
width: 50px; // 设置一个固定宽度
line-height: 50px;
background-color: green;
color: #FFF;
padding: 6px 10px;
transition: width 1s; // 设置过渡效果
}
</style>
<body>
<div id="cont">
dkkdkkdncnksk
</div>
<div>
<button onclick="test()">点击测试 </button>
</div>
</body>
<script type="text/javascript">
function test() {
// 点击后设置新的宽度
document.getElementById('cont').innerHTML='dkddkllaslslslslslkxkkkkdldldldldlldllslsl'
document.getElementById("cont").style.width = "300px";
}
</script>
https://css-tricks.com/using-css-transitions-auto-dimensions/
// 使用公式(an+ b).描述:a代表一个循环的大小,N是一个计数器(从0开始),以及b是偏移量。
.item:nth-child(4n+1) {
padding-left: 0;
}
// 选择容器中最后一个p元素
p:last-of-type {
margin-bottom: 0;
}
box-shadow: h-shadow v-shadow blur spread color inset;
例子:生成1px的白色内边框
//参数说明 //1 //2 上下偏移 //3 box-shadow: 0 0 0px 1px #fff inset
box-shadow: 0 2px 10px 0 rgba(0,0,0,.4)
box-shadow: 0 1px 2px rgba(150,150,150,0.3)
box-shadow: 1rpx 1rpx 1rpx rgba(0,0,0,0.2),0rpx 0rpx 1rpx rgba(0,0,0,0.1)
@media screen and (-webkit-min-device-pixel-ratio: 2) {
.h5ui-card { border-bottom: 0.5px solid #999 }
}
@media screen and (-webkit-min-device-pixel-ratio: 3) {
.h5ui-card { border-bottom: 0.333333px solid #999 }
}
// 这是元素的宽度为当前容器宽度的20%再减去10px
width: calc(20% - 10px);
.btn {
position: relative;
}
.btn::before {
content: '';
position: absolute;
top: -20px;
right: -20px;
bottom: -20px;
left: -20px;
}
.box { position: -webkit-sticky; position: sticky;
.base-one-circle {
width: 100px;
height: 100px;
position: relative;
background: radial-gradient(circle at 0px 50px, transparent 10px, #28A4F2 0) top
}
// 在父元素没有设置高度的情况下,可以设置图片height:100%,可以解决这个问题。
height:100%
h1::before {
content: "*";
color: #ff4d4f;
}
多个容器堆叠在一起,边框不变粗
原理上是给父元素设置左边框和上边框,然后子元素统一设置右边框和下边框
demo
效果