HTML and CSS   XSLT   JavaScript   Images   Soft   Etc  
Vladimir Tokmakov

Picture blocks with captions September 26, 2008


Task:

to create float blocks whose height and width are tied to the dimensions of a picture and its caption.

The aim here is to distribute the content as evenly as possible across available screen space (taking into account the abundance of screens and display resolutions).

In this example we will look at creating float blocks whose height is the sum of the image height in pixels and the text height in em, while width is fixed both in pixels and in em.

How it looks in the browser

Mandership. Second Edition
Mandership by Artemy Lebedev, Second Edition
Folderix
Folderix flash drive
Ptolemy's Map
Ptolemy’s Map by Herz Frank
Rigroup
Rigroup website
Day of the Dragon
Day of the Dragon by Vadim Panov
Grain Holding
Grain Holding corporate identity
01 
02 
03 
04 
05 
06 
07 
08 
09 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
<style type="text/css">
.floats
{
/* Compensating indent between float blocks so&nbsp;that they take all available space */
margin: -3em 0 0 -2em;

/* IE-specific rules */
position: relative;
display: inline-block;
clear: both;
}
.floats:after
{
content: '';
display: block;
clear: both;
}
.floats .left
{
position: relative;
float: left;

/* Removing double indents in&nbsp;IE */
display: inline;

/* Hiding everything outside of&nbsp;our constraints */
overflow: hidden;

/* Indents between float blocks */
margin: 3em 0 0 2em;

/* Setting the minimal width for picture and text */
width: 14em;
min-width: 200px;
}
.floats .left .r
{
position: absolute;
top: 0;
left: 0;
width: 100%;
}
.floats .left .min
{
/* Setting the minimal width for picture */
margin: 0 0 200px 0;

/* Setting the minimal width for text */
height: 4em;

/* Repeating the minimal width for picture for&nbsp;IE */
width: 200px;
}
</style>
<div class="floats">
    <div class="left">
        <div class="r">
            /everything/izdal/kovodstvo2/"><img src="//img.artlebedev.ru/everything/izdal/kovodstvo2/izdal-kovodstvo2-anon.jpg" alt="Mandership. Second Edition" /></a><br />
            /everything/izdal/kovodstvo2/">Mandership</a> by&nbsp;Artemy Lebedev, Second Edition
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/optosystems/"><img src="/everything/optosystems/optosystems-anon.jpg" alt="Optosystems" /></a><br />
            Optosystems /everything/optosystems/">ophthalmologic excimer laser apparatus</a>
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/folderix/"><img src="/everything/folderix/folderix-anon.jpg" alt="Folderix" /></a><br />
            /everything/folderix/">Folderix</a> flash drive
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/izdal/karta-ptolemeya/"><img src="http://www.artlebedev.ru/everything/izdal/karta-ptolemeya/izdal-karta-ptolemeya-anon.jpg" alt="Ptolemy's Map" /></a><br />
            /everything/izdal/karta-ptolemeya/">Ptolemy&rsquo;s Map</a> by&nbsp;Herz Frank
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/ancor/site2/"><img src="/everything/ancor/site2/ancor-anon.jpg" alt="Ancor 2.0" /></a><br />
            /everything/ancor/site2/">Ancor website 2.0</a>
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/rigroup/"><img src="/everything/rigroup/rigroup-anon.jpg" alt="Rigroup" /></a><br />
            /everything/rigroup/">Rigroup</a> website
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/eksmo/panov-dragon-day/"><img src="/everything/eksmo/panov-dragon-day/panov-dragon-day-anon.jpg" alt="Day of the Dragon" /></a><br />
            /everything/eksmo/panov-dragon-day/">Day of&nbsp;the Dragon</a> by&nbsp;Vadim Panov
        </div>
        <div class="min"></div>
    </div>
    <div class="left">
        <div class="r">
            /everything/grain-holding/identity/"><img src="/everything/grain-holding/identity/grain-anon.jpg" alt="Grain Holding" /></a><br />
            /everything/grain-holding/identity/">Grain Holding</a> corporate identity
        </div>
        <div class="min"></div>
    </div>
</div>

Order a design...