.input{ width: 278px; height: 18px; margin-bottom: 10px; outline: none; padding: 10px; font-size: 13px; color: white; text-shadow:1px 1px 1px; border-top: 1px solid #312E3D; border-left: 1px solid #312E3D; border-right: 1px solid #312E3D; border-bottom: 1px solid #56536A; border-radius: 4px; background-color: #fff; }在此代码的基础上怎么样使得在文本框中输入的文字可以被看见
时间: 2024-02-12 11:08:48 浏览: 82
要使在文本框中输入的文字可以被看见,需要在CSS样式中设置文本框的背景颜色和文字颜色不同,例如可以将文本框的背景颜色设置为白色,文字颜色设置为黑色。可以在代码中添加如下CSS样式:
```
.input:focus {
background-color: #fff;
color: #000;
}
```
这样当文本框被选中时,背景色变为白色,文字颜色变为黑色,输入的文字就可以被看见了。
相关问题
* { margin: 0; padding: 0; box-sizing: border-box; } html, body { width: 100%; height: 100%; } body { background: #252525; } .container { position: absolute; margin: auto; top: 0; left: 0; right: 0; bottom: 0; width: 300px; height: 100px; } .container .search { position: absolute; margin: auto; top: 0; right: 0; bottom: 0; left: 0; width: 80px; height: 80px; background: crimson; border-radius: 50%; transition: all 1s; z-index: 4; box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.4); } .container .search:hover { cursor: pointer; } .container .search::before { content: ""; position: absolute; margin: auto; top: 22px; right: 0; bottom: 0; left: 22px; width: 12px; height: 2px; background: white; transform: rotate(45deg); transition: all 0.5s; } .container .search::after { content: ""; position: absolute; margin: auto; top: -5px; right: 0; bottom: 0; left: -5px; width: 25px; height: 25px; border-radius: 50%; border: 2px solid white; transition: all 0.5s; } .container input { font-family: "Inconsolata", monospace; position: absolute; margin: auto; top: 0; right: 0; bottom: 0; left: 0; width: 50px; height: 50px; outline: none; border: none; background: crimson; color: white; text-shadow: 0 0 10px crimson; padding: 0 80px 0 20px; border-radius: 30px; box-shadow: 0 0 25px 0 crimson, 0 20px 25px 0 rgba(0, 0, 0, 0.2); transition: all 1s; opacity: 0; z-index: 5; font-weight: bolder; letter-spacing: 0.1em; } .container input:hover { cursor: pointer; } .container input:focus { width: 300px; opacity: 1; cursor: text; } .container input:focus ~ .search { right: -250px; background: #151515; z-index: 6; } .container input:focus ~ .search::before { top: 0; left: 0; width: 25px; } .container input:focus ~ .search::after { top: 0; left: 0; width: 25px; height: 2px; border: none; background: white; border-radius: 0%; transform: rotate(-45deg); } .container input::placeholder { color: white; opacity: 0.5; font-weight: bolder; }
这段代码是一个简单的搜索框样式,使用了CSS3的动画效果。其中包括一个圆形搜索按钮(红色),点击按钮后输入框会从小圆圈扩大为长方形,并且搜索按钮会移动到输入框的左侧,并且变为白色。同时,输入框的背景颜色也会变成一个深色,并且输入框的宽度会变宽,以便用户能够输入更多的内容。在输入框中输入搜索内容时,输入框的文本颜色变为白色,而搜索按钮的形状也会变化,以增强用户的反馈感。
优化这个页面代码:.login { text-align: center; margin: 100px auto; width: 600px; height: 520px; background-color: rgba(87, 86, 86, 0.2); border-radius: 25px; box-shadow: 5px 2px 35px -7px #ff9a9e; } .login h2 { margin-top: 40px; color: aliceblue; font-weight: 100; } .login_form { padding: 20px; } .login_form span { color: rgb(131, 220, 255); font-size: 18px; font-weight: 100; } .login_form input { background-color: transparent; width: 320px; padding: 2px; text-indent: 2px; color: white; font-size: 30px; font-family: "KaiTi"; height: 45px; margin: 30px 30px 30px 5px; outline: none; border: 0; border-bottom: 1px solid rgb(131, 220, 255); } input::placeholder { color: #fbc2eb; font-weight: 100; font-size: 18px; font-style: italic; } .login_btn { background-color: rgba(255, 255, 255, 0.582); border: 1px solid rgb(190, 225, 255); padding: 10px; width: 220px; height: 60px; border-radius: 30px; font-size: 35px; font-family: "KaiTi"; color: white; font-weight: 100; margin-top: 15px; } .login_btn:hover { box-shadow: 2px 2px 15px 2px rgb(190, 225, 255); background-color: transparent; /* 选择动画 / animation: login_mation 0.5s; } / 定义动画 */ @keyframes login_mation { from { background-color: rgba(255, 255, 255, 0.582); box-shadow: 0px 0px 15px 2px rgb(190, 225, 255); } to { background-color: transparent; box-shadow: 2px 2px 15px 2px rgb(190, 225, 255); } }
.login {
text-align: center;
margin: 100px auto;
width: 600px;
height: 520px;
background-color: rgba(87, 86, 86, 0.2);
border-radius: 25px;
box-shadow: 5px 2px 35px -7px #ff9a9e;
}
.login h2 {
margin-top: 40px;
color: aliceblue;
font-weight: 100;
}
.login_form {
padding: 20px;
}
.login_form span {
color: rgb(131, 220, 255);
font-size: 18px;
font-weight: 100;
}
.login_form input {
background-color: transparent;
width: 320px;
padding: 2px;
text-indent: 2px;
color: white;
font-size: 30px;
font-family: "KaiTi";
height: 45px;
margin: 30px 30px 30px 5px;
outline: none;
border: 0;
border-bottom: 1px solid rgb(131, 220, 255);
}
input::placeholder {
color: #fbc2eb;
font-weight: 100;
font-size: 18px;
font-style: italic;
}
.login_btn {
background-color: rgba(255, 255, 255, 0.582);
border: 1px solid rgb(190, 225, 255);
padding: 10px;
width: 220px;
height: 60px;
border-radius: 30px;
font-size: 35px;
font-family: "KaiTi";
color: white;
font-weight: 100;
margin-top: 15px;
transition: all 0.3s ease-in-out; /* 添加过渡效果 */
}
.login_btn:hover {
box-shadow: 2px 2px 15px 2px rgb(190, 225, 255);
background-color: transparent;
animation: login_mation 0.5s;
}
@keyframes login_mation {
from {
background-color: rgba(255, 255, 255, 0.582);
box-shadow: 0px 0px 15px 2px rgb(190, 225, 255);
}
to {
background-color: transparent;
box-shadow: 2px 2px 15px 2px rgb(190, 225, 255);
}
}
优化建议:
1. 添加过渡效果,使按钮 hover 时更加平滑
2. 将选择动画添加到 hover 触发的样式中,避免在加载页面时就执行动画
3. 将动画的定义移到样式表的最后面,避免影响其他样式的加载速度
阅读全文