代码之家  ›  专栏  ›  技术社区  ›  ken4ward

将图像设置为div的右上角

  •  0
  • ken4ward  · 技术社区  · 10 年前

    我想将图像的样式设置在div的右上角,如何实现?请帮忙。 I want to style this to reflect this screenshot

    <html>
    <head>
        <style>
            .first{
                width: 200px;
                height: 200px;
                color: blue;
                border: blue;
                border-style: solid;
                border-color: blue;
                background: blue;
            }
        </style>
    </head>
    
    <body>
    <div class="first">testing this forum
    </div>
    </body>
    </html>
    
    1 回复  |  直到 10 年前
        1
  •  1
  •   Maciej A. Czyzewski HamZa    10 年前

    div {
        height: 175px;
        width: 175px;
        background: blue;
        position: relative;
        /* Additionally padding? */
    }
    
    div > img {
        height: 25px;
        width: 25px;
        position: absolute;
        top: 0px; right: 0px; 
        /* Change top < 0 and right < 0 to be outside */
    }
    <div>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque velit elit, tempus non suscipit id, pretium a mi. Aliquam erat volutpat.
      <img src="http://maciejczyzewski.me/assets/images/prints/head.jpeg" />
    </div>