html - Extra space added to last justified inline-block element in Chrome -
i've come across slight issue appears occur in chrome (tested , ok in ie10 , ff 31).
in example provided there #message
, #link
, both set display: inline-block;
can vertically aligned middle of each other (the text in #message
vary in length greatly).
text-align: justify;
has been set on #container
ensure #message
aligned left , #link
right.
the issue @ window sizes small "space" appear right of #link
.
the problem:
what should like:
what trying achieve:
if view fiddle , can't see problem try re-sizing window.
- what causing issue in chrome?
- is there way fix without resorting using floats (i keep vertical alignment)?
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 perfect candidate using flexbox layout. can keep existing code add following lines. keep original code fallback browsers don't support flexbox. since chrome support current flexbox syntax all way version 21, should safely eliminate problem.
modified css
#container { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; } #message { flex: 1; }
you'll need vendor prefix code comprehensive browser support, since you're worried bug in chrome not strictly necessary (unprefixed support goes version 29, although version 27 still holds .54% of global market share, might throw -webkit- in on safe side).
since flexbox can little confusing use @ first, if haven't used before there overview examples @ css-tricks. don't have enough reputation points post more 2 links google "css tricks flexbox".
hope helps.
Comments
Post a Comment