Created
March 27, 2019 03:45
-
-
Save scottgruber/c676747f9a9e4b2c8676fc5007dc468f to your computer and use it in GitHub Desktop.
The min-content keyword gives us the width of the largest unbreakable element inside the box (i.e., the widest word or image or fixed-width box). This is exactly what we need! Now, giving our figures an appropriate width and horizontally centering them as simple is two lines of code: Fall back for older browser doesn't work unless you know exact…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
figure { | |
width: min-content; | |
margin: auto; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Some text […]</p> | |
<figure> | |
<img src="adamcatlace.jpg" /> | |
<figcaption> | |
The great Sir Adam Catlace was named after | |
Countess Ada Lovelace, the first programmer. | |
</figcaption> | |
</figure> | |
<p>More text […].</p> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Intrinsic sizing | |
*/ | |
figure { | |
max-width: 300px; | |
max-width: min-content; | |
margin: auto; | |
} | |
figure > img { max-width: inherit } | |
/* Basic styling */ | |
figure { | |
padding: 10px; | |
border: 1px solid silver; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment