How do I position one image on top of another in HTML?

前端 未结 10 1468
难免孤独
难免孤独 2020-11-22 17:15

I\'m a beginner at rails programming, attempting to show many images on a page. Some images are to lay on top of others. To make it simple, say I want a blue square, with

10条回答
  •  一生所求
    2020-11-22 17:45

    You can absolutely position pseudo elements relative to their parent element.

    This gives you two extra layers to play with for every element - so positioning one image on top of another becomes easy - with minimal and semantic markup (no empty divs etc).

    markup:

    css:

    .overlap
    {
        width: 100px;
        height: 100px;
        position: relative;
        background-color: blue;
    }
    .overlap:after
    {
        content: '';
        position: absolute;
        width: 20px;
        height: 20px;
        top: 5px;
        left: 5px;
        background-color: red;
    }
    

    Here's a LIVE DEMO

提交回复
热议问题