css - 使用 box-shadow 创建边框

标签 css

我正在尝试使用框阴影在 2 个 html 元素周围创建边框。我不能在按钮元素上使用 box-shadow,因为 Android 的性能很差,它需要在每个内部元素上。我也不能使用 border 属性,因为在某些 Android 设备上性能又很差。正如您在 jsfiddle 上看到的那样,左右“边框”比顶部和底部粗。

下面的解决方案在 em 元素的顶部、左侧和底部以及 span 元素的顶部、右侧和底部使用了框阴影。

如何使“边框”看起来均匀?

<button class="button">
    <em></em>
   <span class="hidden" style="display: inline;">698</span>
</button>


.button {
    background: #00bdf2;
    border-color: white;
    border-width: 0.1rem;
    border-style: solid;
    float: right;
    height: 3rem;
    margin-right: 2.4rem;
    margin-top: 0.9rem;
    overflow: visible;
    padding: 0;
    position: relative;
    z-index: 101;
    border: 0;
    }

    input, button {
    border-radius: 0;
    outline: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    }


    .button em {
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 1.5rem 1.5rem;
    display: inline-block;
    float: left;
    height: 100%;
    padding: 0 1rem;
    width: 1.5rem;
    -webkit-box-shadow: inset .1rem 0 0 .1rem #000;
    -moz-box-shadow: inset 0 0 .2rem #000;
    box-shadow: inset .1rem 0 0 .1rem #000;
    }

    .button > span {
    background: #ffcd00;
    color: #444444;
    float: right;
    height: 100%;
    font-family: Arial;
    font-size: 1.4rem;
    line-height: 3rem;
    padding: 0 1rem;
    text-align: center;
    -webkit-box-shadow: inset .1rem 0 0 .1rem #000;
    -moz-box-shadow: inset 0 0 .2rem #000;
    box-shadow: inset -.1rem 0 0 .1rem #000;
    }

最佳答案

通过将 h-shadow 移动到 .1rem 和 -.1rem,您将阴影向左(或向右)推该值,因此根据设计,这将在该侧显示更多阴影。

删除该值并将其设置为 0 将解决此问题,但也会显示您试图隐藏它的一侧的阴影,因此这不会产生您想要的效果。

关于css - 使用 box-shadow 创建边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25264490/

相关文章:

html - 我可以在一个 CSS 选择器中同时使用百分比 (100%) 和像素 (-30px)

html - 消除 <ul> 中的 <li> 上的 "margin"的正确方法是什么?

javascript - 如何阻止 Flex 图像相互重叠?

html - 如何使表头固定在滚动条上?

html - 在禁用时阻止 anchor 像超链接一样运行

javascript - 有没有一种方法可以将 wordpress 上传到特定目录,以便我可以将 javascript 脚本指向它?

html - 使中央 div 倾斜且背景图像不倾斜,从而在页面中心下方创建垂直对 Angular 线效果

css - 缩放图像时禁用抗锯齿

html - div 中的 CSS 边框不适合内容的高度

html - 旋转的链接文本在 Firefox 中悬停时跳转