简体   繁体   English

Webkit中的内联div对齐问题?

[英]Inline div alignment problems in Webkit?

If you check out antonpug.com 如果您查看antonpug.com

You'll notice that in Firefox and Opera, the header states Title (Search Icon) (Menu) 您会注意到,在Firefox和Opera中,标题显示标题(搜索图标)(菜单)

However in Chrome and Safari, it seems like both elements refuse to be inline and you get something like this: 但是在Chrome和Safari中,似乎这两个元素都拒绝内联,您会得到如下所示的信息:

(Search Icon) (搜索图标)
Anton Pugachevsky (Menu) 安东·普加切夫斯基(菜单)

I have been pondering this one for a while, any ideas why this might be happening? 我已经思考了一段时间,为什么会发生这种情况?

If you wish to make elements float properly in CSS you'll need to set the width of their container, or else the outer container will only gain a width of largest child element. 如果要使元素在CSS中正确浮动,则需要设置其容器的宽度,否则外部容器将仅获得最大子元素的宽度。

In your case simply set a width for .navbar-header and the elements will display inline. 在您的情况下,只需为.navbar-header设置宽度,元素将内联显示。

If you wish the search to be on the left of the title then simply add float:left to the #search-icon. 如果您希望搜索在标题的左侧,则只需将float:left添加到#search-icon即可。

For example 例如

.navbar-header{ width:50%; }

.navbar-header #search-icon{ float:left; margin-right:30px; }

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

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