-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the tiny gap under replaced elements that shows by default #14
Comments
There was someone talking on Twitter a while ago about Update: This is the tweet, and the solution is to use: img { vertical-align: middle; } (That being said, I do always |
I just made a demo: https://codepen.io/jensimmons/pen/QYmmJK?editors=1100 |
I feel like
All of this does depend on the image. If it's a little icon, like the demo on the MDN page for vertical align, then After looking at this again for a while, I believe we have two choices.
or
Neither gives people their likely desired result for little inline icon images. Developers are going to need to write code for those usecases. There's simply too much variation in such moments to be able to guess what people want. To me, this is a choice between
To me, this isn't about correcting a bug, however. This is about finding a new best default. I expect that someone long ago debated whether to make images behave as (what we now call) inline or block. Maybe there was a public discussion. Maybe Marc Andreessen just decided. But if we were inventing the img element and its default CSS today, for the first time, I believe it would make more sense to set the default to block. My sense is that most of the time, images are in fact presented as a block-type object. The usecase where an image is set within a line of type — as part of that line of type — maybe we do that 10% of the time? This makes me lean towards:
|
Twitter and WordPress use inline Firefox's reader mode has problems with them as a result of it trying to blockify images, so I would heavily recommend keeping images inline. Blockifying images works pretty naturally like this already: <p>Blah blah blah…</p>
<img>
<p>Bloo bloo bloo…</p> …which seems to be the simplest thing that could possibly work, markup-wise. EDIT: I went digging and found other use-cases:
So what?While it's true that these use-cases are vastly outweighed by block images, my argument is that blockifying inline-by-default images is easy and just works by inserting them between two block-level elements — which happens 99% of the time naturally — but inlining block-by-default images is much more annoying and requires a class or fragile selectors. |
As I understand it, based on the original spec, the img element was meant to display inline icons and figures, much like how emoji are displayed inline today. However, this is not the "normal" use case for the img element today, nor has it been for a very long time. Imo the img element should be block level, and the developer can choose to set display:inline in the rare cases where inline images are needed. |
I'd like to suggest using As @tigt pointed out correctly, this still needs the What do you think? 🤔 And thats what a working draft of the spec mentions as "typical default" img { display: inline-block; } |
@Dangoo I’d be fine with that too, but I think |
Just to be clear, this is not a discussion about changing the CSS specification or how browsers work. It is impossible to do so. This is about CSS Remedy. If you don’t know what that is, please read the project page for this repo. |
@jensimmons I’m sorry I was unclear. I’d like to keep EDIT: I am very much in favor of adding |
Thanks everyone for the input here. It's really fun to take a deep dive into such details, and try to figure out what the 'best' way, the best 'new default' for CSS could be. I also posted this question to Twitter, where a lot of people responded. https://twitter.com/jensimmons/status/1094731679040712707 I'd been leaning towards It's not surprising we don't all agree. That's the beautiful thing about having a starter-file, each of us can fork it and make it perfect for our particular way of doing things. Or override the default, setting things back to inline. I'm going to close this issue now, I think we've uncovered all the important ideas in this conversation. |
@jensimmons Put |
@Dangoo Images are replaced elements, so |
I agree on |
I did put Fantasai makes a good point, that it's likely people will want @fantasai are all replaced elements inline by default?? So what should we include here?
SVG? Ok... lemme go look this up:
|
I would still choose a camp and go |
img,
svg,
video,
canvas,
audio,
iframe,
embed,
object {
display: block;
vertical-align: middle;
} VS Code prompts this warning: |
@web2033 Read the earlier comments - the vertical-align is there so that when people change their images to inline with an override style, the tiny gap under them is still gone by default. The rule is basically "Block by default, vertical-align middle if not block". |
Just add a comment above |
The vertical-align for replaced elements is incorrectly warned by some editors built-in linting (afaik VSCode), saying it's useless when using with block display. However, this is completely expected: jensimmons#14 I just think that the comment is a little bit confusing at first. Mentioning the property name would help!
Hey @adamwathan , I just wanted to let you know that |
It took me several hours to figure out that there is no bug in my library, just the default I believe that setting the layout of the img elements by the parent width is a bit too opinionated. It is perfect if there is an option to disable this. |
Using |
Add `vertical-align: middle` to align replaced elements more sensibly by default. (jensimmons/cssremedy#14 (comment)) This can trigger a poorly considered lint error in some tools but is included by design.
Not sure if anyone is also facing tons of warnings from using Next.js with TailwindCSS (tailwind uses preflight), but with these settings on images,
it causes images to be "responsive" based on the image's height, which can be ideal for some developers. However, Next.js has some optimisations for images built in-place and it needs images to be explicitly set a width and a height, so I'm unsure which option to follow.
Here's what I did to revert the changes for this CSS rule. (By also explicitly defining width and height on the tag) You might also want to add Relevant thread where people are also facing a similar issue: tailwindlabs/tailwindcss#506 |
* Hi @luoxiaozero, I've just noticed the same issue as described here (#190) and tracked it down to tailwindcss. In the output.css generated by it we have: ``` /* 1. Make replaced elements `display: block` by default. (jensimmons/cssremedy#14) 2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (jensimmons/cssremedy#14 (comment)) This can trigger a poorly considered lint error in some tools but is included by design. */ img, svg, video, canvas, audio, iframe, embed, object { display: block; /* 1 */ vertical-align: middle; /* 2 */ } ``` Your recent change sets the display to inline-block (983e857) and this collides with the 'vertical-align' set by tailwindcss. Changing the vertical-align property to 'top' fixes the misalignment so I think the simplest fix is to add 'vertical-align: top' to icon.css. I don't see it affecting anything else so it should be safe. * icon missaligment fix
I was just reading Tantek's original Reset stylesheet (likely the first ever).
He wrote
OMG! That's right. There were ugly blue boxes around images that have a link. Does this still happen anyplace? I don't think so. But if it does.... we should fix it. Ha.
Meanwhile, I do think images still have that little gap below them, because they are
display: inline
by default (mistake, imho), and the line height for whatever text size is added to the bottom of the box. I've spent many hours of my life trying to figure out where that gap is coming from. Until I finally remembered to always include this in my CSS:Shall we add that to Remedy? Does anyone else always do this?
The text was updated successfully, but these errors were encountered: