【问题标题】:drawing navigation arrow shape using css使用 css 绘制导航箭头形状
【发布时间】:2014-10-18 18:38:27
【问题描述】:

我正在尝试仅使用 css 绘制导航箭头,我编写了这段代码

<span class="outer">
   <span class="inner"></span>
</span>

搭配风格

.outer {
    width: 40px;
    height: 40px;
    border: 2px solid #000;
    border-radius: 30px;
    display: block;
    position: relative;
}
.inner {
    width: 0px;
    height: 0px;
    border-style: solid;
    border-width: 10px 15px 10px 0;
    border-color: transparent #000 transparent transparent;
    position: absolute;
    right: 35%;
    top: 24%;
}

但我希望内部三角形像这样 JSFiddle分享了我的代码

【问题讨论】:

    标签: html css draw shape css-shapes


    【解决方案1】:

    您可以使用伪元素来获得这种形状。

    唯一的缺点是您需要知道topleft 的值;它们与.inner 的大小无关。

    .outer {
        width: 40px;
        height: 40px;
        border: 2px solid #000;
        border-radius: 30px;
        display: block;
        position: relative;
    }
    .inner {
        width: 0px;
        height: 0px;
        border-style: solid;
        border-width: 10px 15px 10px 0;
        border-color: transparent #000 transparent transparent;
        position: absolute;
        right: 35%;
        top: 24%;
    }
    
    .inner:after{
        content:'';
        width: 0px;
        height: 0px;
        border-style: solid;
        border-width: 10px 15px 10px 0;
        border-color: transparent #FFF transparent transparent;
        position: absolute;
        left: 5px;
        top: -10px;    
    }
    <span class="outer">
        <span class="inner"></span>
    </span>

    这只是将相同大小的箭头放在.inner 的顶部,但轻推了几个像素。增加left 样式,使箭头“更粗”。

    【讨论】:

    • 或者只使用less than 符号&lt;...同样有效,而且是更简单的 CSS 标记。
    • @Paulie_D 我原以为这个选项不用说。特别是因为OP在问题中使用了它
    • 你会这么认为...但我的意思是在您的 content 属性中...然后您可以使用字体属性对其进行样式设置...不需要边框。
    猜你喜欢
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多