html - 使用 CSS 选择器的动画不起作用

标签 html css css-selectors css-transitions

我的 HTML:

<div id="composite-field">
        <input type='email' name='email' class='input animate' value='' placeholder='E-mail'>
        <input type='submit' id='submit' class='submit animate' value='>'>
</div>

我的 CSS:

.animate { -webkit-transition: all 0.2s ease-in-out; -moz-transition: all 0.2s ease-in-out; -o-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; }    

html body div.body-container form div#composite-field {
            position: relative; float: left;
            width: 80%; height: 100px; margin: 0 10%; padding: 0;
        }

        html body div.body-container form div#composite-field input[type=email] {
            float: left;
            width: 90%; height: 100px; margin: 0; padding: 0 6% 0 4%;

            border: 0; outline: none;
            -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;
            background-color: #eab94e; color: rgba(26, 60, 88, 0.9);

            z-index: 10;
        }

        html body div.body-container form div#composite-field input[type=submit] {
            position: absolute; float: none; clear: both; top: 0; right: 5%;
            min-width: 80px; width: auto; height: 100px; margin: 0; padding: 0;

            border: 0; border-radius: 0; outline: none; -webkit-appearance: none;
            background-color: #2e4856; color: #eab94e;
            z-index: 11;
        }

        html body div.body-container form div#composite-field input[type=email],
        html body div.body-container form div#composite-field input[type=submit] { font-family: "Fjalla One", sans-serif; font-weight: 400; font-size: 40px; letter-spacing: normal; }

        html body div.body-container form div#composite-field input[type=email]:focus { 
            box-shadow: inset 0 0 0 5px rgba(26, 60, 88, 0.9);
        }

        html body div.body-container form div#composite-field input[type=submit]:hover { opacity: 0.5; }

现在问题来了,20% 的宽度没有得到动画。它以前有效。而且我似乎无法弄清楚为什么不是现在...

html body div.body-container form div#composite-field input[type=email]:focus ~ input[type=submit] { width: 20%; }

我的 CSS 是否有错误?

谢谢。

最佳答案

问题是您的提交按钮的宽度为“自动”,正在过渡到 80%(宽度仅使用最小宽度设置)。如果您在其上设置宽度,过渡将起作用。这是一个 fiddle : http://jsfiddle.net/znm63rky/15/

html body div.body-container form div#composite-field input[type=submit] {
    width: 80px;
}

关于html - 使用 CSS 选择器的动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28269866/

相关文章:

javascript - 难以理解 if 语句代码

python - 如何从 Django ModelChoiceField 查询集中选择值和标签

javascript - 将鼠标悬停在图像上时 Bootstrap 4 弹出窗口

带前置/append 的 Jquery 奇数/偶数问题

javascript - 尝试使用 Nightwatch.js 单击具有相同类的第二个元素

javascript - jQuery 在计数后插入关闭的 div 标签和打开的 div 标签

html - 图像在 Firefox 中完全不对齐,但在 Chrome 中没有

javascript - 无法让 jQuery 匹配高度

html - 文本转换是否为 : Capitalize work for <option> elements,?如果是,在哪些浏览器中?

css - 在没有额外标记的情况下将 clearfix 应用到第 n 个 child