使用css

时间:2015-10-09 12:29:13

标签: html css css3

考虑以下enter image description here

<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>居中对齐,而<input>应该在右侧。我怎样才能用CSS实现这个目标?

1 个答案:

答案 0 :(得分:2)

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

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>

相关问题