-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Inline-block and white space in the grid #170
Comments
Instead of commenting out white-space you could try using another method by extending the grid in your application specific stylesheet like this: .grid {
letter-spacing: -0.31em;
}
/* Opera hack */
.opera:-o-prefocus,
.grid {
word-spacing: -0.43em;
}
.grid__item {
letter-spacing: normal;
word-spacing: normal;
} |
This will be in place until a more robust solution presents itself, which it so far hasn’t, so I can (with all confidence) say that this solution could well be around forever. I was always wary of the At work we regularly generate grids from loops and stuff, and you can write your loops in such a way that your comments will take out the whitespace. Also, in teams, people will know something is awry when their grid breaks, and (I would hope) and developer worth their salt will go and find a grid that does work and reverse engineer their solution based on that (or, y’know, speak to someone on the team). I’m afraid that, although inuit.css is suited to big projects where you might have a big team, it can’t take responsibility for how that team communicates any details of a project. |
Thanks guys. Both responses are helpful. @csswizardry I was hoping to be able to hold your framework accountable for our boneheaded mistakes with formatting. =) Just kidding of course. Many thanks for all the good work on the framework. Your advice rings true. I figured we'd just fix the white space issues if they arise. We can surely add the HTML formatting style to our process. And we'll definitely experiment with the extension from @kevva (thanks). |
Don’t mention it! I’m sorry there isn’t a better solution to this problem, but I guess it’s the price you gotta pay :( If a (decent) solution does pop up though, I’ll be sure to implement it :D H |
Out of curiosity, what is it that you don't like about the |
Hi, I use Inuit.css with several CMS frameworks, and this issue is causing all of them to misbehave, watching this issue with great interest for a better/alternative solution. Thank you. |
I think having to use a bad comment in order to use this grid to "inline-block"... |
@kevva I've been working with your css fix noted above, and it is testing out fine in all the major browsers. We've tested:
We're feeling pretty good about using it, but I figured I'd check in with you too see if you're seeing any issues. |
There shouldn't be any issues as far as I know. |
If this does work then I might add a |
I've been using it with no problems too. +1 for the var. |
Somehow I'd feel better about it being in the core as an option =), so +1 for the variable choice. Thanks guys. |
Coolness :D |
@csswizardry So will we see the variable soon? I am still using 4.x version so things won't break 😦 |
Can someone explain to me where the word/letter-spacing values have come from, were they just blindly copied direct from YUI? Any idea how they were derived originally? And I'd love to know if/how they can possibly work for every font on every platform? Personally I'll be dropping optional end tags as that's the only solution that's actually in the spec that doesn't require weird formatting or spurious comments. |
The hack doesn't work for me so i created a new one.
|
@s4wny, just use my solution further up. |
@kevva It didn't work for me. |
@s4wny, weird, maybe you've done something wrong? How does your code look like? |
This is a known issue with inline-block elements in general, and there's a good and simpler CSS hack: .grid__item { Chris Coyier wrote up a good summary: |
@jorgepinon As soon as you change the base font size (which lots of people will), that will break. You can apply that fix outside the framework once you've set the base font size though. |
@SamuelTurner Good point. Maybe an em value would do the trick. I'll try to test it when I get some time. |
@jorgepinon Em/percentage values would just result in Also setting For me, using commented markup is not clean at all, but only has this one caveat: Being dirty. You don't have to worry about setting a wrong rule in your CSS, because everything works the same. That doesn't apply for all the other given fixes. |
@kleinfreund actually I meant to use negative margin without setting the parent's font-size to 0. It's certainly true that changing font-families would affect the value, but for me this is a cleaner and more natural solution. I understand your point about comments, but I prefer a css solution to a visual problem. Or in this case, a css hack over an html hack. I'm just adding it as another method that some may prefer. I also work on larger apps and share code among 2 other people, which makes the choice much easier for me. Either maintain html comments on all inline-block sets in all html templates and partials, or set it (and adjust it as needed) in a single place. |
@jorgepinon I was talking about negative margin-right as one solution and font-size set to zero as another one you posted in a later comment. Didn't want to mix them up. I don't know about whether one could run into some problems using negative margin-right in this case. Is the calculated whitespace full pixels wide? Let me ask this differently: Could different rounding of decimals in browsers result in different whitespace sizes? |
@kleinfreund someone set up a useful dabblet that can be used to test all solutions: http://dabblet.com/gist/2422174 I found that -0.24em to -0.26em covers most use cases. For practical purposes, someone could go with -0.26em and lose a pixel at smaller sizes. There's no doubt that removing whitespace altogether is the safest way (even though it nags at my standardista training). But in practice, for our large-ish template library, this is a more manageable method. I'd extend the framework to include a switch, something like $use-inlineblock-margin-hack |
I created a fiddle to test and it looks like -0.28em works well for almost all sizes with font-family set to "sans-serif". For serif, it's a little better at -0.27em. I'd set it depending on the font family. http://jsfiddle.net/jorgeluis/SAd7G/ One last thing (sorry), the negative-margin hack doesn't work on IE7 or below. |
There is also a method of creating your own font with a square space. Doesn't work in IE8: |
All the attempts without the "markup hack" have problems that do outweigh the "cleanliness" of the HTML by far. And I'm not even speaking about the disadvantages custom fonts have performance wise etc. - especially on mobile with flaky connections and in comparison to some HTML "hackery". I really don't get all the contempt for the HTML comments or simple whitespace removal (apart from co-workers not liking it or oneself forgetting about it ;-)). I get that it's somewhat annoying when one writes plain old HTML, but it gets less of a problem when a template library/language is used. May it be HAML or Jinja2 or Twig or whatever. In Haml it's a simple .grid__item>
some content
.grid__item>
more content In other templating systems like Twig it can be achieved via Simplified {% set name = name | default("unnamed") %}
{% set col1 = col1 | default("col1") %}
{% set col2 = col2 | default("col2") %}
{% set col3 = col3 | default("col3") %}
<div class="{{ name }}">
<div class="{{ name }}-container">
<div class="{{ col1 }}-box">
<div class="{{ col1 }}">{% block col1 %}{% endblock %}</div>
</div><!--
--><div class="{{ col2 }}-box">
<div class="{{ col2 }}">{% block col2 %}{% endblock %}</div>
</div><!--
--><div class="{{ col3 }}-box">
<div class="{{ col3 }}">{% block col3 %}{% endblock %}</div>
</div>
</div>
</div> Usage in a Twig template: {% embed '3cols.twig' with { name: 'mywidget', col1: 'shu', col2: 'ha', col3: 'ri' } %}
{% block col1 %}
content of column 1
{% endblock %}
{% block col2 %}
{% include ['home.' ~ locale ~ '.twig', 'home.twig'] %}
{% endblock %}
{% block col3 %}
content of column 3
{% endblock %}
{% endembed %} The parameters to name the columns with class names are not necessary in this example. Source code like that could be used with the following SCSS to have a nestable grid system without ever having too much to do with the "markup hack" for designers. [class$="-container"] {
@extend %grid;
}
[class$="-box"] {
@extend %grid__item;
} Now the Just my 2 cents. Thanks for |
Don't see the problem with performance since the font only contains 2 characters and is base64 encoded. As for why not just remove whitespace – in some cases this code might be used in a premium item, so I'm just trying to make it easier to customise. |
I've just been taking .5% out of the percentages when this has caused issues. Don't shout.. :/ Removing white space is better and something I'm doing more often now that I've switched to HTML pre-processers (e.g. Jade's pretty:false option does a great job and means I don't have to think about it). Commenting has just never appealed to me, personally. Just my two pence. |
Hey, so I'm not using Inuit on any projects, but inline-block is very advantageous. I've used Django templating, which is similar to Smarty and unless you need repeatables generated from the database, inline-block need not be an issue. When you do need something like repeatables, it's often a good use case to use an unordered list (even sematically), and since you don't need to close list tags with HTML5, this can resolve some of the problems you mention.. I would personally hesitate to use CSS hacks for the whitespace issue, if it can be resolved within the markup, you can sleep peacefully at night :D |
.grid { .grid>* { ??? |
@YemSalat This is a widely known alternate approach of getting around the inline-block white space issue. All methods have their caveats, even this one. With the font-size set to zero, you need to keep the element with the The point is, it doesn't get easier with this. |
I haven't gotten to trying this yet, but how about minifying the html using https://github.com/Moveo/minimize? minimize.parse(
'<p class="paragraph" id="title">\n Some content\n </p>',
function (error, data) {
// data output: <p class="paragraph" id="title">Some content</p>
}
); |
Since the jQuery plugin jQuery.fn.removeWhitespace = function() {
textNodes = this.contents().filter(
function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
.remove();
return this;
} Usage: $('.container').removeWhitespace(); UPDATE: This is actually only good during development, assuming the prodution HTML would be minified and thus spaceless. |
hi.. i was struggling with this a bit. i wanted to make a grid of articles that are split into 2 columns. i had to nest another grid inside my main grid http://pastebin.com/kCYXa8ZA because i can't seem, to put this without the layout breaking
any suggestions much appreciated. enjoying following your work. thanks. j [update.. this doesn't solve my nesting problem but i've found you can strip white space in your .twig templates with |
See my comment above – in addition to |
I hope to raise this as a new issue for clarity sake, but my apologies upfront because I know this has been discussed all over the place related to inuit.css here and here and elsewhere.
In regards to using inline-block for the grid system, do we suspect that the solution of commenting the whitespace between grid elements is the long-term solution for inuit.css?
The commenting solution is no doubt a robust solution (or removing the whitespace altogether). No argument there and I'm thankful for the solution because using inline-block for grid elements is simply awesome.
However, the commenting solution does make our grid dependent on HTML formatting - which although semantically valid seems like it will present it's fair share of challenges when working with a team of developers and/or using the grid on repeating regions generated from a database. Basically, I'm reluctant to use the grid system with this dependency on a production site if this is the long-term solution.
Again, sorry for the redundancy. Amidst all the issue threads I can find on this topic, I'm a little confused about the short-term vs. long-term ramifications. Thanks.
The text was updated successfully, but these errors were encountered: