css - Bootstrap 3 : how to set 2 html div side by side in the header?

标签 css twitter-bootstrap

我知道这应该是一个需要解决的基本问题。我只是想在我的页眉中并排放置 2 个 div。

我正在使用 bootstrap 3。我也在使用这个模板 https://getbootstrap.com/examples/justified-nav/

这是我的 html-css 代码。

  <div class="masthead">
    <!-- That's what I tried. Help me to find the good css style please -->
    <div class="pull-left" style="display:inline-block; border:solid; width:30%"><p>Logo image will be placed here but look  at this div behavious !!!!!!</p></div>
    <div style="border:solid; width:70%"><p>Site title will be placed here</p></div>
    <!-- -->
    <nav>
      <ul class="nav nav-justified">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">Projects</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Downloads</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </div>

编辑:这是一个 jsfiddle https://jsfiddle.net/cw9oycq7/

最佳答案

您错误地使用了 BOOTSTRAP

这是一个有效的 JSDIFFLE

  <div class="masthead">
    <!-- That's what I tried. Help me to find the good css style please -->
    <!-- ----------------CODE CHANGED HERE -------------- -->
    <div class="row">
        <div class="col-xs-6" style="border:solid;">
            <p>Logo image will be placed here but look  at this div behaviour !!!!!!</p>
        </div>
        <div class="col-xs-6" style="border:solid">
            <p>Site title will be placed here</p>
        </div>
    <!-- -----------------CODE CHANGE END----------------- -->
    </div>
    <nav>
        <ul class="nav nav-justified">
            <li class="active">
                <a href="#">Home</a>
            </li>
            <li>
                <a href="#">Projects</a>
            </li>
            <li>
                <a href="#">Services</a>
            </li>
            <li>
                <a href="#">Downloads</a>
            </li>
            <li>
                <a href="#">About</a>
            </li>
            <li>
                <a href="#">Contact</a>
            </li>
        </ul>
    </nav>
</div>

您正在尝试通过 width 属性将宽度设置为 30%。在 Bootstrap 中,我们使用 COL- 属性来设置宽度/列大小。例如-

.col-md-4//适用于中屏
.col-sm-6//适用于小屏幕
.col-lg-2//适用于大屏幕

您可以阅读有关如何使用 Bootstrap 网格的更多信息 HERE .

此外,在使用 COL 时无需使用 pull-left 类。在大多数情况下,它会得到处理。

关于css - Bootstrap 3 : how to set 2 html div side by side in the header?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36965129/

相关文章:

css - 最小高度不适用于另一台服务器。

html - 需要 CSS 侧边栏高度来扩展内容

html - 修复 Bootstrap 菜单

jquery - Bootstrap 崩溃数据目标选择器失败

html - 使用 Bootstrap 3 如何隐藏表中的列?

html - 跨多个页面的导航栏的django最佳实践

html - 导航栏中的相邻 div 受到 div 中增加字体大小的影响

html - 如何更改表单输入的Tab键顺序

jquery - Twitter Bootstrap 比较密码验证

javascript - 如果已经选中,则在页面加载时显示 css