Can't make CSS width transition work

为君一笑 提交于 2019-12-12 00:37:48

问题


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.

Here's my 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%;
}

Here's the 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?


回答1:


You should add width rule for non hover selector.

https://jsfiddle.net/qz3qj846/



来源:https://stackoverflow.com/questions/36391479/cant-make-css-width-transition-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!