Maison > interface Web > tutoriel HTML > le corps du texte

inline-block 空白间距问题

WBOY
Libérer: 2016-08-10 08:49:39
original
1162 Les gens l'ont consulté

一. 问题

元素是inline-block属性时,会有空白间隙

二. 解决方案

1. html方式

1)将元素之间的空隙去除

<span style="color: #0000ff"><span style="color: #800000">div </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="space"</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="##"</span><span style="color: #0000ff">>A</span><span style="color: #0000ff"></span><span style="color: #800000">a
    </span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="##"</span><span style="color: #0000ff">><font color="#000000">B</font></span><span style="color: #0000ff"></span><span style="color: #800000">a
    </span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="##"</span><span style="color: #0000ff">><font color="#000000">C</font></span><span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></span><span style="color: #800000">div</span><span style="color: #0000ff">></span></span></span></span></span>
Copier après la connexion

2)省略闭合标签

<span style="color: #0000ff"><span style="color: #800000">div </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="space"</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="##"</span><span style="color: #0000ff">><font color="#000000">A</font></span><span style="color: #000000">
    </span><span style="color: #0000ff"><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="##"</span><span style="color: #0000ff">><font color="#000000">B</font></span><span style="color: #000000">
    </span><span style="color: #0000ff"><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="##"</span><span style="color: #0000ff">><font color="#000000">C</font></span><span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></span><span style="color: #800000">div</span><span style="color: #0000ff">></span></span></span></span></span>
Copier après la connexion

2. css方式

1. 使用margin负值(不同浏览器margin-right值可能不一样)

<span style="color: #800000">.space a </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> inline-block</span>;<span style="color: #ff0000">
    margin-right</span>:<span style="color: #0000ff"> -3px</span>;
}
Copier après la connexion

2. font-size:0(IE7会有1px的间隙)

<span style="color: #800000">.space </span>{<span style="color: #ff0000">
    font-size</span>:<span style="color: #0000ff"> 0</span>;
Copier après la connexion
}<span style="color: #800000">
.space a </span>{<span style="color: #ff0000">
    font-size</span>:<span style="color: #0000ff"> 12px</span>;
}
Copier après la connexion

3. letter-spacing负值(Opera浏览器最小间距1px,letter-spacing再小就还原了)

<span style="color: #800000">.space </span>{<span style="color: #ff0000">
    letter-spacing</span>:<span style="color: #0000ff"> -3px</span>;
}<span style="color: #800000">
.space a </span>{<span style="color: #ff0000">
    letter-spacing</span>:<span style="color: #0000ff"> 0</span>;
}
Copier après la connexion

4. word-spacing负值

<span style="color: #800000">.space </span>{<span style="color: #ff0000">
    display:inline-table;(为了兼容Chrome)</span>
Copier après la connexion
<span style="color: #ff0000">    word-spacing</span>:<span style="color: #0000ff"> -6px</span>;
}<span style="color: #800000">
.space a </span>{<span style="color: #ff0000">
    word-spacing</span>:<span style="color: #0000ff"> 0</span>;
}
Copier après la connexion

三. inline-block和baseline

https://segmentfault.com/a/1190000002668492

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal