css - 过渡持续时间不适用于引导按钮
问题描述
我正在尝试在一些引导按钮上添加过渡效果。
问题在于高度和宽度属性。这些会立即更改,而无需考虑过渡持续时间属性。
请注意,所有其他属性都会在描述的持续时间内(本例中为 2 秒)内发生变化。
HTML
<div class="container">
<div class="row">
<div class="col">
1 of 2
</div>
<div class="col">
2 of 2
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col">
2 of 3
</div>
<div class="col">
3 of 3
</div>
</div>
<button type="button" data-toggle="modal" data-target="#infoModal" class="btn btn-outline-warning mt-5 mb-3 3mr-3 ">Learn More</button>
</div>
CSS
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.btn-outline-warning {
border-color: white;
transition: all;
transition-duration: 2s;
}
.btn-outline-warning:hover {
border-color: rgb(255, 136, 0);
background-color: rgba(0,0,0,.5);
transform: rotate(20deg);
width: 300px;
height: 100px;
}
这是我的 JSFiddle 以获得更多说明和演示。
解决方案
如果您想transition
在其中一个css
属性上使用,您需要先在其上设置默认值,然后在悬停时更改它。特别是那些需要大小之类的属性px
。width
或height
遵循此规则。
.btn-outline-warning {
border-color: white;
transition: 2s all ease;
width: 200px; /* default value */
height: 50px; /* default value */
}
.btn-outline-warning:hover {
border-color: rgb(255, 136, 0);
background-color: rgba(0, 0, 0, .5);
transform: rotate(20deg);
width: 300px;
height: 100px;
}
推荐阅读
- javascript - 如何通过 javascript lodash 更改嵌套 JSON 中的数据
- javascript - 如何简化我的减速器功能或简单的减速器功能应该多长时间?
- ubuntu - 双击打开已经运行的 jupyter lab 的 .ipynb
- java - 如何使 java JFR 在转储 StartFlightRecording 文件名和时间戳的文件中包含时间戳
- c++ - EasyHook 停止捕获一些消息
- .net - Swagger 具有相同名称的不同 API 版本,相同的路由不起作用
- r - 如何在R中订购一个情节
- c# - 在 Blazor 的开始屏幕上设置 InputText 焦点
- pine-script - 如何用指标替换策略变量
- reactjs - 如何将 HTMLElement 转换为 React 元素?