css Corner Ribbon Scss组件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css Corner Ribbon Scss组件相关的知识,希望对你有一定的参考价值。

// ----
// libsass (v3.3.6)
// Autoprefixer: last 2 version
// ----

.container{
  max-width:600px;
  height: 200px;
  display: block;
  top:100px;
  position: relative;
  margin: 0 auto;
  
  background-color: silver;
}
// ----------------------------------------------------
// LIB
// ----------------------------------------------------

$modernize: false;

/* # Corner Ribbon

Sources & Inspirations :

- <http://marketmesuite.github.io/3D-CORNER-RIBBONS/>
- <http://www.cssportal.com/css-ribbon-generator/>

.corner-ribbon-small    - Set Small Text
.corner-ribbon-large    - Set a larger text
.corner-ribbon-black    - Black
.corner-ribbon-pink     - Pink
.corner-ribbon-red      - Red


Markup:
<div class="corner-ribbon $modifierClass">
    <div class="banner">
            <div class="text">My Ribbon Text</div>
    </div>
</div>


@version -  1.0.0

Styleguide components.ui.ribbons.cornerribbons
*/

$corner-ribbon_prefix: 'corner-ribbon';
$corner-ribbon-banner-color-default: #51a351;
$corner-ribbon-text-color-default: #62c462;

.#{$corner-ribbon-prefix} {
    /*position: absolute;*/
    /*top: 0;*/
    /*right: 0;*/
}

/* reset certain elements (in case of conflicting CSS for classes, links, etc.) */
.#{$corner-ribbon-prefix} .text,
.#{$corner-ribbon-prefix} .banner,
.#{$corner-ribbon-prefix} a {
	margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}

.#{$corner-ribbon-prefix} a {
	color: #fff;
	text-decoration: none;
}



.#{$corner-ribbon-prefix} .banner {
	transform: rotate(45deg);
	//color: #fff;
	-webkit-font-smoothing: antialiased;
	display: block;
	float: right;
	position: relative;
	right: -14px;
	top: 22px;
	width: 100px;
}

.#{$corner-ribbon-prefix} .banner::after,
.#{$corner-ribbon-prefix} .banner::before {
	content: '';
	display: block;
	height: 12px;
	position: absolute;
	width: 30px;
}

.#{$corner-ribbon-prefix} .banner::before {
	transform: skewY(-45deg) translate(50%,15px);
	transform-origin: 100% center;
	left: -45px;
}

.#{$corner-ribbon-prefix} .banner::after {
	transform: translate(100%,-100%) skewY(45deg) translateX(-58%);
	transform-origin: 0 center;
	right: -17px;
}




.#{$corner-ribbon-prefix} .text {
	position: relative;
	z-index: 2;
	padding: 6px 0;
	font-size: 12px;
	font-weight: bold;
    text-align: center;
	min-height: 18px;
	line-height: 18px;
	text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.20);
	white-space: nowrap;
	text-overflow: ellipsis;
}

.#{$corner-ribbon-prefix} .text::before,
.#{$corner-ribbon-prefix} .text::after {
	content: '';
	display: block;
	height: 30px;
	position: absolute;
	top: 0;
	width: 100%;
	z-index: -1;
}

.#{$corner-ribbon-prefix} .text::before {
	transform: translateX(-15%) skewX(-45deg);
}

.#{$corner-ribbon-prefix} .text::after {
	transform: translateX(15%) skewX(45deg);
}





@if $modernize == true {
    
    .no-css-transforms .#{$corner-ribbon-prefix} {
        font-size: 1em;
        position: relative;
        width: 100%;
    }
    .no-css-transforms .#{$corner-ribbon-prefix} .banner {
        position: static;
        width: 100%;
        float: none;
        font-size: 10px;
    }
    .no-css-transforms .#{$corner-ribbon-prefix} .text {
        height: 25px;
        padding: 3px;
    }
}







@mixin corner-ribbon-small(){
    
    // Small banner
    .#{$corner-ribbon-prefix}--small .banner {
        right: -8px;
        top: 15px;
        width: 65px;
    }
    
    .#{$corner-ribbon-prefix}--small .banner::after,
    .#{$corner-ribbon-prefix}--small .banner::before {
        height: 6px;
        width: 20px;
    }
    
    .#{$corner-ribbon-prefix}--small .banner::before {
        top: -5px;
        left: -30px;
    }
    
    .#{$corner-ribbon-prefix}--small .banner::after {
        top: 18px;
        right: -12px;
    }
    
    // small text 
    .#{$corner-ribbon-prefix}--small .text {
        padding: 3px 0;
        font-size: 8px;
        min-height: 14px;
        line-height: 14px;
    }
}

@mixin corner-ribbon-large(){
    // large banner
    .#{$corner-ribbon-prefix}--large .banner {
        right: -20px;
        top: 32px;
        width: 150px;
    }
    
    .#{$corner-ribbon-prefix}--large .banner::after,
    .#{$corner-ribbon-prefix}--large .banner::before {
        height: 18px;
        width: 45px;
    }
    .#{$corner-ribbon-prefix}--large .banner::before {
    	top: 9px;
    	left: -68px;
    }
    .#{$corner-ribbon-prefix}--large .banner::after {
        top: 45px;
        right: -26px;
    }
    // large text 
    .#{$corner-ribbon-prefix}.#{$corner-ribbon-prefix}--large .text::before,
    .#{$corner-ribbon-prefix}.#{$corner-ribbon-prefix}--large .text::after {
        height: 46px;
    }
}

/*--- RIBBON COLORIZER ---*/
@mixin colorize-corner-ribbon($banner-color: $corner-ribbon-banner-color-default,
                           $text-color: $corner-ribbon-text-color-default
                          ){
    
    & .banner::after,
    & .banner::before {
        background-color: darken($banner-color, 10%);
    }
    & .text::before,
    & .text::after {
        background-color: $banner-color;
    }
    
    & .text {
      color: $text-color;
    }
    
    @if $modernize == true {
      .no-css-transforms & .text {
        background-color: $banner-color;
      }
    }
}


// ----------------------------------------------------
// USAGE
// ----------------------------------------------------


$brand-color-tertiary: pink;

.corner-ribbon--tertiary {
  @include colorize-corner-ribbon($brand-color-tertiary, white);
}
<div class="container">
  <div class="corner-ribbon corner-ribbon--tertiary">
      <div class="banner">
          <div class="text">My Ribbon Text</div>
      </div>
  </div>
</div>
.container {
  max-width: 600px;
  height: 200px;
  display: block;
  top: 100px;
  position: relative;
  margin: 0 auto;
  background-color: silver;
}

/* # Corner Ribbon

Sources & Inspirations :

- <http://marketmesuite.github.io/3D-CORNER-RIBBONS/>
- <http://www.cssportal.com/css-ribbon-generator/>

.corner-ribbon-small    - Set Small Text
.corner-ribbon-large    - Set a larger text
.corner-ribbon-black    - Black
.corner-ribbon-pink     - Pink
.corner-ribbon-red      - Red


Markup:
<div class="corner-ribbon $modifierClass">
    <div class="banner">
            <div class="text">My Ribbon Text</div>
    </div>
</div>


@version -  1.0.0

Styleguide components.ui.ribbons.cornerribbons
*/
.corner-ribbon {
  /*position: absolute;*/
  /*top: 0;*/
  /*right: 0;*/
}

/* reset certain elements (in case of conflicting CSS for classes, links, etc.) */
.corner-ribbon .text,
.corner-ribbon .banner,
.corner-ribbon a {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent;
}

.corner-ribbon a {
  color: #fff;
  text-decoration: none;
}

.corner-ribbon .banner {
  -webkit-transform: rotate(45deg);
      -ms-transform: rotate(45deg);
          transform: rotate(45deg);
  -webkit-font-smoothing: antialiased;
  display: block;
  float: right;
  position: relative;
  right: -14px;
  top: 22px;
  width: 100px;
}

.corner-ribbon .banner::after,
.corner-ribbon .banner::before {
  content: '';
  display: block;
  height: 12px;
  position: absolute;
  width: 30px;
}

.corner-ribbon .banner::before {
  -webkit-transform: skewY(-45deg) translate(50%, 15px);
      -ms-transform: skewY(-45deg) translate(50%, 15px);
          transform: skewY(-45deg) translate(50%, 15px);
  -webkit-transform-origin: 100% center;
      -ms-transform-origin: 100% center;
          transform-origin: 100% center;
  left: -45px;
}

.corner-ribbon .banner::after {
  -webkit-transform: translate(100%, -100%) skewY(45deg) translateX(-58%);
      -ms-transform: translate(100%, -100%) skewY(45deg) translateX(-58%);
          transform: translate(100%, -100%) skewY(45deg) translateX(-58%);
  -webkit-transform-origin: 0 center;
      -ms-transform-origin: 0 center;
          transform-origin: 0 center;
  right: -17px;
}

.corner-ribbon .text {
  position: relative;
  z-index: 2;
  padding: 6px 0;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  min-height: 18px;
  line-height: 18px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.corner-ribbon .text::before,
.corner-ribbon .text::after {
  content: '';
  display: block;
  height: 30px;
  position: absolute;
  top: 0;
  width: 100%;
  z-index: -1;
}

.corner-ribbon .text::before {
  -webkit-transform: translateX(-15%) skewX(-45deg);
      -ms-transform: translateX(-15%) skewX(-45deg);
          transform: translateX(-15%) skewX(-45deg);
}

.corner-ribbon .text::after {
  -webkit-transform: translateX(15%) skewX(45deg);
      -ms-transform: translateX(15%) skewX(45deg);
          transform: translateX(15%) skewX(45deg);
}

/*--- RIBBON COLORIZER ---*/
.corner-ribbon--tertiary .banner::after,
.corner-ribbon--tertiary .banner::before {
  background-color: #ff8da1;
}

.corner-ribbon--tertiary .text::before,
.corner-ribbon--tertiary .text::after {
  background-color: pink;
}

.corner-ribbon--tertiary .text {
  color: white;
}

以上是关于css Corner Ribbon Scss组件的主要内容,如果未能解决你的问题,请参考以下文章

你能在 SASS/SCSS CSS 中使用多个条件吗

如何在子组件 scss 文件中覆盖 main.component.scss 中的 css

在 React 组件中使用 css/scss 变量作为内联样式

如何将 CSS/SCSS 与 Vue 组件文件保持一致

在生成新的角度组件时无法获取 .scss 而不是 .css

什么时候应该在 Angular 中使用 styles.scss,什么时候应该使用组件的 scss