首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS转换不适用于输入宽度。

CSS转换不适用于输入宽度。
EN

Stack Overflow用户
提问于 2020-09-01 10:45:11
回答 2查看 397关注 0票数 0

我希望看到输入框中的width增加或减少,但无法使transition工作。有人知道为什么不起作用吗?

代码语言:javascript
复制
.expand input[type = "text"], 
.expand input[type = "password"]{
    border: 2px solid rgb(0, 119, 255);
    border-radius: 30px;
    background: none;
    transition: 0.25s;
}

.expand input[type = "text"]:hover,
.expand input[type = "password"]:hover{
    width: 210px;
    border-color: rgb(47, 255, 57);
}
代码语言:javascript
复制
<form>
  <h3 style="color: white; font-family: Montserrat; text-align: center;">Login</h3>
  <div class="center">
    <div class="expand">
      <input type="text" placeholder="Username" style="font-family: Montserrat; height: 30px; text-align: center; color: white; font-size: 13px;">
    </div>
  </div>
</form>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-01 10:49:29

您不能使用width: auto进行转换(这是默认的,因为您没有指定宽度),您的元素需要一个初始宽度来定义。

代码语言:javascript
复制
.expand input[type = "text"], 
.expand input[type = "password"]{
    border: 2px solid rgb(0, 119, 255);
    border-radius: 30px;
    background: none;
    transition: 0.25s;
    width: 100px; /* New CSS */
}

.expand input[type = "text"]:hover,
.expand input[type = "password"]:hover{
    width: 210px;
    border-color: rgb(47, 255, 57);
}
代码语言:javascript
复制
<form>
  <h3 style="color: white; font-family: Montserrat; text-align: center;">Login</h3>
  <div class="center">
    <div class="expand">
      <input type="text" placeholder="Username" style="font-family: Montserrat; height: 30px; text-align: center; color: white; font-size: 13px;">
    </div>
  </div>
</form>

票数 3
EN

Stack Overflow用户

发布于 2020-09-01 10:54:13

您需要设置输入的初始宽度。

代码语言:javascript
复制
.expand input[type = "text"], 
.expand input[type = "password"]{
    border: 2px solid rgb(0, 119, 255);
    border-radius: 30px;
    background: none;
    transition: 0.25s;
    width: 100px;
}

.expand input[type = "text"]:hover,
.expand input[type = "password"]:hover{
    width: 210px;
    border-color: rgb(47, 255, 57);
}
代码语言:javascript
复制
<form>
  <h3 style="color: white; font-family: Montserrat; text-align: center;">Login</h3>
  <div class="center">
    <div class="expand">
      <input type="text" placeholder="Username" style="font-family: Montserrat; height: 30px; text-align: center; color: white; font-size: 13px;">
    </div>
  </div>
</form>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63686131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档