gpt4 book ai didi

html - 将标题元素与左中右顺序对齐

转载 作者:行者123 更新时间:2023-11-28 04:34:12 25 4
gpt4 key购买 nike

我想在我的标题中对齐我的元素,以便它们定位,如下所示:

LOGO 搜索链接|LINK

Logo 从最左边开始,搜索在中间,链接在右边,而我希望搜索是 Logo 的 div 和 siteMeta 之间空间的最大宽度,我不想打破响应。

body {
margin: 0 auto;
}
.container {
border: 1px solid blue;
box-sizing: border-box;
padding: 0;
}
#logo {
float: left;
max-width: 220px;
}
#search {
float: left;
max-width: 300px;
margin-top: 75px;
}
#siteMeta {
float: left;
max-width: 300px;
height: 220px;
line-height: 220px;
}
<div class="container">
<div id="header">
<div id="logo">
<img src="images/logo.png" class="img-responsive">
</div>
<div id="search">
<form class="navbar-form" role="search">
<div class="input-group add-on">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
<div id="siteMeta">
<a href="#">Link</a>
<a href="#">Link</a>
</div>
</div>
</div>

最佳答案

您可以将 #header 设为表格,其子元素 table-cells 具有 width: 33%;:

body {
margin: 0 auto;
}
.container {
border: 1px solid blue;
box-sizing: border-box;
padding: 0;
}
#header {
display: table;
width: 100%;
}
#header > * {
display: table-cell;
width: 33%;
}
#logo {
}
#search {
margin-top: 75px;
text-align: center;
}
#siteMeta {
text-align: right;
height: 220px;
line-height: 220px;
}
<body>

<div class="container">
<div id="header">
<div id="logo">
<img src="images/logo.png" class="img-responsive">
</div>
<div id="search">
<form class="navbar-form" role="search">
<div class="input-group add-on">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</form>
</div>
<div id="siteMeta">
<a href="#">Link</a>
<a href="#">Link</a>
</div>

</div>

关于html - 将标题元素与左中右顺序对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41573705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com