[html] CSS technique for a horizontal line with words in the middle

Just in case anyone wants to, IMHO the best solution using CSS is by a flexbox.

Here is an example:

_x000D_
_x000D_
.kw-dvp-HorizonalButton {_x000D_
    color: #0078d7;_x000D_
    display:flex;_x000D_
    flex-wrap:nowrap;_x000D_
    align-items:center;_x000D_
}_x000D_
.kw-dvp-HorizonalButton:before, .kw-dvp-HorizonalButton:after {_x000D_
    background-color: #0078d7;_x000D_
    content: "";_x000D_
    display: inline-block;_x000D_
    float:left;_x000D_
    height:1px;_x000D_
}_x000D_
.kw-dvp-HorizonalButton:before {_x000D_
    order:1;_x000D_
    flex-grow:1;_x000D_
    margin-right:8px;_x000D_
}_x000D_
.kw-dvp-HorizonalButton:after {_x000D_
    order: 3;_x000D_
    flex-grow: 1;_x000D_
    margin-left: 8px;_x000D_
}_x000D_
.kw-dvp-HorizonalButton * {_x000D_
    order: 2;_x000D_
}
_x000D_
    <div class="kw-dvp-HorizonalButton">_x000D_
        <span>hello</span>_x000D_
    </div>
_x000D_
_x000D_
_x000D_

This should always result in a perfectly centered aligned content with a line to the left and right, with an easy to control margin between the line and your content.

It creates a line element before and after your top control and set them to order 1,3 in your flex container while setting your content as order 2 (go in the middle). giving the before/after a grow of 1 will make them consume the most vacant space equally while keeping your content centered.

Hope this helps!

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to cross-browser

Show datalist labels but submit the actual value Stupid error: Failed to load resource: net::ERR_CACHE_MISS Click to call html How to Detect Browser Back Button event - Cross Browser How can I make window.showmodaldialog work in chrome 37? Cross-browser custom styling for file upload button Flexbox and Internet Explorer 11 (display:flex in <html>?) browser sessionStorage. share between tabs? How to know whether refresh button or browser back button is clicked in Firefox CSS Custom Dropdown Select that works across all browsers IE7+ FF Webkit