html - use :before and :after elements to fill remaining space of text element -


this question has answer here:

i'm trying create effect frames title tag 2 line either side fill remaining width of container. i'm trying create whatever length title text is, still same effect + amount of spacing. image better shows i'm trying explain:

enter image description here

the closest i've got using percentage widths, if small title used there lots of remaining space. add background color span object within title tag, i'm trying make effect work on varied background colors.

here's jsfiddle: https://jsfiddle.net/wv9zcuvm/ , code:

html:

<h2><span>small title</span></h2> 

css:

h2{     width:100%;     position:relative;     top:0; left: 0; }  h2:before, h2:after{     content:"";     display:inline-block;     width:30%;     height:1px;     background-color:red;     position:relative;     top: -10px; }  h2:before{     left:0; }  h2:after{     right:0; }  h2 span{     width:40%;     display:inline-block;     text-align:center; } 

can suggest how can achieve i'm trying create?

you use display:flex; without span tag

h2 {    display: flex;  }  h2:before,  h2:after {    content: '';    flex: 1;    margin: auto 1em;    height: 0;    border-top: solid red 1px;  }
<h2>small title</h2>  <h2>this long title</h2>

h2 {    display:flex;    text-align:center;    }  h2:before,  h2:after {    content:'';    flex:1;    margin:auto 1em;    height:0;    border-top:solid red 1px;    }
<h2>big long title <br/>on 2 lines ? title</h2>


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -