How can I make a fieldset legend-style “background line” on heading text?

前端 未结 9 1329
后悔当初
后悔当初 2020-11-29 08:31

I\'m attempting to style heading text similar to how your default legend text appears in fieldsets; that is to say, I\'d like a strikethrough-like line to come up to, but no

9条回答
  •  既然无缘
    2020-11-29 09:21

    body { padding-top: 100px; }
    
    div.parent {
        text-align: center;
        border-top: 1px solid #ccc;
    }
    
    div.parent div {
        display: inline-block;
        margin-top: -0.8em;
        padding: 0 0.5em;
        background: #fff;
    }
    
    
        
    My Text Here

    This is a fluid-width solution that matches your design and should be ok in IE7 (though I'll admit I didn't check). There are a couple of downsides:

    • You lose the fieldset/legend semantics.
    • You can't put a transparent background on the text.

    If you don't need it to be fluid-width, onteria_'s solution is probably your best bet.

提交回复
热议问题