更改CCS功能区代码/样式

时间:2017-08-01 17:22:39

标签: css ribbon

我正在尝试使用此功能区代码(在某些生成器网站上找到) 包含链接

我觉得它看起来很不错但是它不适合我需要在那里显示的LONG文本行(PAST PRESIDENT)。

这是我第一次尝试使用CSS功能区效果......似乎无法绕过什么参数将其移动(向左侧移动)...并使其更长显示我想要显示的较长文本。

  • 它是一个右侧对齐的色带(只是为了清楚)..需要向左移动一点点...并且制作更长的'显示更长的文字。

这是我的代码:

/* CSS ribbon styles */
/* http://www.cssportal.com/css-ribbon-generator/ */

.ribbon {
  position: absolute;
  right: -5px; top: -5px;
  z-index: 1;
  overflow: hidden;
  width: 75px; height: 75px;
  text-align: right;
}
.ribbon span {
  font-size: 10px;
  font-weight: bold;
  font-size:10px;
  color: #FFF;
  text-transform: uppercase;
  text-align: center;
  line-height: 20px;
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  width: 100px;
  display: block;
  background: #79A70A;
  background: linear-gradient(#2989d8 0%, #1e5799 100%);
  box-shadow: 0 3px 10px -5px rgba(0, 0, 0, 1);
  position: absolute;
  top: 19px; right: -21px;
}
.ribbon span::before {
  content: "";
  position: absolute; left: 0px; top: 100%;
  z-index: -1;
  border-left: 3px solid #1e5799;
  border-right: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-top: 3px solid #1e5799;
}
.ribbon span::after {
  content: "";
  position: absolute; right: 0px; top: 100%;
  z-index: -1;
  border-left: 3px solid transparent;
  border-right: 3px solid #1e5799;
  border-bottom: 3px solid transparent;
  border-top: 3px solid #1e5799;
}

虽然我使用这些更新的样式使它更大..

  • 这个字体看起来有些“janky'
  • 我似乎无法调整前/后效果,因为我已经调整了其他样式。

更新:

.ribbon {
    position: absolute;
    right: -5px; top: -5px;
    z-index: 1;
    overflow: hidden;
    width: 275px; 
    height: 275px;
    text-align: right;
}

/* new bigger attempt */
.ribbon span {
    background: rgba(0, 0, 0, 0) linear-gradient(#2989d8 0%, #1e5799 100%) repeat scroll 0 0;
    box-shadow: 0 3px 10px -5px rgb(0, 0, 0);
    color: #fff;
    display: block;
    font-size: 10px;
    font-weight: bold;
    line-height: 20px;
    position: absolute;
    right: -85px;
    text-align: center;
    text-transform: uppercase;
    top: 32px;
    transform: rotate(45deg);
    width: 250px;
}

1 个答案:

答案 0 :(得分:1)

试试这个。我更新了.ribbon上的宽度/高度/顶部/左边以及.ribbon span上的顶部/右边。

.box {
  width: 200px;
  height: 200px;
  background: gainsboro;
  position: relative;
}


/* CSS ribbon styles */


/* http://www.cssportal.com/css-ribbon-generator/ */

.ribbon {
  position: absolute;
  right: -6px;
  top: -5px;
  z-index: 1;
  overflow: hidden;
  width: 115px;
  height: 115px;
  text-align: right;
}

.ribbon span {
  font-weight: bold;
  font-size: 10px;
  color: #FFF;
  text-transform: uppercase;
  text-align: center;
  line-height: 20px;
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  width: 125px;
  display: block;
  background: linear-gradient(#2989d8 0%, #1e5799 100%);
  box-shadow: 0 3px 10px -5px rgba(0, 0, 0, 1);
  position: absolute;
  top: 28px;
  right: -24px;
}

.ribbon span::before {
  content: "";
  position: absolute;
  left: 0px;
  top: 100%;
  z-index: -1;
  border-left: 3px solid #1e5799;
  border-right: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-top: 3px solid #1e5799;
}

.ribbon span::after {
  content: "";
  position: absolute;
  right: 0px;
  top: 100%;
  z-index: -1;
  border-left: 3px solid transparent;
  border-right: 3px solid #1e5799;
  border-bottom: 3px solid transparent;
  border-top: 3px solid #1e5799;
}
<div class="box">
  <div class="ribbon"><span>PAST PRESIDENT</span></div>
</div>