将图片设置为div的右上方

时间:2016-04-01 16:15:51

标签: html5 image css3 styles css-position

我想将图像设置为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 个答案:

答案 0 :(得分:1)

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>