How to ignore white spaces in between tags, CSS, PHP

I have 2 divs next to each other, with a space in between them, even though their margin is set to 0. I don't want the space to be there. The space is created by the white space in between the 2 div tags. I'm wondering if there is a way to ignore the white spaces in between tags while styling with css? Thanks.

div {
    width: 100px;
    height: 100px;
    background-color: red;
    border: 1px solid black;
    display: inline-block;
    margin: 0px;
    font-size: 0px;
}
<div></div> <div></div> 

你可以设置一个祖先的字体大小为0 ...

.parent {
    font-size: 0;
}

div {
    width: 100px;
    height: 100px;
    background-color: red;
    border: 1px solid black;
    display: inline-block;
    margin: 0px;
    font-size: 0px;
}
<span class="parent">
    <div></div> <div></div> 
</span>

Not in CSS, that I'm aware of, but you can remove the whitespace in the HTML by adding a comment between them.

<div>
</div><!--
--><div>
</div>

This works because everything inside the comment tag is ignored when the page is rendered.


Because you're using display: inline-block; which makes whitespace significant. Either get rid of the whitespace or get rid of inline display types.

You can also use floats.

div {
    width: 100px;
    height: 100px;
    background-color: red;
    border: 1px solid black;
    /*display: inline-block;*/
    margin: 0px;
    font-size: 0px;
    float: left;
}
<div></div> <div></div> 
链接地址: http://www.djcxy.com/p/89248.html

上一篇: 去除锚标签之间的空间

下一篇: 如何忽略标签,CSS和PHP之间的空白