How can I add opening quotation marks to every line of text using HTML and CSS?

Is it possible to display a quotation mark at the beginning of each line in a quote using HTML and CSS?

In traditional typography, quotes were often marked at every linebreak in addition to the opening and closing of the quote. I want to replicate this on an HTML website while ensuring that the quotation marks remain aligned to the left even if the lines are rearranged, such as on a smaller screen. Is there a way to achieve this?

Here is an example of what I am trying to accomplish:

(example showing multiple quotation marks aligned to the left side of a longer quote from The Life of St. Augustine)

Answer №1

Using CSS Only for Quote Effect

To my surprise, it is possible to achieve the old quote effect using only CSS.

This method involves adding a pseudo element to the block quote using :before. The pseudo element contains quote symbols stacked vertically with the help of overflow-wrap: anywhere, aligned to the left of the text to create the desired effect.

The solution adapts well to changes in container and font size, but there is room for improvement such as reducing the extra whitespace between the quote and the text.

Snippet Showcase

Feel free to run the snippet below for a visual demonstration.

h4 {
  color: blue;
  margin-bottom: 0;
}

.old-quote {
  display: inline-block;
  position: relative;
  padding-left: 0.8rem;
}

.old-quote:before {
  content: '""""""""""""""""""""""""""""""""""';/* truncated for brevity */
  /* CSS styling properties for pseudo element */
}

.old-quote:after {
  content: '"';
  width: 0.8rem;
}

/* Additional styles for French quotes */

.old-quote-fr:before {
   content: '«««««««««««««««««';/* truncated for brevity */
}

.old-quote-fr:after {
  content: "»";
}
<h4>Test I - short quote</h4>
<div class="old-quote">
Alles hat ein Ende, nur die Wurst hat zwei
</div>

<h4>Test II - long quote</h4>
<div class="old-quote old-quote-fr"> 
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...
</div>

<h4>Test III - large font quote</h4>
<div class="old-quote" style="width:50%;font-size:1.5em;"> 
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...
</div>

Answer №2

I agree with @yogi's suggested solution, but I would suggest a slight modification. Utilizing HTML-Entity-Codes can help in displaying special characters like so:

&laquo; //displays «

All you need to do is set the content to the Character-Code:

content: '&laquo;';

Answer №3

One innovative approach using pure CSS involves implementing box-decoration-break: clone along with an SVG background image to handle scenarios where text starts and ends in the middle of lines, mimicking the behavior seen in your provided text snippet.

The property box-decoration-break: clone duplicates any padding at the beginning and end of each line, while also replicating the background image on every line. By leveraging padding-left on <q> tags alongside a non-repeating background image depicting a « symbol, the desired visual effect can be achieved.

Note that for compatibility with Chromium and Safari browsers, the prefix -webkit- is required when utilizing box-decoration-break.

q {
  quotes:none;
  padding-left: 9px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 1 7 24" width="7" height="24"><text x="0" y="16">«</text></svg>');
  background-repeat: no-repeat;
}
q:after {
  content:'';
  padding-left: 9px;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 1 7 24" width="7" height="24"><text x="0" y="16">»</text></svg>');
  background-repeat: no-repeat;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <q>Pellentesque fermentum ornare venenatis. Cras vitae nisl sit amet eros ultricies accumsan tincidunt vel ex. Vivamus id mollis lectus. In ullamcorper mi id nisl faucibus, non condimentum enim egestas. Donec sodales, tellus quis eleifend tristique, sem augue feugiat lectus, a vestibulum odio sem sit amet risus.</q> Etiam faucibus augue dolor, <q>eget viverra nisi</q> luctus eget. Vivamus sed rhoncus leo. Maecenas vestibulum dui ut velit dignissim, eu auctor turpis sagittis. Donec p...
<p>Nullam efficitur ante id volutpat dictum...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for dynamically resizing a dhtmlxgrid based on various monitor screen sizes

I have incorporated a DHTMLX grid into a table layout to align them next to each other. This setup seems to be the only way I could get them to display side by side. However, I am facing an issue where the grids do not automatically adjust their size base ...

css The issue of ul and ol elements not inheriting the padding property

https://codepen.io/unique-user123/pen/abcDeFG Why is it necessary to utilize the ul, ol, and li selectors in order to remove the default 40px left padding and 16px top and bottom margin? Can't we simply use the body selector to achieve this? <hea ...

Creating an HTML list based on a hierarchical MySQL table structure

I have retrieved a hierarchical table showing different elements and their parent-child relationships as follows: id| name | parent_id | header 1 | Assets | 0 | Y 2 | Fixed Assets | 1 | Y 3 | Asset One | 2 | N 4 | ...

Choosing colors for Font Awesome icons

Is there a way to customize the color of a font awesome icon using CSS? I've tried changing the color of everything except font awesome icons with this code: ::selection{ background: #ffb7b7 !important; /* Safari */ } ::-moz-selection { back ...

Customizing the design of vuetify table header to your liking

My goal is to implement a custom style for v-data table headers using the fixHeader method. The CSS code is intended to keep the header fixed in place even when scrolling horizontally. The issue arises as the style is applied to the inner <span> ele ...

What steps can I take to minimize the flashing of this fixed navigation bar?

My fixed navigation bar fades out when scrolling down the page and reappears when scrolling up, which all works well. However, I have noticed that if I do this very quickly with short movements, around 20 times, it doesn't have enough time to complete ...

Automate website button clicks using Python and Selenium

I could really use some assistance: Currently, I have a Python/Selenium code snippet that carries out basic actions on a website to retrieve names, and it works perfectly fine. The objective: However, what I am aiming for is to automate these actions to ...

navigation bar icons alignment problem

Help with positioning an icon next to the navbar text Example Code: <ul> <li><a href="#" id="other-color" class="ui-btn ui-shadow ui-btn-icon-left ui-custom-icon ui-arrow ui-nodisc-icon">Set Filter</a></li> <li> ...

Having difficulty positioning the image on the left side

Learning CSS can be a challenge, but I recently made progress by using display flex to create a navigation bar. However, I encountered an issue where the background image for the navbar doesn't align with the left side of the screen and results in unw ...

Tips for choosing a specific cell in a table

I currently have a total of 14 cells that have been generated. Is there a way for me to individually select and manipulate a specific cell out of the 14? I am looking to make only one cell unique, while leaving the rest to be displayed as they are in the ...

When utilizing the `express.static(__dirname)` function in Node.js with Express, the visitor may be directed to an incorrect HTML page

My website consists of a login page named login.html and an index page named index.html. I want to implement authentication so that only logged in users can access the index page. I have not set up the post method on the login HTML page. Therefore, I have ...

I'm curious about the specific sequence of CSS properties order recommended by Stylelint. Where can I locate

With Stylelint's CSS order option enabled, I'm having trouble getting Visual Studio Code to display the errors. Where can I locate the declaration/property order being used? Below is a snippet of my .stylelintrc.js configuration file: module.exp ...

Example of using the CSS property white-space with break-spaces

I've been searching for an example of using css white-space: break-spaces for hours with no luck. Most tutorials only cover examples for normal, nowrap, pre, pre-wrap, pre-line. When it comes to break-spaces, the information available is limited to qu ...

Utilizing jQuery or Javascript to obtain the title of the current webpage, find a specific string within it, and then apply a class to the corresponding element

Let's imagine I start with this: <title>Banana</title> and also have some navigation set up like this: <ul id="navigation"> <li> <a href=#">Banana</a> </li> </ul> Upon loading the sit ...

Using jQuery, you can create and add an element to the page when a user clicks

Currently, my webpage contains numerous anchor tags that link to various video files, along with a single div element: <a href="http://www.example.com/example-1.mkv" class="video">1</a> <a href="http://www.example.com/example-2.mkv" class=" ...

What is the best way to align the 'Typography' component in the center?

Attempting to center it using flexbox with justify-content did not yield the desired result. I also tried replacing the Typography component with a div tag, but still no success. import {AppBar,Zoom,Toolbar,Typography,CssBaseline,useScrollTrigger,Fab,ma ...

Discover how to effortlessly unveil JSON data by clicking on data retrieved from an API

After successfully parsing data from a Tumblr API, I encountered an issue when introducing tags within the body description, which includes images and hyperlinks. The main task at hand is to create a list of blog titles where the corresponding blog descri ...

What is the method for creating a fixed position div that remains until a certain point?

Is there a way to prevent the position: fixed; property from being applied after a certain point on the screen scroll using only CSS? ...

Nested tables in CSS

Creating a Gridview with two nested Gridviews in separate cells may result in some CSS inheritance issues. Each row of the table contains these nested Gridviews, but trying to isolate their style using CssClass doesn't always work effectively. Is the ...

Creating an AngularJS directive specifically for a certain <div> tag

Recently, I began learning angularjs and came across a script to change the font size. However, this script ended up changing all <p> tags on the entire webpage. Is there a way to modify the font size of <p> tags only within the <div class=" ...