CSS3 Drop Caps

Tutorials

CSS3 Drop Caps tutorial. Today is design orienting article. I am going to tell you about making nice-looking drop caps with css3. I sure that you have been already saw these big letters in each children’s book of fairy tales. Especially in old books. To repeat this effect some webmasters separated this first letter (into own DOM element) and applied special own styles for it. But, this is not necessary in case of CSS3. We can use :first-letter selector to select necessary first symbol. Lets take a look to result that we can achieve

 

CSS3 Drop Caps result

Here are samples and downloadable package:

Live Demo

[sociallocker]

download in package

[/sociallocker]


Ok, download the example files and lets start coding !


Step 1. HTML

Here is basic html structure of our page:

index.html

01 <!DOCTYPE html>
02 <html lang="en" >
03     <head>
04         <meta charset="utf-8" />
05         <title>CSS3 Drop Caps | Script Tutorials</title>
06         <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen">
07     </head>
08     <body>
09         <header>
10             <h2>CSS3 Drop Caps</h2>
11             <a href="https://www.script-tutorials.com/css3-drop-caps/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a>
12         </header>
13         <div class="container">
14             <div>The King sat naked. Like a foolish pauper on the street, he sat leaning
15             against  a  cold  wall, drawing in his blue, goose-bumped legs. He shivered,
16             with his eyes closed, he listened, but everything was quiet.</div>
17             <div>He awoke at midnight from a nightmare and immediatelly understood  that
18             he  was  finished.  Some  one  weezed and writhed by the door of the bedroom
19             suite, he heard footsteps, metalic jingling and  drunken  mummbling  of  His
20             Highness,  Uncle  Buht: "Let me through... Let me.. Break it down, hell with
21             it..." Wet with icy sweat, he slintly rolled off  his  bed,  ducked  into  a
22             secter  closet,  and  loosing  himself  he ran down the underground passage.
23             Something sqelched under his bare feet, the startled rats dashed  away,  but
24             he  did  not notice anything, just now, sitting next to a wall he remembered
25             everything; the darkness, the slippery walls, and the pain from  a  blow  on
26             the  head against the shakled door to the temple, and his own unberable high
27             yelp.</div>
28             <div>They shall not enter here, he thought. No one shall enter here. Only if
29             the King  order's  so.  But  the  King  shall  not  order...  He   snickered
30             hysterically. Oh no, the King will not order! He carefully un screwed up his
31             eyes  and  saw  his  blue, hairless legs with scraped knees. Still alive, he
32             thought. I will live, because they shall not enter here.</div>
33             <div>Everything in the temple  was  blueish  from  the  cold  light  of  the
34             lanterns -- long glowing tubes that were stretched under the ceiling. In the
35             center,  God stood on an eminence, big, heavy, with sparkling dead eyes. The
36             King continuously and stupidly stared, until God was suddenly screened by  a
37             shabby  lay  brother,  still  a  greenhorn. Scraching, with an open mouth he
38             gazed at the naked King. The King squinted once again. Scum, he  thought,  a
39             lousy  vermine,  catch the mongrel and to the dogs, for them to ravage... He
40             reasoned that he did not remember the lout well, but he was  long  gone.  So
41             scrawny,   snotty...   That's  all  right,  we'll  remember.  We'll  remeber
42             everything, Your Highness, Uncle Buht. During the father's  reighn,  I  dare
43             say you sat quietly, drank a bit and kept silent, were afraid to be noticed,
44             you knew that King Prostyaga did not forget you ignoble treachery...</div>
45             <div>Great  was  the father, the King thought with an accustomed envy. You'd
46             be great, if your advisors are God's angels in flesh.  All  know,  all  have
47             seen  them:  their  faces  fearful, white, like milk, and their garment were
48             such that one could not understand if they were  naked  or  not.  And  their
49             arrows  were  fiery,  like  lightning,  they  drove  off the nomads with the
50             arrows, and although they casted them overhead, half the horde cripled  from
51             fear.  His  Highness,  Uncle  Buht,  wispered  once  upon  a time, drunk and
52             burping, that those arrows can be cast by anyone, that  special  slings  are
53             needed that the angels have and that would be nice to take from them. And he
54             said  then -- he was drunk then, -- that if it is nice to have, why not have
55             it, why not... Soon after that table talk one angel fell off the  wall  into
56             the  moat,  probably  slipped.  Next  to  him they found one of uncle's body
57             guards with a javelin between his shoulder  blades.  It  was  a  dark,  dark
58             deed...  It  good  that  the people did not care about the angels, they were
59             scary to look at, but it is not clear why is it scary -- angels were  happy,
60             cordial  people.  Only  their  eyes  were scary. Small, shiny, and they keep
61             racing around... non humanoid eyes, not peaceful. So the people hushed down,
62             although father, King Prostyaga gave them such freedom that it  is  shameful
63             to  remember...  although,  before  the  Coup, father, they say was a saddle
64             maker. For saying so, with my own hands I had torn eyes out, and sewen  ears
65             shut.  But  I remember, he used to sit in the evenings by the Crystal Tower,
66             and he would cut out leather -- beautiful work. And I would perch myself  at
67             his  side, it's warm and comfy... The angels were singing from the rooms, so
68             quietly, and in harmony, and father would start  to  accompany  --  he  knew
69             their  language  --  it  used to be spacious, nobody around... not like now,
70             guards are stuck at every corner, but there is no sense in it...</div>
71         </div>
72     </body>
73 </html>

Step 2. CSS

Here are all necessary CSS styles for achieve this effect:

css/slider.css

01 *{
02     margin:0;
03     padding:0;
04 }
05 body {
06     background-color:#eee;
07     color:#fff;
08     font:14px/1.3 Arial,sans-serif;
09 }
10 header {
11     background-color:#212121;
12     box-shadow: 0 -1px 2px #111111;
13     display:block;
14     height:70px;
15     position:relative;
16     width:100%;
17     z-index:100;
18 }
19 header h2{
20     font-size:22px;
21     font-weight:normal;
22     left:50%;
23     margin-left:-400px;
24     padding:22px 0;
25     position:absolute;
26     width:540px;
27 }
28 header a.stuts,a.stuts:visited{
29     border:none;
30     text-decoration:none;
31     color:#fcfcfc;
32     font-size:14px;
33     left:50%;
34     line-height:31px;
35     margin:23px 0 0 110px;
36     position:absolute;
37     top:0;
38 }
39 header .stuts span {
40     font-size:22px;
41     font-weight:bold;
42     margin-left:5px;
43 }
44 .container {
45     border1px dotted #000000;
46     margin0 auto;
47     overflowhidden;
48     padding20px;
49     positionrelative;
50     text-alignjustify;
51     width75%;
52 }
53 @font-face {
54     font-family: celticmd;
55     srcurl("celticmd.ttf"format("truetype");
56 }
57 .container div {
58     color#000000;
59     font-family"celticmd",Sans-Serif;
60     font-size18px;
61     line-height32px;
62     text-shadow2px 2px 2px rgba(0000.2);
63 }
64 .container div:first-letter {
65     floatleft;
66     font-size80px;
67     line-height1;
68     margin15px 5px 0 0;
69     text-transformuppercase;
70 }

First half of styles is page layout. But last three are most important. We have added custom font (celticmd.ttf) with using ‘@font-face’. First letter of each row is selected with ‘:first-letter’ selector. Each first letter of each row is increased in size, uppercase, floated left to allow it to break out of the paragraph’s flow, last – applied custom margins.


Live Demo

Conclusion

Our new tutorial is complete. Today we have learned about customization of drop cap letters. Welcome back. Good luck!

Rate article