How to create responsive text on top of an image?

前端 未结 1 1089
我寻月下人不归
我寻月下人不归 2020-12-03 08:11

I\'m really not sure how to pose this question any other way, but I\'m trying to load text on top of an image - which appears to be a tricky task in itself, but I\'ve got it

相关标签:
1条回答
  • 2020-12-03 08:56

    Here are the changes I would make:

    • Position the span using bottom rather than top, so you always have a specific margin between the span and the bottom of the image.
    • Use a percentage-based line-height so that it will change proportionally to the font-size
    • Add some padding to the right of the span, so the text doesn't bump right up on the edge of the span

    Updated CSS:

    .herotext span {
        position:    absolute;
        bottom:      20px;
        font-family: 'museo_slab500';
        font-size:   150%;
        color:       #fff;
        padding:     0 20px;
        width:       40%;
        line-height: 150%;
        background:  rgb(0, 0, 0);
        background:  rgba(0, 0, 0, 0.7);
    }
    
    0 讨论(0)
提交回复
热议问题