简体   繁体   English

将容器中的三个元素水平对齐并垂直居中

[英]horizontally align and vertically center three elements in a container

I need to align 3 items inside Div. 我需要在Div内对齐3个项目。

Every item must be placed vertically in the center. 每个项目都必须垂直放置在中间。

  • First item 2% margin-left. 第一项左2%的利润。
  • Second item in the center and must be a textbox. 中间的第二项,必须是文本框。
  • Third item 2% margin-right. 第三项权利金为2%。

Item First and Third must fit the div(square). 第一项和第三项必须适合div(square)。

I used alignment but it didn't work. 我使用对齐方式,但是没有用。 Here there is a graphic example: 这里有一个图形示例:

在此处输入图片说明

HTML 的HTML

<div id="container">
    <div class="box" id="left"></div>
    <input type="text" name="search" placeholder="SEARCH HERE" id="searchbox">
    <div class="box" id="right"></div>  
</div><!-- end #container-->

CSS 的CSS

#container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 95%;
    height: 90px;
    background-color: orangered;
}

.box {
    height: 75px;
    width: 75px;
    background-color: lightgreen;
}

#left {
    margin-left: 2%;
}

#right {
    margin-right: 2%;
}

input {
    width: 250px;
    padding: 18px;
    font-size: 2em;
}

DEMO: http://jsfiddle.net/xptx9wxn/2/ 演示: http : //jsfiddle.net/xptx9wxn/2/

在此处输入图片说明

For more information about CSS Flexbox visit: 有关CSS Flexbox的更多信息,请访问:

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

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