CSS: How to insert guitar chords into the text in a space-saving manner?

I create HTML documents with song lyrics for printing. The lyrics are as large as possible. So, the more verses there are, the smaller the text.

Now I want to add chord information. This causes the line height to swell enormously, and the text no longer fits on A4:

Which CSS raises the chords while maintaining the line height? Here's what I experimented with:

 akk_c::before {  color:          red;  background:     #eee;  vertical-align: super;  font-family:    arial, sans-serif;  font-size:      80%; } akk_c::before   { content: "C"; }

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
10 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
medmonk
1 year ago

Your previous implementation is not valid and can make it easier for you to read the value of the chord in a data attribute. The respective word is then nested in a and formatted with CSS.

HTML:

Sie putzen klirrend am Geschirr...

CSS:

.chord {
  position: relative;
  margin-left: 11px;
}

.chord[data-chord]::before {
  content: attr(data-chord);
  padding: 3px 5px;
  position: absolute;
  top: -9px;
  left: -13px;
  color: red;
}

The above structure perfectly aligns the chord to the element. It doesn’t matter what you set the line-height. The chord automatically moves along as it depends on the .

You can also alienate the element for this purpose, as you like it for the purpose of incorporating icons. It would be a little shorter.

klirrend
verreisterNutzer
1 year ago
Reply to  medmonk

Perfect, you can’t explain it better.

guteantwort626
1 year ago
Reply to  medmonk

Your previous implementation is not valid

Do you think about your own definition of an HTML element? This would be valid in HTML5 if instead of an _ one – would be used, see https://www.mediaevent.de/html/custom-elements.html

medmonk
1 year ago
Reply to  guteantwort626

I know you can create your own elements. It was actually about the spelling. The same scheme applies to the data attribute.

medmonk
1 year ago

You have to take the source code as I have specified it. Make up the unnecessary chip in CSS, as well as your akk_f etc.

is the style for .cord completely ignored, what can that be?

The class is called chord (English for chord 😉 ). You must replace your “akk” with a or element and then enter the desired chord in the data attribute. Then it works.

Your HTML should look like this:

Dorfplatz 
steht(wenn der 
Maibaum wieder am 
Dorfplatz 
steht)

Your CSS:

.chord {
  position: relative;
  margin-left: 11px;
}

.chord[data-chord]::before {
  content: attr(data-chord);
  padding: 3px 5px;
  position: absolute;
  top: -9px;
  left: -13px;
  color: red;
}