简体   繁体   English

如何制作一个带有图标的输入栏响应式,垂直居中它所在的表单?

[英]How do I make a input bar with an icon overlaid on it responsive, center vertically the form it is in?

I have two input bars with icons on the left side centered inside a form, which is also centered horizontally.我有两个输入栏,左侧带有图标,在表单内居中,表单也水平居中。 Unfortunately, shrinking the page horizontally causes the placeholder text, and the icon to cross each other, and I have still not managed to find a way to center the form vertically.不幸的是,水平缩小页面会导致占位符文本和图标相互交叉,我仍然没有设法找到垂直居中表单的方法。 What can I do fix both issues?我能做些什么来解决这两个问题?

 .body-color{ background-color: rgb(30,94,255); } .signup-form{ text-align: center; margin: auto; margin-top: 5%; width: 50vw; height: fit-content; border-radius: 15px; background-color: white; box-shadow: 0 0 15pt 2pt black; } input{ width: 75%; margin-top: 20px; margin-bottom: 15px; padding: 10px; border-radius: 20px; border: 0; box-shadow: 0 0 15pt 2pt #D3D3D3; outline: 0; text-indent: 35px; } .input-container{ position: relative; } i{ position: absolute; font-size: 25px; top: 30px; left: 75px; }
 <form class="signup-form"> <div class="input-container"> <i class="bi bi-person-circle"></i> <input type="text" required placeholder="Username"/> </div> <div class="input-container"> <i class="bi bi-lock"></i> <input type="password" required placeholder="Password"/> </div> </form>

I think it will be useful for you.我认为这对你有用。 The solution was to add padding to .signup-form and change the width to 100% .解决方案是向.signup-form添加padding并将width更改为100%

 * { } .body-color { background-color: rgb(30, 94, 255); } .signup-form { text-align: center; margin: auto; margin-top: 5%; width: 50vw; height: fit-content; border-radius: 15px; background-color: white; box-shadow: 0 0 15pt 2pt black; padding: 15px 25px; /* New line */ } input { width: 100%; /* Changed */ margin-top: 20px; margin-bottom: 15px; padding: 10px; border-radius: 20px; border: 0; box-shadow: 0 0 15pt 2pt #d3d3d3; outline: 0; text-indent: 35px; box-sizing: border-box; /* New line */ } .input-container { position: relative; } i { position: absolute; font-size: 16px; /* Changed */ top: 30px; left: 17px; /* Changed */ }
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"> <form class="signup-form"> <div class="input-container"> <i class="bi bi-person-circle"></i> <input type="text" required placeholder="Username" /> </div> <div class="input-container"> <i class="bi bi-lock"></i> <input type="password" required placeholder="Password" /> </div> </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM