简体   繁体   English

CSS边框波顿线填充

[英]CSS Border botton line padding

I am trying to add left padding to a border bottom line for a div. 我试图将左填充添加到div的边框底线。 How can I achieve this? 我该如何实现?

This is what i tried 这就是我尝试过的

When I add padding left then both text and border bottom line moves. 当我向左添加填充时,文本和边框底线都会移动。

<div class='ot'>
Black border bottom should start from 30px left    <div>

.ot{
   width:100%;
   background-color:yellow;
    border-bottom: solid;       
}

You could fudge it with some pseudo content. 您可以用一些伪内容捏造它。

http://jsfiddle.net/E7fFL/3/ http://jsfiddle.net/E7fFL/3/

div {
   width:100%;
   background-color:yellow;
   border-bottom: solid 2px;
   position: relative;
}
div:after {
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 30px;
    height: 2px;
    content: '.';
    background: yellow;
    text-indent: -999px;
}

This will work provided the height and bottom properties are the equivalent and inverse equivalent, respectively, of the border width. 只要heightbottom属性分别等于边框宽度的等效值和倒数等效值,这将起作用。

You may use a background-image and background-size. 您可以使用背景图像和背景尺寸。 DEMO (with linear gradient) 演示(线性渐变)

.ot {
    width:100%;
    background:yellow linear-gradient(to top, black, black) no-repeat 30px bottom;
    background-size: 100% 3px;
}

Or a 1 pixel image : DEMO 或1像素的图像: DEMO

.ot {
    width:100%;
    background:yellow url(http://dummyimage.com/1x1) no-repeat 30px bottom;
    background-size: 100% 3px;
}

Note , a padding:bottom average fake border heifgt might be necessary 请注意,可能需要padding:bottom底部平均假边界

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM