Right corner ribbon on a div CSS

后端 未结 4 2193
别那么骄傲
别那么骄傲 2020-12-18 14:02

I am trying to make a corner ribbon in a div and its going everywhere I want it to look neat and nice it goes over the div and does not sit well.

4条回答
  •  一生所求
    2020-12-18 14:20

    Edit: I keep seeing people approving of my rather quick and inflexible suggestion - but if you don't know the content (length/size) of the ribbon, definitely Check out Paulie_D's solution! His is more accomodating, as the ribbon "adjusts", depending on text length inside the ribbon. I would suggest a min-width for the :before/:after pseudo-elements though, since you only get a very short block if the content is just "new", for example


    Are you really just looking for a better positioning?

    Make the ribbon longer and move it so it is positioned neatly in the corner, make sure you give the CONTAINER element overflow: hidden;

    https://jsfiddle.net/svArtist/jtwuxhcv/

    .corner-ribbon {
      width: 250px;
      background: #e43;
      position: absolute;
      top: 25px;
      left: -50px;
      text-align: center;
      line-height: 50px;
      letter-spacing: 1px;
      color: #f0f0f0;
      transform: rotate(-45deg);
      -webkit-transform: rotate(-45deg);
      overflow: hidden;
    }
    .corner-ribbon.shadow {
      box-shadow: 0 0 3px rgba(0, 0, 0, .3);
    }
    /* Different positions */
    
    .corner-ribbon.top-right {
      /* top: 18px; */
        top:30px;
      right: -70px;
      left: auto;
      transform: rotate(45deg);
      -webkit-transform: rotate(46deg);
      overflow: hidden;
    }
    .corner-ribbon.blue {
      background: #39d;
    }
    
    .large-4, html{
        height:100%;
        overflow:hidden;
        width:100%;
    }
    
    body{
        margin:0;
        padding:0;
        position:relative;
        width:100%;
    }
    Hello

提交回复
热议问题