如何使用侧面的线条简化此标题,以便它不需要css3背景属性?

3 html css cross-browser css3 html-heading

我有一个用于居中标题的css类,并在两侧添加垂直居中的线条.问题是,它使用css3背景属性,而不是每个浏览器都支持这些属性.所以我想简化这个以实现跨浏览器兼容性,但我不知道该怎么做.

有没有更简单的方法来实现这一点,没有css3背景(并且没有添加任何额外的元素或静态高度/宽度)?

在这里演示

.section-heading {
  display: table;
  white-space: nowrap;
}

.section-heading:before {
  background: linear-gradient(to bottom, black, black) no-repeat left center / 95% 1px;
  content: "";
  display: table-cell;
  width: 50%;
}

.section-heading:after {
  background: linear-gradient(to bottom, black, black) no-repeat right center / 95% 1px;
  content: "";
  display: table-cell;
  width: 50%;
}
Run Code Online (Sandbox Code Playgroud)

Don*_*pin 6

你可以使用fieldset和legend,它不是很漂亮的代码,但你不需要CSS3

http://jsfiddle.net/dASCv/9/

HTML

<fieldset>
    <legend>
        <h2>Example</h2>
    </legend>
</fieldset>
Run Code Online (Sandbox Code Playgroud)

CSS

fieldset {
  text-align:center;
  border:none;
  border-top:1px solid black;
}

legend{
    padding:20px;
}
Run Code Online (Sandbox Code Playgroud)

或其他方法惠特:after:before

HTML

<div>
        <h2>text TEXT</h2>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

div {
    text-align: center;
}

h2:before,
h2:after {
    border-top: 1px solid black;
    display: block;
    height: 1px;
    content: " ";
    width: 40%;
    position: absolute;
    left: 0;
    top: 1.4em;
}
h2:after {
   right: 0;  
   left: auto; 
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/dASCv/10/