简体   繁体   English

CSS 文本框 alignment inside div 和图像

[英]CSS Textbox alignment inside div together with the an image

I'm trying to align a textbox inside a <div> - using the class .textbox我正在尝试对齐<div>内的textbox - 使用 class .textbox

CSS Code CSS 代码

.sec1 {
   padding-left: 20px;
   padding-right: 20px;
   display: relative;
}

.textbox {
   display: absolute;
   top: 10px;
   background-color: white;
   border-radius: 10px;
}

.subcars {
   display: inline-flex;
}

.selectcar {
   width: 80%;
}

HTML Code HTML 代码

<div class="subcars">
    <div class="sec1">
         <button class="bot"><img class="selectcar" src="Images/caradd2.png" alt="selectcar"></button>
         <br><input name="cars1" class="textbox"></input>
    </div>
</div>

The results so far is (I'm using pesticide to clarify the elements):到目前为止的结果是(我正在使用杀虫剂来澄清元素):

在此处输入图像描述

As it is possible to see, the text box is not centered inside the <div> , how can I fix it?可以看到,文本框没有在<div>内居中,我该如何解决?

As @m4n0 mentioned in the comments, relative and absolute are not invalid values for display attribute.正如@m4n0 在评论中提到的,相对和绝对不是显示属性的无效值。 So, you don't need them in your code.因此,您的代码中不需要它们。

And to center the textbox, you can add margin-left property with a value accordingly under .textbox css.为了使文本框居中,您可以在.textbox css 下添加具有相应值的margin-left属性。

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

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