html - 带有 float 元素的 div 内的垂直对齐问题

标签 html css

我正在尝试使我的 input 和 div 内的标记元素垂直居中。

我有

<div id='title-container'>
        <div id='logo'><img src='images/topLogo.png'></div>
       <div id='search'><input type='text'><a id='btn' href='#'>test button</a></div>
</div>

我想显示类似的东西

----------------------------------------------------------------------------------
|
|    ----------------------------------                             
|    |            topologic.png       |               my input box    test button                         
|    ----------------------------------                        
|________________________________________________________________________________

CSS

#title-container{ 
   height: 80px;
  width: 980px;
  background-color: yellow;
  display: table-cell;
  vertical-align: middle;
}

#logo{
  display: table-cell;
  margin: 10px;
}
#search{
  display: table-cell;
  text-align: right;
  margin: 10px;
  vertical-align: middle;
}

我想在我的标题容器 div 中垂直对齐我的输入框和测试按钮,并将这两项 float 到右侧。

上面的代码会让我明白

----------------------------------------------------------------------------------
|
|    ----------------------------------                             
|    |            topologic.png        |my input box    test button                         
|    ----------------------------------                        
|_________________________________________________________________________________

我不确定如何将我的input 框和test 按钮 float 到右侧。谁能帮我解决这个问题?谢谢!

最佳答案

 #title-container{ 
    height: 80px;
   width: 980px;
   background-color: yellow;
   display: table-cell;
   vertical-align: middle;
 }

 #logo{
   display: table-cell;
   margin: 10px;
 float:left;
 }
 #search{
   display: table-cell;
   text-align: right;
   margin: 10px;
   vertical-align: middle;
 float:right;
 }

关于html - 带有 float 元素的 div 内的垂直对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20152532/

相关文章:

html - 为什么CSS动画要产生渐变?

javascript - 如何在ajax请求后更改主体的背景图像?

html - IE 和 Edge 高度 100% bug

html - 具有固定标题的 div 表

javascript - jQuery + JSON - 如何根据相应的 JSON 字符串选择类?

html - 如何防止 Bootstrap 3 列重叠

html - 如何将固定宽度和缩小到内容相结合的存档表格单元格?

html - 标题不居中

jquery - fadeOut() 函数仅适用于第一项

javascript - Twitter Bootstrap 3.0/JQuery 1.9.1 模态渲染不正确