【发布时间】:2015-06-23 15:41:05
【问题描述】:
我正在尝试用类似这样的渐变线替换引导程序 <hr />。
到目前为止,我已经尝试过使用这个 mixin:
.horizontal-gradient (@startColor: #eee, @endColor: white) {
background-color: @startColor;
background-image: -webkit-gradient(linear, left top, right top, from(@startColor), to(@endColor));
background-image: -webkit-linear-gradient(left, @startColor, @endColor);
background-image: -moz-linear-gradient(left, @startColor, @endColor);
background-image: -ms-linear-gradient(left, @startColor, @endColor);
background-image: -o-linear-gradient(left, @startColor, @endColor);
}
但是……它没有用。
编辑
我决定创建一个单独的类(<hr/> 将来可能会很有用)。但是,我仍然无法让它工作......
.post-title-line {
background-color: #403a41;
background-image: -webkit-gradient(linear, left top, right top, from(#403a41), to(rgba(0, 0, 0, 0)));
background-image: -webkit-linear-gradient(left, #403a41, rgba(0, 0, 0, 0));
background-image: -moz-linear-gradient(left, #403a41, rgba(0, 0, 0, 0));
background-image: -ms-linear-gradient(left, #403a41, rgba(0, 0, 0, 0));
background-image: -o-linear-gradient(left, #403a41, rgba(0, 0, 0, 0));
width: 100%;
height: 1px;
position: relative;
}
<div class="post-title-line"></div>
【问题讨论】:
-
请详细说明没有工作,并告诉我们编译后的 CSS 输出或调用 mixin 的方式。如果使用正确,该 mixin 应该可以正常工作。
-
你究竟是如何使用这个mixin的? Mixin 不会自行生成任何 CSS。默认情况下,Bootstrap 使用最小的
hr来自常见的normalizegoody,并且它不调用任何 mixins。更重要的是它的高度为零(所以即使你将background-image设置为hr它仍然是不可见的)。 -
好的,我创建了一个单独的类,将其命名为
post-title-line,然后将width: 100%; height: 1px; position: relative;添加到它和mixin。这是css输出pastebin.com/cnMsZ7qq
标签: css less linear-gradients