<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: blockquote</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/blockquote.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2003-05-21T23:54:22+00:00</updated><author><name>Simon Willison</name></author><entry><title>Quick tip: Styling blockquotes with CSS</title><link href="https://simonwillison.net/2003/May/21/stylingBlockquotes/#atom-tag" rel="alternate"/><published>2003-05-21T23:54:22+00:00</published><updated>2003-05-21T23:54:22+00:00</updated><id>https://simonwillison.net/2003/May/21/stylingBlockquotes/#atom-tag</id><summary type="html">
    &lt;p&gt;Today's tutorial is going to be short one, as I'm working on one last piece of coursework. This time I'm going to explain a clever &lt;acronym title="Cascading Style Sheets"&gt;CSS&lt;/acronym&gt; trick borrowed from &lt;a href="http://www.frejol.org/"&gt;Nick Boalch&lt;/a&gt;. Here's a screenshot:&lt;/p&gt;

&lt;p class="img"&gt;&lt;img alt="The blockquote has large quote mark images surrounding it" height="134" src="https://static.simonwillison.net/static/2003/blockquotes.gif" width="541" /&gt;&lt;/p&gt;

&lt;p&gt;Here's the &lt;acronym title="HyperText Markup Language"&gt;HTML&lt;/acronym&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code class="html"&gt;&amp;lt;blockquote cite="http://www.w3.org/TR/REC-html40/struct/tables.html#h-11.1"&amp;gt;
&amp;lt;div&amp;gt;
Tables should not be used purely as a means to layout document content as 
this may present problems when rendering to non-visual media. 
Additionally, when used with graphics, these tables may force users to 
scroll horizontally to view a table designed on a system with a larger 
display. To minimize these problems, authors should use style sheets to 
control layout rather than tables.
&amp;lt;/div&amp;gt;
&amp;lt;/blockquote&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code class="html"&gt;&amp;lt;div&amp;gt;&lt;/code&gt; in the above code is a slight sticking point: it has no structural value but is required for the technique to work. This is a trade off between 100% structural purity and presentational effects but I think it is one that is worth making.&lt;/p&gt;

&lt;p&gt;Here's the relevant &lt;acronym title="Cascading Style Sheets"&gt;CSS&lt;/acronym&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code class="css"&gt;blockquote {
  background: transparent url(quoleft.png) left top no-repeat;
}
blockquote div {
  padding: 0 48px;
  background: transparent url(quoright.png) right bottom no-repeat;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There's a simple trick at work here. &lt;acronym title="Cascading Style Sheets"&gt;CSS&lt;/acronym&gt; backgrounds are extremely powerful but in &lt;acronym title="Cascading Style Sheets"&gt;CSS&lt;/acronym&gt;2 only one background can be applied to any single element. The blockquote effect requires two background images, one for the quote mark on the left hand side and one for the one on the right. The additional nested &lt;code class="html"&gt;&amp;lt;div&amp;gt;&lt;/code&gt; allows us to do this, by applying one background image to the &lt;code class="html"&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; and one to the &lt;code class="html"&gt;&amp;lt;div&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The padding is applied to the &lt;code class="html"&gt;&amp;lt;div&amp;gt;&lt;/code&gt; rather than the &lt;code class="html"&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; because the &lt;code class="html"&gt;&amp;lt;div&amp;gt;&lt;/code&gt; needs to stretch the entire width of the &lt;code class="html"&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; in order for the background image to appear in the right place. The images are 38 pixels wide, so a padding is applied to the left and right hand sides of the &lt;code class="html"&gt;&amp;lt;div&amp;gt;&lt;/code&gt; to allow space for the images and give an extra 10 pixels of whitespace.&lt;/p&gt;

&lt;p&gt;You can see the technique being used on &lt;a href="http://simon.incutio.com/code/css/boalch/blockquote.html" title="Funky Blockquotes"&gt;this sample page&lt;/a&gt;, or over on &lt;a href="http://www.frejol.org/"&gt;Nick's weblog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One final note: while it's tempting to add &lt;code&gt;font-style: italic&lt;/code&gt; to blockquotes, doing so may cause a &lt;a href="/2003/Apr/09/italicBlockquotesCauseScrollba/"&gt;horizontal scrollbar to appear&lt;/a&gt; in &lt;acronym title="Internet Explorer"&gt;IE&lt;/acronym&gt;6/Windows. Strange but true.&lt;/p&gt;

&lt;p&gt;Incidentally, I've been getting some absolutely fantastic feedback on this series on the comments attached to each entry - please keep it coming! The feedback has included a number of suggested improvements and other worthwhile tips. Rather than editing the original articles I plan to use tomorrow's update to revisit the previous day's articles and update them based on suggestions from the comments.&lt;/p&gt;
    
        &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/blockquote"&gt;blockquote&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/css"&gt;css&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/cssaintrocketscience"&gt;cssaintrocketscience&lt;/a&gt;&lt;/p&gt;
    

</summary><category term="blockquote"/><category term="css"/><category term="cssaintrocketscience"/></entry></feed>