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

前端 未结 9 1353
后悔当初
后悔当初 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:09

    Here is what I am using on a client's site: http://jsfiddle.net/TPgE4/

    Pros:

    • No images needed - renders instantly
    • Uses padding to control space on both sides of text
    • Text can be center aligned, or left/right aligned — just add, e.g., margin-left: 8px or margin-right: 8px on h2 span style definition to make it look good

    Cons:

    • Requires use of additional tag such as ... inside heading tag
    • Text must fit on one line for good appearance
    • Background color on element must match surrounding background color, so if you have a non-solid background image, gradient or pattern it won't match perfectly

提交回复
热议问题