Creating image links: wrapping <Image> with <Anchor> causes image to render full size, ignoring parent <Box>
See original GitHub issueExpected Behavior
Anchor should have no effect on sizing of children
Actual Behavior
Wrapping <Image>
with <Anchor>
causes image to render full size, ignoring parent <Box>
height and width.
URL, screen shot, or Codepen exhibiting the issue
https://codesandbox.io/s/grommet-github-issue-3186-0m2dl (see src/Image.js and https://0m2dl.codesandbox.io/image)
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Wrapping a link around an image destroys flexbox layout and ...
Wrapping a link around an image destroys flexbox layout and causes browser rendering quirks · The middle row, which I'm calling section. ·...
Read more >How to fill a box with an image without distorting it
In this guide you can learn a technique for causing an HTML image to completely fill a box.
Read more >Learn how to wrap text around objects in InDesign
Learn how to wrap text around any object, including text frames, imported images, and objects you draw in InDesign.
Read more >How To Style Figure and Image HTML Elements with CSS
This tutorial will lead you through examples of image CSS styling for web pages, allowing you to make informed decisions about how images...
Read more >float | CSS-Tricks
Ignoring the text wrap will allow the words to flow right over the image like it wasn't even there. This is the difference...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe
max-width: 100%; max-height: 100%
onstyled.img
insrc/js/components/Image/StyledImage.js
could solve the issue? Can I take this up?@markjackson02 – I looked into this and think there are a couple of options here, but my recommendation would be to move the
Anchor
so that it contains theBox
andImage
, rather than theAnchor
being placed in between theBox
andImage
.I have modified your CodeSandbox example to demonstrate: https://codesandbox.io/s/grommet-github-issue-3186-gingn?file=/src/Image.js
Explanation If we were to perform the same implementation in pure HTML/CSS, we would run into a similar issue where an
<a>
in between a<div>
and<img>
. This is because<a>
is an inline element and receives it dimensions from its contents. When the anchor is immediately wrapping the image, there is nothing (outside of the source file) setting the image’s dimension. The solution here would be similar:<a><div><img /></div></a>
.There is a newer CSS spec recommendation for
display: contents
which when applied to the anchor would achieve the desired results, but it is not production ready and still has accessibility issues: https://caniuse.com/#feat=css-display-contents & https://developer.mozilla.org/en-US/docs/Web/CSS/display@markjackson02 Can you checkout the modified CodeSandbox and confirm this alternate approach solves your needs?