简体   繁体   English

如何删除输入字段的边框底部?

[英]How do I remove border bottom of input field?

Can anyone tell me how do I remove border-bottom of the input field when I start writing? 谁能告诉我开始书写时如何删除输入字段的边框底部?

 .car-list-input { font-family: 'Source Sans Pro', sans-serif; border-radius: 3px; font-size: 14px; font-weight: 400 !important; height: 35px; position: relative; border-left: 2px solid #e0e6e8; border-right: 2px solid #e0e6e8; border-top: 2px solid #e0e6e8; border-bottom: 0px; } .car-list-input:focus { border-color: #25c16f; outline: 0; box-shadow: none; border-bottom: 0px; } 
 <input type="text" placeholder="Enter the location of your vehicle" id="location" onchange="locationApproved()" autocomplete="off" class="form-control car-list-input"> 

You didn't defined any margin-bottom style. 您没有定义任何边距底样式。

The input looks "tall" because your font size is 14px and the input height is 35px. 输入看起来“高”,因为您的字体大小为14px,输入高度为35px。

So maybe, just low the height, put some padding and add an event listener. 因此,也许只是降低高度,添加一些填充并添加事件监听器。

 document.getElementById("location").addEventListener("keyup", function(){ if (this.value != '') { this.style.borderBottomWidth = "0px" } else { this.style.borderBottomWidth = "2px" } },false) 
 .car-list-input { font-family: 'Source Sans Pro', sans-serif; border: 2px solid #e0e6e8; border-radius: 3px; font-size: 14px; font-weight: 400 !important; height: 35px; position: relative; } .car-list-input:focus { border-color: #25c16f; outline: 0; box-shadow: none; border-bottom: solid 2px #25c16f; } 
 <input type="text" placeholder="Enter the location of your vehicle" id="location" onchange="locationApproved()" autocomplete="off" class="form-control car-list-input"> 

Also, pure CSS proposition, add a required attribute to input and check the new CSS : 另外,纯CSS命题,添加一个required属性以输入并检查新CSS:

 .car-list-input { font-family: 'Source Sans Pro', sans-serif; border-style: solid; border-color: #e0e6e8; border-width: 2px 2px 0 2px; border-radius: 3px; font-size: 14px; font-weight: 400 !important; height: 35px; position: relative; } .car-list-input:focus { border-color: #25c16f; outline: 0; box-shadow: none; border-color: #25c16f; } .car-list-input:invalid { border-width:2px; } 
 <input type="text" required placeholder="Enter the location of your vehicle" id="location" onchange="locationApproved()" autocomplete="off" class="form-control car-list-input"> 

I'm not sure if you mean padding or margin. 我不确定您是指填充还是边距。 Here are two examples: 这是两个示例:

margin-bottom : margin-bottom

https://jsfiddle.net/q049negk/ https://jsfiddle.net/q049negk/

 .car-list-input { font-family: 'Source Sans Pro', sans-serif; border-radius: 3px; font-size: 14px; font-weight: 400 !important; height: 35px; position: relative; border-left: 2px solid #e0e6e8; border-right: 2px solid #e0e6e8; border-top: 2px solid #e0e6e8; border-bottom: 0px; margin-bottom: 50px; } .car-list-input:focus { border-color: #25c16f; outline: 0; box-shadow: none; border-bottom: solid 2px #25c16f; margin-bottom: 0px; } .square { height: 60px; width: 60px; background: red; margin: 0; padding: 0; } 
 <input type="text" placeholder="Enter the location of your vehicle" id="location" onchange="locationApproved()" autocomplete="off" class="form-control car-list-input"> <div class="square"> </div> 

padding-bottom : padding-bottom

https://jsfiddle.net/q049negk/1/ https://jsfiddle.net/q049negk/1/

 .car-list-input { font-family: 'Source Sans Pro', sans-serif; border-radius: 3px; font-size: 14px; font-weight: 400 !important; height: 35px; position: relative; border-left: 2px solid #e0e6e8; border-right: 2px solid #e0e6e8; border-top: 2px solid #e0e6e8; border-bottom: 0px; padding-bottom: 50px; } .car-list-input:focus { border-color: #25c16f; outline: 0; box-shadow: none; border-bottom: solid 2px #25c16f; padding-bottom: 0px; } .square { height: 60px; width: 60px; background: red; margin: 0; padding: 0; } 
 <input type="text" placeholder="Enter the location of your vehicle" id="location" onchange="locationApproved()" autocomplete="off" class="form-control car-list-input"> <div class="square"> </div> 


Here are MDN links for both: 这是两者的MDN链接:

margin-bottom

padding-bottom

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

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