繁体   English   中英

使用css水平对齐不同高度和未知宽度的元素

[英]Horizontally aligning elements of different heights and unknown widths using css

考虑以下在此处输入图片说明

<span class="title">
  <h1>This is the title</h1>
  <input type="button" class="btn"></input>
</span>

我希望<span>的宽度为 100%。 按钮只有一个图标,按钮大小为 40 x 40。现在按钮的宽度和高度是已知的,而<h1>的宽度和高度是未知的。
我希望<h1><input><span>中间垂直对齐,并在图像中水平对齐。 我希望<h1><span> <h1>居中对齐,而<input>应该在右边。 如何使用 CSS 实现这一点?

使用以下代码并根据您的需要进行修改。

 div{display:table;width:100%;border:1px solid;} span{display:table-cell;height:150px;text-align:center;vertical-align:middle;} .btn{float:right;} h1{margin:0;}
 <div> <span class="title"> <input type="button" class="btn"></input> <h1>This is the title</h1> </span> </div>

暂无
暂无

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

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