【发布时间】:2020-09-13 08:31:53
【问题描述】:
我正在尝试在输入我的input 标签后显示一个按钮。目前我将我的按钮设置为display: none,当我专注于输入字段时,它应该改变我的display: inline-block,这应该让它重新出现。我做错了什么?
html
<h1 className='title-caption'>Get started today!</h1>
<div className='email-newsletter-container'>
<p className='sign-up-caption'>
Sign up for our newletter for more information
</p>
<input
className='email-input'
placeholder='Enter email address'
></input>
<br />
<button className='submit-button' id='submit-button'>
Submit
</button>
</div>
css
.email-input {
margin-top: 20px;
height: 40px;
width: 400px;
text-align: center;
border-radius: 5px;
border: none;
outline: none;
position: relative;
&:focus + .submit-button {
display: inline-block;
}
}
.email-input:focus + .submit-button {
display: inline-block;
}
.submit-button {
position: relative;
border-radius: 20px;
width: 90px;
margin-top: 15px;
padding: 10px 10px 10px 10px;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande',
'Lucida Sans', Arial, sans-serif;
background-color: transparent;
border: 2px solid white;
color: white;
display: none;
}
【问题讨论】:
-
只是为了确保:您的“CSS”代码必须首先通过预处理器运行。你做到了,对吧?
-
@Sirko,确定他没有,这些都是 CSS 选择器
-
尝试使用
~选择器而不是+选择器。+将选择任何紧随其后的元素,而~选择任何紧随其后的元素 -
@Simplicius 您能否向我解释一下这适用于 CSS 标准的哪一部分:
&:focus + .submit-button作为嵌套选择器。 -
@Sirko,这里有一些参考:w3schools.com/cssref/css_selectors.asp