Created
October 18, 2013 23:02
-
-
Save hucklesby/7049507 to your computer and use it in GitHub Desktop.
Fit caption to the width of any image
This file contains hidden or 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
/** | |
* Fit caption to the width of any image | |
*/ | |
.captioned-figure { | |
display: table; | |
table-layout: fixed; | |
} | |
.captioned-figure img { | |
margin-bottom: 10px; | |
border: 0; | |
} | |
.captioned-figure .figcaption { | |
display: table-caption; | |
caption-side: bottom; | |
} | |
/* Container to add padding and border around the figure */ | |
.captioned-figure-outer { | |
display: inline-block; | |
border: 1px solid #999; | |
margin-bottom: 1.5em; | |
padding: 20px; | |
background-color: white; | |
} | |
html { | |
background-color: #600; | |
} | |
.page { | |
width: 80%; | |
max-width: 50em; | |
margin: 5em auto; | |
padding: 2em; | |
border: 1px solid #500; | |
border-radius: 3px; | |
color: black; | |
background-color: #f0f0f0; | |
} |
This file contains hidden or 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
<div class="page"> | |
<h1>Fit To Width</h1> | |
<div class="captioned-figure-outer"> | |
<div class="captioned-figure"> | |
<img src="https://dl.dropboxusercontent.com/u/36859227/images/skylar.jpg" alt="Skylar's portrait" width="240" height="160"> | |
<div class="figcaption"> | |
This is a long caption of two or more lines. Increase the text size to make this wrap some more. | |
</div> | |
</div> | |
</div> | |
</div> |
This file contains hidden or 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
// alert('Hello world!'); |
This file contains hidden or 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
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this! It was exactly what I needed.