search

Home  >  Q&A  >  body text

css - 一条线两边有短线的样式表怎么写?

图片的蓝线我想到的是单独用p写。

<p>abacedfg</p>
<p class="蓝线"></p>

我想直接在<p>abacedfg</p>这个p直接画出这样的线,这样少了一个p标签了。不知道css有没有技巧能画出这样两边有短线。

PHPzPHPz2863 days ago814

reply all(7)I'll reply

  • 怪我咯

    怪我咯2017-04-17 11:19:44

    Go directly to the answer, one <p> can do it:

    http://jsfiddle.net/2drzmzkh/

    uses a pseudo element ::before.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:19:44

    Use two pseudo-elements for absolute positioning. .

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:19:44

    What the person above said is correct. I would like to add a little point here: use p pseudo-elements: before and :after, and then absolutely position them on both sides. IE7 and below are not compatible. If you need to be compatible with lower versions of IE, then Need to think about it again.

    reply
    0
  • PHPz

    PHPz2017-04-17 11:19:44

    The short lines on the left and right sides can be realized by using the left border of p, and the color of the border can be achieved by using the linear gradient of CSS3 linear-gradient, but it is not backward compatible.

    But in fact, it is better to add <p class="蓝色"></p> directly to border. Multiple ps are not a problem and the compatibility is better.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:19:44

    If it is not compatible with lower versions of IE, you can use :after, :before to control the display of the left and right borders. If it is compatible, it will be like the one above, but the blank space is meaningless. Too much

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:19:44

    border-left,border-right

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:19:44

    Don’t a box have a border, and then the top border is removed?

    cssp {
      border: 2px solid blue;
      border-top: none;
      width: 100%;
      height: 2px;
      overflow: hidden;
    }
    

    reply
    0
  • Cancelreply