I’ve now done four CSS Katas, and four times I ended up Googling “CSS first-word selector”. Of course, every time the answer was the same: not possible.
Today I made final attempt to avoid introducing non-semantic elements and use purely CSS to hack the actual movie poster together. However, it requires you to resort to some pretty hefty hacks to get things working. Take, for example, the heading for the movie stars:
In markup for this I can still rationalize grouping the two names into their own elements, but separating first name and surname feels like a bit too much. So we end up with markup like this:
1 2 3 4 |
Brad Pitt Edward Norton |
Now, without a “first-word” selector: what’s left in CSS to style first names differently from surnames? All I could think of was this dirty trick:
1 2 3 |
background: -webkit-linear-gradient(left, #cd7d38 0%,#cd7d38 19%,#ffffff 21%,#ffffff 36%,#cd7d38 37%,#cd7d38 70%,#ffffff 70%,#ffffff 100%); /* Chrome10+,Safari5.1+ */ -webkit-background-clip: text; -webkit-text-fill-color: transparent; |
This creates a linear gradient left-to-right, with stops at oppropriate horizontal positions: exactly between words. After that, it sets the text to clip out that background, so that you can only see the background where there’s also text. Oh, obviously this will only work in webkit browsers (and will look pretty awful in others.
Other parts of this poster were less interesting. The soap bar is mostly an excercise in text-shadow, line-height, letter-spacing, and some rotation. In any case, this is the end result, compared to the original:
The code for this result can be found on cssdesk, and is as follows:
1 2 3 4 5 6 7 8 |
Brad Pitt Edward Norton A David Fincher FilmFight Club |
And this CSS:
1 2 3 4 5 6 7 8 9 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 |
.poster { position: relative; height: 500px; width: 340px; background-color: black; color: white; font-style: italic; text-transform:uppercase; font-family: Arial Narrow; background-image: url('http://blog.jeroenheijmans.nl/wp-content/uploads/fight-club-bg.jpg'); } h1 { position: absolute; left: 20px; top: 60px; background-color: #E02FFB; width: 150px; height: 70px; padding: 10px 10px 5px 0px; color: #ED9AFF; font-weight: bold; font-size: 50px; line-height: 0.58em; text-shadow: 0px 3px #660035, 1px 1px #660035, -1px 0 #F0DEF8; text-align: center; letter-spacing: -2px; text-indent: 20px; -webkit-transform: rotate(10deg); border-radius: 5px; border-right: 5px solid #660035; border-bottom: 3px solid #660035; border-top: 10px solid #ED9AFF; } h1:first-line { font-size: 35px; border: 1px solid red; letter-spacing: 2px; text-shadow: 2px 1px #660035, 1px 1px #660035, -1px -1px #F0DEF8; } h2 { position: absolute; right: 50px; top: 20px; font-size: 16px; background: #cd7d38; /* Old browsers */ background: -webkit-linear-gradient(left, #cd7d38 0%,#cd7d38 19%,#ffffff 21%,#ffffff 36%,#cd7d38 37%,#cd7d38 70%,#ffffff 70%,#ffffff 100%); /* Chrome10+,Safari5.1+ */ -webkit-background-clip: text; -webkit-text-fill-color: transparent; } h3 { position: absolute; right: 52px; top: 38px; font-size: 11px; font-weight: bold; color: #C00; } |
Next time: Lord of the Rings. Probably with full-markup-cheats turned on!