Give Button and Text on the same line and text to be center of button

谁说我不能喝 提交于 2019-12-23 15:54:22

问题


<input type="button" class="click" id="click" value="Click" style="width: 45px; margin-top: 1.5%; height: 20px; text-align: center; color: white; background: #23b7e5; font-size: 13px; border-color: #23b7e5; border-radius:2px; padding: 0px; "> 

    <label class="control-label" style="border: thin red solid; margin-top: 10px;">Here to find location</label>

I want button and text box in the same line which i got but i am not getting text to be center of button. I get this output. I want "Here to find location" to be center of button.

Thank You. Any help would be grateful.


回答1:


display: inline-block and vertical-align:middle will do the trick.

input, label{
  display: inline-block;
  vertical-align: middle;
  margin: 10px 0;
}
<input type="button" class="click" id="click" value="Click" style="width: 45px; height: 20px; text-align: center; color: white; background: #23b7e5; font-size: 13px; border-color: #23b7e5; border-radius:2px; padding: 0px; "> 

    <label class="control-label" style="border: thin red solid;">Here to find location</label>



回答2:


Try It Once

<button>Click</button><input type="text" value =" Here The Location"/>



回答3:


You have given margin-top:1.5%; to input and margin-top:10px to label, you should use same margin value for both

input{
  float:left;
  width: 45px;
  margin-top:10px; 
  height: 20px; 
  text-align: center; 
  color: white;
  background: #23b7e5; 
  font-size: 13px; 
  border-color: #23b7e5;
  border-radius:2px; 
  padding: 0px; 
  }
.control-label{
  float:left;
  border: thin red solid; 
  margin-top: 10px;
}
<input type="button" class="click" id="click" value="Click" style=""> 

    <label class="control-label" style="">Here to find location</label>


来源:https://stackoverflow.com/questions/38889121/give-button-and-text-on-the-same-line-and-text-to-be-center-of-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!