Placing an image to the top right corner - CSS

后端 未结 3 467
野性不改
野性不改 2020-12-04 08:10

I need to display an image on the top-right corner of a div (the image is a \"diagonal\" ribbon) but keeping the current text contained in an internal div, like stuck to the

相关标签:
3条回答
  • 2020-12-04 08:34

    While looking at the same problem, I found an example

    <style type="text/css">
    #topright {
        position: absolute;
        right: 0;
        top: 0;
        display: block;
        height: 125px;
        width: 125px;
        background: url(TRbanner.gif) no-repeat;
        text-indent: -999em;
        text-decoration: none;
    }
    </style>
    
    <a id="topright" href="#" title="TopRight">Top Right Link Text</a>
    

    The trick here is to create a small, (I used GIMP) a PNG (or GIF) that has a transparent background, (and then just delete the opposite bottom corner.)

    0 讨论(0)
  • 2020-12-04 08:38

    Position the div relatively, and position the ribbon absolutely inside it. Something like:

    #content {
      position:relative;
    }
    
    .ribbon {
      position:absolute;
      top:0;
      right:0;
    }
    
    0 讨论(0)
  • 2020-12-04 08:52

    You can just do it like this:

    #content {
        position: relative;
    }
    #content img {
        position: absolute;
        top: 0px;
        right: 0px;
    }
    
    <div id="content">
        <img src="images/ribbon.png" class="ribbon"/>
        <div>some text...</div>
    </div>
    
    0 讨论(0)
提交回复
热议问题