Code
<header>
<ul>
<li><a href="">我的首页</a></li>
<li><a href="">GitHub</a></li>
<li><a href="">about me</a></li>
<li><a href="">所有内容</a></li>
</ul>
</header>
body,ul,h1{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
a {
text-decoration: none;
}
header {
width: 1000px;
}
li {
padding: 25px;
text-align: center;
display: inline-block;
width: 200px;
}
li元素横向排列,li width:200px(200*4=800px);
左右padding为25px(25*8=200px);
总和1000px;但是实际却超过了1000px。


搞不清楚为什么两个li之间为什么不是紧挨着的
在Firefox中,1015px及以上可以一行显示...
但在Chrome中,1024px及以上时才可以做到一行显示;
我完全搞不懂了...通过Head First进行入门,但是回顾了一下,也没有任何关于这种情况的说明



It is caused by carriage return and line feed. There are many solutions. I have found the root cause. You can delete the line feed. You can change the font-size:0 of ul, then li, and write the font size you need (chrome should have the minimum font size. 12), and the margin is set to a negative value
The
<li> tag is set to display: inline-block and a newline character is added after the end tag, which will generate a blank character. This newline character is just one character. will take up position.
IE browsers above IE8 and standard browsers such as FF and chrome will produce a blank bug. Chrome displays an 8px blank bug, but other browsers display a 4px blank bug.
Method 1: Remove the blank space in the middle of </li><li> in the code
Method 2: Solve by negative margin margin-right: -4px; *margin-right: 0px; chrome cannot be solved if it is 8px (ps: I tried method 2 and it can solve chrome.). *It is ie6 or ie7. This is a parsing bug using ie
Method 3: Set the parent element font-size: 0; this cannot solve Safari, letter-spacing: -4px; (adjust the character spacing and remove it) this can solve Safari; combine the two
Method 4: Remove the </li> if the closing tag is lost (not recommended, but many compression tools can be set to remove the closing tag, which Virgos cannot tolerate);
Please set the parent element
font-size:0;
I tried it
This margin-right:-8px;
Compatible with chrome firefox IE Edge 360
In order to keep the html structure good-looking, my common approach is to set font-size: 0 on the parent element
Since you are using Li, why not use float:left. to achieve the function you want.
In addition, this is not an unknown gap, but its gap width has different widths in different browsers, so it cannot be achieved by modifying the offset. In fact, my common method is to not add closing tags to the first few. .
For example
Add a closing tag to the last tag to prevent problems.
This can perfectly solve the gap problem.
I would like to ask what the measuring tool on that page is called
This is the white space problem of inline-block
These are some whitespace characters, which are invisible, but will occupy a certain amount of
widthetc.There are many solutions
A certain method comes from http://www.w3cplus.com/css/fighting-the-space-between-inline-block-elements
For specific processing methods, you can read the article on w3cplus on how to solve the white space of inline-block elements
Owner, when you converted
块级元素to行内元素, did you ever think that空格would affect the layout?Just like
Do these three situations display the same thing?
If you really understand the example I gave you, then your problem has been solved.
Conclusion
This
未知间隙,就是空格, which is your换行符, block-level elements can ignore line breaks, but inline elements will not.Inline-block interval problem