Search code examples
htmlcssribbon

making ribbon center using css


Im creating a ribbon using css. the page it is on is FOUND HERE

I know the rest of my page needs more work but right this second I am focusing on the ribbon.

I need it to be auto 90% and center no matter what the screen size. at the moment it is cut off on the left a little and not center.

my css code:

.ribbon {
   width: 90%;
   position: absolute;
   text-align: center;
   font-size: 15px!important;
   background: #2cdb1c;
   background: -webkit-gradient(linear, left top, left bottom, from(#2cdb1c), to(#618028));
   background: -webkit-linear-gradient(top, #2cdb1c, #618028);
   background: -moz-linear-gradient(top, #2cdb1c, #618028);
   background: -ms-linear-gradient(top, #2cdb1c, #618028);
   background: -o-linear-gradient(top, #2cdb1c, #618028);
   background-image: -ms-linear-gradient(top, #2cdb1c 0%, #618028 100%);
   -webkit-box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
   -moz-box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
   box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
   font-family: 'Helvetica Neue',Helvetica, sans-serif;
   }
.ribbon h1 {
   font-size: 23px!important;
   color: #000000;
   text-shadow: #b9c9b5 0 1px 0;
   margin:0px;
   padding: 15px 10px;
   }
.ribbon:before, .ribbon:after {
   content: '';
   position: absolute;
   display: block;
   bottom: -1em;
   border: 1.5em solid #379c27;
   z-index: -1;
   }
.ribbon:before {
   left: -2em;
   border-right-width: 1.5em;
   border-left-color: transparent;
   -webkit-box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
   -moz-box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
   box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
   }
.ribbon:after {
   right: -2em;
   border-left-width: 1.5em;
   border-right-color: transparent;
   -webkit-box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
   -moz-box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
   box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
   }
.ribbon .ribbon-content:before, .ribbon .ribbon-content:after {
   border-color: #000000 transparent transparent transparent;
   position: absolute;
   display: block;
   border-style: solid;
   bottom: -1em;
   content: '';
   }
.ribbon .ribbon-content:before {
   left: 0;
   border-width: 1em 0 0 1em;
   }
.ribbon .ribbon-content:after {
   right: 0;
   border-width: 1em 1em 0 0;
   }
.ribbon-stitches-top {
   margin-top:2px;
   border-top: 1px dashed rgba(0, 0, 0, 0.2);
   -moz-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
   -webkit-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
   box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.5);
   }
.ribbon-stitches-bottom {
   margin-bottom:2px;
   border-top: 1px dashed rgba(0, 0, 0, 0.2);
   -moz-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.3);
   -webkit-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.3);
   box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.3);
   }

Can someone please help me? thank you.


Solution

  • You could actually center it based on percentage and absolutely:

    .ribbon {
        position: absolute;
        width: 90%;
        left: 50%;
        margin-left: -45%;
    }