我遇到了一个似乎仅在Chrome中出现的小问题(经过IE10和FF 31的测试并确定)。
在提供的示例中,将#message
和#link
都设置为,display: inline-block;
以便它们可以彼此垂直垂直对齐(中的文本#message
长度可能会大大不同)。
text-align: justify;
已设置#container
为确保#message
与左侧和#link
右侧对齐。
问题是,在某些窗口大小下,的右侧会出现一个小的“空格” #link
。
问题:
它应该是什么样的:
我实际上试图实现的目标:
If you view the fiddle and can't see the problem try re-sizing the window.
JS Fiddle:
HTML:
<div id="container">
<div id="message">Lorem 1. Ipsum dolor sit amet, consectetur adipiscing elit. Aliquam bibendum gravida tincidunt.</div>
<a id="link" href="#">OK</a>
<div id="info">Lorem 2. Ipsum dolor sit amet, consectetur adipiscing elit. Aliquam bibendum gravida tincidunt.</div>
</div>
CSS:
#container {
background-color: red;
bottom: 0;
left: 0;
margin: 10px 5%;
position: fixed;
text-align: justify;
width: 90%;
}
#message {
color: #FFFFFF;
display: inline-block;
max-width: 80%;
vertical-align: middle;
}
#link {
background-color: #FFFFFF;
color: #000000;
display: inline-block;
padding: 1em;
}
#info {
background-color: green;
color: #FFFFFF;
display: inline-block;
margin: 0;
width: 100%;
}
This case is a perfect candidate for using the flexbox layout. You can keep your existing code as is but add the following lines. This will keep your original code as a fallback for browsers which don't support flexbox. Since Chrome does support the current flexbox syntax all the way back to version 21, this should safely eliminate your problem.
Modified CSS
#container {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
#message {
flex: 1;
}
您需要为代码提供前缀以提供全面的浏览器支持,但是由于您仅担心Chrome中的错误,因此这并不是绝对必要的(无前缀支持可以追溯到版本29,尽管版本27仍占全球的.54%市场份额,因此您可以放心-webkit-)。
由于刚开始使用flexbox可能会有些混乱,因此如果您在使用CSS之前没有使用过flexbox,那么CSS-Tricks上的示例将对它进行很好的概述。我没有足够的声誉点来发布两个以上的链接,而只是Google“ css技巧flexbox”。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句