I have a bunch of images that are numbered in the caption beneath the image, as in “Fig. 1” (short for Figure), “Fig. 2”, “Fig. 3”, etc., followed by a short description on the same line. Is there a way to use CSS or tell Javascript to find these strings (the “Fig. #” only) and style them with italics and small caps? I’d rather do that than have to create a span tag for each and every one.
body {
counter-reset: figcaption;
counter-increment: 1;
}
figcaption:before {
counter-increment: figcaption;
font-variant: small-caps;
font-style: italic;
content: "Fig. " counter(figcaption) " ";
}
#gallery {
width: 360px;
height: 3600px;
float: left;
background-color: #F8F1D4;
}
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto
}
.imageBlockLeft {
padding: 10px 0px 10px 20px;
width: 150px;
float: left;
}
.imageBlockRight {
padding: 10px 20px 10px 0px;
width: 150px;
float: right;
}
.imageBlockFloatLeftClearLeft {
clear: left;
float: left;
padding: 10px 0 10px 20px;
width: 150px;
}
.imageBlockLeft p:nth-child(2n+2) {
font-family: "jaf-bernina-sans-narrow";
font-size: .8em;
line-height: 18px;
border-bottom: 1px solid black;
background-color: #F8F1D4;
}
.imageBlockRight p:nth-child(2n+2) {
font-family: "jaf-bernina-sans-narrow";
font-size: .8em;
line-height: 18px;
border-bottom: 1px solid black;
background-color: #F8F1D4;
}
.imageBlockFloatLeftClearLeft p:nth-child(2n+2) {
font-family: "jaf-bernina-sans-narrow";
font-size: .8em;
line-height: 18px;
border-bottom: 1px solid black;
background-color: #F8F1D4;
counter-increment: figcaption;
font-variant: small-caps;
font-style: italic;
content: "Fig. " counter(figcaption) " ";
}
.captionFull {
float: left;
margin: 0px 10px;
padding: 0px 20px;
font-family: "jaf-bernina-sans-narrow";
font-size: .8em;
line-height: 18px;
border-bottom: 1px solid black;
background-color: #F8F1D4;
}
.captionFull p {
padding: 0px;
margin: 0px;
}
p.centerHover {
font-family: "jaf-bernina-sans-narrow";
font-size: .9em;
line-height: 20px;
padding: 0 1em 0;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
width: 16em;
text-align: center;
}
h1 {
font-size: 1.2em;
font-variant: small-caps;
text-align: center;
padding-top: 9px;
padding-bottom: 11px;
border-top: 2px solid #E3A300 !important;
border-bottom: 2px solid #E3A300 !important;
}
/*THIS AFFECTS THE SPEED OF THE ZOOM*/
.img-zoom {
width: 150px;
-webkit-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
}
/*THIS AFFECTS THE SIZE OF THE ZOOM*/
.transition {
-webkit-transform: scale(4.5);
-moz-transform: scale(4.5);
-o-transform: scale(4.5);
transform: scale(4.5);
}
<div id="gallery">
<h1>Image Gallery</h1>
<p class="centerHover">Hover over images to enlarge.</p>
<div class="imageBlockLeft"><p><img class="img-zoom" src="_images/pg_p_lewis_robert_e.jpg" alt="lewis land warrant" width="148" height="195"></p>
<figcaption>My great-grandfather, Robert Ewing Lewis, ca. 1908.</figcaption></div>
<div class="imageBlockRight"><p><img class="img-zoom" src="_images/pg_p_lewis_gene.jpg" width="148" height="184"></p>
<figcaption>My grandfather, Eugene Barton Lewis, ca. 1926.</figcaption></div>
<div class="imageBlockFloatLeftClearLeft"><p><img class="img-zoom" src="_images/pg_p_lewis_jim.jpg" width="149" height="225"></p>
<figcaption>My father, James Edward Lewis, ca. 1959.</figcaption></div>
<div class="imageBlockRight"><p><img class="img-zoom" src="_images/pg_p_lewis_4_generations.jpg" width="143" height="104"></p>
<figcaption>Four generations: Thompson Price Lewis, Robert Ewing Lewis holding James Edward Lewis, Eugene Barton Lewis, Jan 1939.</figcaption></div>
<div class="imageBlockFloatLeftClearLeft"><p><img class="img-zoom" src="_images/pg_p_lewis_alex_17981019_ky_christian_war_1197.jpg" width="140" height="143"></p>
<figcaption>Alexander Lewis's warrant #3663 to survey 200 acres of "second rate land" on the west fork of Pond River, dated 19 Oct 1798.</figcaption></div>
<div class="imageBlockRight"><p><img class="img-zoom" src="_images/pg_p_lewis_alex_17990212_ky_christian_sur_1197.jpg" class="img-thumbnail" alt="lewis land survey" width="147" height="256"></p>
<figcaption>Alexander Lewis's survey #1197 dated 12 Feb 1799 for warrant #3663.</figcaption></div>
<div class="imageBlockLeft"><p><img class="img-zoom" src="_images/pg_p_lewis_alex_18050501_ky_christian_trn_1197.jpg" class="img-thumbnail" alt="lewis land transfer" width="146" height="256"></p>
<figcaption>Alexander Lewis transferred his survey #1197 to Benjamin P Campbell on 1 May 1805. Campbell transferred it to Smith Lofland on 13 Nov 1806.</figcaption></div>
<div class="imageBlockRight"><p><img class="img-zoom" src="_images/pg_p_lewis_alex_&_robt_18020809_ky_christian_war_14849.jpg" width="143" height="118"></p>
<figcaption>Robert Lewis's warrant #725 for 200 acres dated 9 Aug 1802.</figcaption></div>
<div class="imageBlockLeft"><p><img class="img-zoom" src="_images/pg_p_lewis_alex_&_robt_18051217_ky_christian_war_14849_obv.jpg" width="143" height="121"></p>
<figcaption>Robert Lewis transferred warrant #725 to his father on 17 Dec 1805.</figcaption></div>
<div class="imageBlockLeft"><p><img class="img-zoom" src="_images/pg_p_lewis_smith_lofland_v_heirs_1.jpg" class="img-thumbnail" alt="lewis land transfer" width="143" height="84"></p></div>
<div class="imageBlockRight"><p><img class="img-zoom" src="_images/pg_p_lewis_smith_lofland_v_heirs_2.jpg" class="img-thumbnail" alt="lewis land transfer" width="142" height="184"></p></div>
<div class="captionFull"><figcaption>Smith Lofland's suit against the heirs of Alexander Lewis.</figcaption></div>
</div>
</head>
<script src="jquery.js"></script>
<script>
//THIS IS THE JS FROM THE DEMO
$(document).ready(function(){
$('.img-zoom').hover(function() {
$(this).addClass('transition');
}, function() {
$(this).removeClass('transition');
});
});
Update
I tried using this solution provided by guest271314 and it works great. But now I have three additional questions:
The font & font-size that I selected is not working except for the last caption, Fig. 10. How can I get that to work for all the captions?
Also, I would like a period after the number in "Fig. #."
Also, how do you get your code and html to appear in their own boxes?