【问题标题】:Style an image to be at the top-right of a div将图像设置在 div 的右上角
【发布时间】:2016-07-21 12:58:31
【问题描述】:

我想将图像设置在 div 的右上角,我该如何实现?请帮忙。

<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>

【问题讨论】:

    标签: html image css styles css-position


    【解决方案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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-08
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多