简体   繁体   English

如何使用浮动元素强制文本换行

[英]How to force text wrapping with floated elements

Here is an image of my problem. 这是我的问题的图片。

See how the hamburger/menu icon is pushed down to the next line? 看看如何将汉堡包/菜单图标下推到下一行? I want the text to go to the next line instead, keeping the menu button and header text next to eachother. 我希望文本转至下一行,同时保持菜单按钮和标题文本彼此相邻。 The title text and menu are floated left and right respectively. 标题文本和菜单分别在左右浮动。

This doesn't seem to be a clear problem (since I'm trying to do the opposite), and I can't think how the white space property could be used in this case. 这似乎不是一个明确的问题(因为我正试图做相反的事情),而且我不认为在这种情况下如何使用空白属性。

The only thing that works is setting a max width on the title, but that messes up the layout at some screen sizes. 唯一有效的方法是在标题上设置最大宽度,但是在某些屏幕尺寸下会弄乱布局。

I have no custom css on these elements, just what comes with Bootstrap 3 我对这些元素没有自定义的CSS,只是Bootstrap 3附带的

Markup (basically lifted straight from the new Bootstrap 3 docs): 标记(基本上从新的Bootstrap 3文档中直接删除):

<div class="navbar navbar-default">
    <div class = "navbar-header">
      <a class = "navbar-brand" href="<%= request.protocol + request.host_with_port%>/weather"> Weather </a>

  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>

  </div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
  <form id="search" class="navbar-form navbar-right form-inline" method="get" action="/weather">
    <div class="form-group">
      <input type="text" placeholder="Search for your city or zip" class="form-control" id = "searchbox" name="search">
    </div>
    <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"/></button>
  </form>
</div>

` `

Stephen, 史蒂芬

Two changes are required to get your desired result. 要获得所需的结果,需要进行两项更改。

First, set .navbar-brand padding right to 70px or what you needed. 首先,将.navbar-brand padding设置为70px或所需的值。

.navbar-brand {
    padding-right:70px; 
}

And second, make .navbar-toggle position:absolute, right:0; 其次,使.navbar-toggle position:absolute,right:0;

.navbar-toggle {
    position:absolute;
    right:0;
    top:0;
}

And you are done! 您完成了! :). :)。

Here is demo: http://jsfiddle.net/sARaY/ 这是演示: http : //jsfiddle.net/sARaY/

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

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