无法使CSS宽度过渡生效 [英] Can't make CSS width transition work

查看:190
本文介绍了无法使CSS宽度过渡生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找出如何使CSS宽度过渡正常工作。好吧,它确实有效,但是它只是从 auto 跳到了 100%没有动画。

I couldn't manage to find out how to make the CSS width transition work. Well, it actually work, but it just jump from auto to 100% with no animation.

这是我的CSS:

div#searchbar {
    padding: 10px;
    background-color: #404040;
}

.searchbar input {
    box-sizing: border-box;
    padding: 10px;
    font-family: Open Sans;
    font-size: 16px;
    color: #404040;
    outline: none;
    background-color: #909090;
    padding-left: 40px;
    -webkit-transition: width 0.4s ease-in-out;
    transition: width 0.4s ease-in-out;
}

.searchbar input:hover {
    width: 100%;
}

以下是HTML:

<html>
    <head>
        <title>
            Test
        </title>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="styles/global.css" />
        <meta name="viewport" content="width=device-width, initial-scale: 1.0, user-scalabe=0" />
        <script src="scripts/jquery-1.12.2.js"></script>
    </head>

    <body>
        <div class="searchbar">
            <form name="Search">
                <input type="text" name="Search" value="Pesquisar...">
            </form>
        </div>
    </body>          
</html>

还有一件事困扰着我,您可以在下图中看到:

There's also one thing bothering me, you can see in the image below:

图像
白色边框

image Which is the white border that shows sometimes.

我如何使所有工作正常?

How can I make everything work?

推荐答案

您应为非悬停选择器添加宽度规则。

You should add width rule for non hover selector.

https://jsfiddle.net/qz3qj846/

这篇关于无法使CSS宽度过渡生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆