简体   繁体   English

显示:内联块未正确分配空间

[英]Display:inline-block not allocating the space properly

I am using five div in my footer content with equal dividing space. 我在页脚内容中使用5个div ,且分隔空间相等。 But it is going to the next line instead of showing in one line. 但这将转到下一行而不是显示在一行中。 Check my fiddle here http://jsfiddle.net/7ZAA6/ . http://jsfiddle.net/7ZAA6/中检查我的小提琴。

HTML 的HTML

 <div class="mainFooterLinks">
<div class="divideFooter">
   <div class="fl_title">Test</div>
   <div class="fl_links">
       <ul>
          <li><a href="#">Solutions</a></li>
          <li><a href="#">Services</a></li>
          <li><a href="#">DotNetNuke</a></li>
          <li><a href="#">Web Design & Development</a></li>
          <li><a href="#">EDC</a></li>
       </ul>
   </div>
</div>
<div class="divideFooter">
   <div class="fl_title">Test Sharepoint</div>
   <div class="fl_links">
       <ul>
          <li><a href="#">Services</a></li>
          <li><a href="#">Web Parts</a></li>
          <li><a href="#">Solutions</a></li>
          <li><a href="#">SharePoint Support</a></li>
       </ul>
   </div>
</div>
<div class="divideFooter">
   <div class="fl_title">Test CRM</div>
   <div class="fl_links">
       <ul>
          <li><a href="#">Products</a></li>
          <li><a href="#">Test Support</a></li>
          <li><a href="#">Services</a></li>
          <li><a href="#">Test CRM</a></li>
       </ul>
   </div>
</div>
<div class="divideFooter">
   <div class="fl_title">Test DNN</div>
   <div class="fl_links">
       <ul>
          <li><a href="#">Website Development</a></li>
          <li><a href="#">Skins</a></li>
          <li><a href="#">Modules</a></li>
          <li><a href="#">Support & Maintenance</a></li>
          <li><a href="#">EDC</a></li>
       </ul>
   </div>
</div>
<div class="divideFooter">
   <div class="fl_title">Test K12 DRM</div>
   <div class="fl_links">
       <ul>
          <li><a href="#">What is K12DRM?</a></li>
          <li><a href="#">K12DRM Features</a></li>
       </ul>
   </div>
</div>    

CSS 的CSS

 .mainFooterLinks
 {
  max-width:1200px;
  background-color:#333;
  padding:20px 0px 20px 0px;
  margin:0px auto;
  box-sizing:border-box;
 }
 .divideFooter
 {
 display:inline-block;
 width:20%;
 vertical-align:top;
 padding:0;
margin:0;  
}
.fl_title
{
font-family:Arial;
color:#cdcdcd;
font-size:15px;
font-weight:700;
padding-left:15px;
}
.fl_links a, .fl_links a:link, .fl_links a:active, .fl_links a:visited
 {
  font-family:Arial;
  color:#636363;
font-size:12px;
font-weight:400;
text-decoration:none;
 }
 .fl_links a:hover
 {
  text-decoration:underline;
 }
 .fl_links ul
 {
 list-style-type:none;
 list-style-image:url('fbull.jpg');
 padding:7px 10px 5px 30px;
 margin:0;
 }

My Solution: If I add float:left property on divideFooter class and the bottom of the last div, adding one more div with clear:both property is working fine here. 我的解决方案:如果我在divideFooter类和最后一个div的底部添加float:left属性,则在divideFooter添加一个带有clear:both属性的div可以正常工作。

But why the inline-block not working properly? 但是为什么内联块无法正常工作? Recent time many people are told like do not use float property, use inline-block property. 最近很多人被告知不要使用float属性,而使用inline-block属性。 So that i want to know the reason what is wrong my code? 这样我想知道我的代码出了什么问题的原因?

Add font-size: 0 to your .mainFooterLinks class. font-size: 0添加到您的.mainFooterLinks类。 With inline-blocks element, whitespace is added between them 使用inline-blocks元素,在它们之间添加空格

It is because using inline-block considers line breaks as whitespace characters. 这是因为使用inline-block将换行符视为whitespace字符。 You can overcome this issue by applying font-size=0 in the parent container, like this: 您可以通过在父容器中应用font-size=0来克服此问题,如下所示:

.mainFooterLinks
{
    max-width:1200px;
    background-color:#333;
    padding:20px 0px 20px 0px;
    margin:0px auto;
    box-sizing:border-box;
    font-size: 0;
}

and then reset the font size in inner container ( .divideFooter in this case). 然后在内部容器(在这种情况下为.divideFooter中重置字体大小。

The reason it's happening is stated in the answers above.. 发生问题的原因已在上面的答案中说明。

A good solution you can use is this: 您可以使用的一个好的解决方案是:

.mainFooterLinks {
     white-space:nowrap;
}

.divideFooter {
    white-space:normal;
}

This will get everything on the same line.. after that tweak your padding's to make everything fit ;] 这将使所有内容都在同一行上。在调整完填充内容以使所有内容都合适之后;]

EXAMPLE

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

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