【发布时间】:2014-12-07 05:33:02
【问题描述】:
我有两个 div 封装在一个更大的 div 中。我认为这会使两个 div 显示在父级中,但由于某种原因,它们显示出来了。我已经尝试了我能想到的所有不同的职位类型组合,并且我尝试了 display: inline。有谁知道我如何将这两个 div 放置在其父对象中?
这是我的 css 文件:
#Buttons {
float: center;
height: 100px;
width: 900px;
#Button1 {
width: 20px;
}
#Button2 {
width: 20px;
}
}
application.html.erb
<div id="Buttons">
<div id="Button1">
<%= link_to "button1", "#", :class "btn btn-large" %>
</div>
<div id="Button2">
<%= link_to "Button2", "#", :class "btn btn-large" %>
</div>
</div>
更新:添加 inline: display 到 #Button1 和 #Button2 使它们显示在 #buttons 中:
#Buttons {
float: center;
height: 100px;
width: 900px;
#Button1 {
width: 20px;
display: inline;
}
#Button2 {
width: 20px;
display: inline;
}
}
但我将完全相同的代码添加到#SearchBar,它仍然显示在它的导航栏之外:
#SearchBar {
height: 30px;
width: 30px;
display: inline;
#p {margin: 0px;}
}
.navbar {
height: 130px;
}
这是我整个标题的 html:
<header class=navbar navbar-fixed-top navbar-inverse">
<div id="Buttons">
<div id="Button1">
<a class="btn btn-large btn-primary" href="/subjects/1">1</a>
</div>
<div id="Button2">
<a class="btn btn-large btn-primary" href="/subjects/2">2</a>
</div>
</div>
<div id= "SearchBar">
<form accept-charset="UTF-8" action="/things" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
<p id="p">
<input id="search" name="search" type="text" />
<button class="btn" type="submit"><i class="thing-search">Go</i></button>
</p>
</form> </div>
</header>
【问题讨论】:
-
只是为了检查:您的 CSS 是非标准的。你在用LESS吗?
-
我在上面给了我的红宝石。不,我没有使用 LESS。
-
@user2570380 其实我只需要添加 display: inline。但是,我在搜索栏中添加了相同的代码,但它仍然显示在其父级之外。
标签: html css user-interface frontend