简体   繁体   English

无法将某些 html 元素与纯 css 对齐?

[英]Unable to align certain html elements with pure css?

I am facing an issue in aligning html elements with a text.我在将 html 元素与文本对齐时遇到问题。 Here is my code:这是我的代码:

 <div id="app"> <input class="table" type="checkbox" style="float: left; margin-top: 5px;>"> <div style="margin-left: 25px;"> header <h2></h2> </div> <div style="margin-left: 25px;"> <input class="filter" type="checkbox" style="float: left; margin-top: 5px;"> <h3>def</h3> <select style="float: left; margin-top: 5px";> <option value="p">Place</option> <option value="t">Time</option> <option value="f">Fee</option> </select> <input class="filter" type="checkbox" style="float: left; margin-top: 5px;"> </div> </div>

As you can see, the text header is placed next to a checkbox which I am able to do.如您所见,文本header位于我能够执行的复选框旁边。 But the drop down and the checkbox should be right next to the text def .但是下拉菜单和复选框应该就在文本def旁边。 But I am unable to do the alignment.但我无法做到 alignment。

I tried using css properties like float: left and margin-left but that doesn't do anything.我尝试使用诸如float: leftmargin-left之类的 css 属性,但这无济于事。 What am I doing wrong?我究竟做错了什么?

You can use inline-block property instead of float:您可以使用 inline-block 属性而不是浮点数:

 <div style="margin-left: 25px;"> <input class="filter" type="checkbox" style="display: inline-block; margin-top: 5px;"> <h3 style="display: inline-block;">def</h3> <select style="display: inline-block; margin-top: 5px";> <option value="p">Place</option> <option value="t">Time</option> <option value="f">Fee</option> </select> <input class="filter" type="checkbox" style="display: inline-block; margin-top: 5px;"> </div>

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

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