简体   繁体   English

显示:内联阻止问题

[英]Display: inline-block issues

i am using display:inner-block in my code. 我在代码中使用display:inner-block。 But inline-block automatically assigns padding between divs's which is causing browser incompatibility in my site. 但是inline-block会自动在div之间分配填充,这导致浏览器在我的网站中不兼容。 Can any one point out a solution. 谁能指出一个解决方案。

Here a fiddle for basic reference.Here you can clearly see the padding assigned by inner block property 这里是一个基本参考的小提琴。在这里您可以清楚地看到内部块属性分配的填充

http://jsfiddle.net/damsarabi/vbhnF/#&togetherjs=4aiQ9gSCpq http://jsfiddle.net/damsarabi/vbhnF/#&togetherjs=4aiQ9gSCpq

This is the basic code for reference in fiddle 这是小提琴供参考的基本代码

<div class="LabelColumn">label column</div>
<div class="DataColumn">data column</div>


div{
 border:1px solid #000   
}

div.LabelColumn
{
    display: inline-block;
    vertical-align: top;
}

Regards, 问候,

inline-block doesn't automatically add margin, it is inline, which means it takes notice of your white space between each element. 内联块不会自动添加边距,而是内联,这意味着它会注意每个元素之间的空白。 Even though this might look like a 4px or so margin, it's not, it's a single space. 即使这看起来像4px左右的空白,也不是,这是一个空格。 One way to get round it would be to remove the whitespace: 解决这个问题的一种方法是删除空格:

<div class = "LabelColumn">asdfasdf</div><div class = "LabelColumn">asdfasdf</div><div class = "DataColumn">data</div><div class = "LabelColumn">asdfasdf</div><div class = "DataColumn">data</div><div class = "LabelColumn">asdfasdf</div><div class = "DataColumn">data</div>

Another, to comment out the whitespace: 另一个,将空白注释掉:

<div class = "LabelColumn">asdfasdf</div><!--
--><div class = "LabelColumn">asdfasdf</div>

JSFiddle 的jsfiddle

Or lastly, but by no means least, float:left instead of changing the display type: 最后,但并非最不重要的一点是, float:left而不是更改display类型:

JSFiddle 的jsfiddle

By default, there is an extra margin-right of 4px (according to the font-size parent). 默认情况下,有一个额外的4px边距右边(根据父字体大小)。

You can fix this issue with a css tweak. 您可以通过CSS调整来解决此问题。 It's the solution I use more often, and it's easy way to adjust this alignment. 这是我经常使用的解决方案,并且是调整此对齐方式的简便方法。

div.LabelColumn
{
    display: inline-block;
    vertical-align: top;
    margin-right: -4px;
}

You can see more tweaks on this link : http://css-tricks.com/fighting-the-space-between-inline-block-elements/ 您可以在此链接上看到更多调整: http : //css-tricks.com/fighting-the-space-between-inline-block-elements/

Also you can set font-size of container to 0 and set necessary font-size for floating elements. 您也可以将容器的font-size设置为0并为浮动元素设置必要的font-size This will eliminate spaces. 这将消除空间。 This is useful for cases when you can't avoid white-spaces between your elements (for example, some IDEs can be configured to automatically reformat markup). 这在无法避免元素之间出现空格的情况下很有用(例如,可以将某些IDE配置为自动重新格式化标记)。

div.LabelColumn
{
    font-size:16px;
    display: inline-block;
    vertical-align: top;
    text-align:left;
    border:1px solid #000;
}

.full_width {
   width:100%;
   font-size:0;
}

Demo: http://jsfiddle.net/keaukraine/htAR6/2/ 演示: http : //jsfiddle.net/keaukraine/htAR6/2/

Try this: 尝试这个:

<div class="LabelColumn">label column</div>
<div class="DataColumn">data column</div>

div.LabelColumn
{
    font-size:16px;
    display: inline-block;
    vertical-align: top;
    text-align:left;
    border:1px solid #000;
}

.full_width {
   width:100%;
   font-size:0;
}

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

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