Styling text to make it appear above the line (for chords above the lyrics)

前端 未结 3 1024
眼角桃花
眼角桃花 2021-02-02 17:55

I\'d like to be able to show chords above the lyrics in music using CSS. This is what I\'d really like it to look like:

C                                                 


        
3条回答
  •  青春惊慌失措
    2021-02-02 18:19

    Yeah, position: relative still reserves the space needed.

    Here is a solution that wraps a position: absolute span around the relatively positioned one, so that the space does not get reserved any more:

     
      C
     This line has a C chord, and it also has an 
     
      F
     F chord
    

    CSS:

    .chord { position: absolute
     }
    
    .chord .inner {  position: relative;
        top: -1em;}
    

    The advantage over the left approach is that this will work for any chord width (think Esus or F7.

    JSFiddle here. Tested in IE6,7,8, Chrome 6

提交回复
热议问题