Stretch divider to one side but keep title centered

flexbox
css grid
flex-grow
inline-flex
flexbox wrap
flex cheat sheet css-tricks
flex order
flex-direction

Please run the example below. I'm trying to stretch the left line further to the left to compensate the parent's padding as you can see in the second example, while keeping the title centered relative to the parent like in the first example. I can't seem to have both.

(For anyone who's familiar, the divider I'm trying to tweak comes from ant-design)

#container {
  height: 100px;
  width: 400px;
  background: #EFEFEF;
  padding: 24px;
}

/* Normal use case */

.divider {
  position: relative;
  line-height: 23px;
  height: 1px;
  display: table;
  margin: 16px 0;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  text-align: center;
  background: transparent;
}

.divider::before, .divider::after {
  position: relative;
  top: 50%;
  display: table-cell;
  width: 50%;
  border-top: 1px solid #AAA;
  -webkit-transform: translateY(50%);
  -ms-transform: translateY(50%);
  transform: translateY(50%);
  content: '';
}

.divider-text {
  display: inline-block;
  padding: 0 24px;
}

/* Trying to stretch the left line to further to the left without puting the title off-center */

.divider.stretched-left {
  left: -24px;
  width: calc(100% + 24px);
  min-width: calc(100% + 24px);
}
<div id="container">
  <div class="divider">
    <span class="divider-text">Title</span>
  </div>
  <div class="divider stretched-left">
    <span class="divider-text">Title</span>
  </div>
</div>

First, I would use flexbox instead of table layout then adjust the margin/padding:

Kept only the relevant code for the demo

#container {
  width: 400px;
  background: #EFEFEF;
  padding: 24px;
}

/* Normal use case */
.divider {
  display: flex;
  margin: 16px 0;
  align-items:center;
}

.divider::before, .divider::after {
  flex:1;
  height: 1px; 
  background:#AAA;
  content: '';
}
.divider::before {
  margin-right:24px;
}
.divider::after {
  margin-left:24px;
}

.divider.stretched-left:before {
  margin-left:-24px;   
  padding-left: 24px;
}

.divider.stretched-right:after {
  margin-right:-24px;   
  padding-right: 24px;
}
<div id="container">
  <div class="divider">
    <span class="divider-text">Title</span>
  </div>
  <div class="divider stretched-left">
    <span class="divider-text">another Title</span>
  </div>
  <div class="divider stretched-right">
    <span class="divider-text">Title</span>
  </div>
  <div class="divider stretched-right">
    <span class="divider-text">another Title</span>
  </div>
  <div class="divider stretched-left stretched-right">
    <span class="divider-text">another Title</span>
  </div>
</div>

The Brotherhood of the Red Nile: America Rebuilds, He quickly accelerated and turned left in front of the car in the left lane. There is a long stretch of 495 where the Blackhawk can intercept the black car. “Keep me posted on your turns and when you are on 495 heading east. Ted then accelerated, narrowly missed a car and swerved, barely to missing the center divider. Equidistant Layout Divider: It might be specialized, but a layout divider is a tool you might find yourself reaching for once you have one handy. There's times in the shop when I have an arbitrary length to a piece and I need to split the difference.

#container {
  height: 100px;
  width: 400px;
  background: #EFEFEF;
  padding: 24px;
}

.divider {
  position: relative;
  line-height: 23px;
  height: 1px;
  display: table;
  margin: 16px 0;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  text-align: center;
  background: transparent;
  width: 100%; /* SOLUTION – this is new */
}

.divider::before, .divider::after {
  position: absolute; /* SOLUTION – this has changed */
  top: 50%;
  display: table-cell;
  width: 41%; /* SOLUTION – changed, matches desired layout best */
  border-top: 1px solid #AAA;
  -webkit-transform: translateY(50%);
  -ms-transform: translateY(50%);
  transform: translateY(50%);
  content: '';
}

.divider::before{
  left: -24px; /* SOLUTION – compensate #container padding */
  width: calc( 41% + 24px ); /* SOLUTION – add the offset to the width */
}
.divider::after{
  right: 0px; /* SOLUTION */
}

.divider-text {
  display: inline-block;
  padding: 0 24px;
}
   
<div id="container">
  <div class="divider">
    <span class="divider-text">Title</span>
  </div>
</div>

Left Half and Right Half Layout, Each side takes up exactly half of the container, creating a distinct break between one. Half of the background is set to one color and the other half another color. The benefit here is that now we have two separate containers that can hold their For instance, flex-direction: row; and align-items: stretch; is what we're after,  Keep your hips square and centered as you focus on lengthening your left side. Take 3 full breaths here, then move your block to left and hold for another 3 breaths. Continue alternating until you’ve repeated the stretch 3 times per side.

.divider.stretched-left {
    left: -24px;
    width: calc(100% + 48px);
    min-width: calc(100% + 48px);
}

Just You have to replace last css lines code with above given code.

Typical use cases of Flexbox, You can read more about the difference between flexbox and CSS This is something that may well change once Box Alignment is implemented in Block Layout. initial behaviour of flexbox, and we are aligning the item on the right by the card will stretch to the height of the grid area or flex container. Have you ever wanted to have a longer title on your detail callout and the line representing that was not long enough? This ScreenCast will show you how to take a dynamic block and stretch the line in both directions while only selecting one grip. The power of dynamic blocks revealed using the block editor and two stretch parameters.

Solution with minimum CSS, without flex, without transform.

.divider {
  position: relative;
  text-align:center;
}
.divider:before {
  content:'';
  position: absolute;
  top:50%;
  height: 1px;
  width: 100%;
  background: #000;
  left: 0;
  z-index: -1;
}
.divider span{
  padding: 0 24px;
  z-index: 1;
  background: #fff;
  display: inline-block;
}
<div class="divider">
    <span>Title</span>
 </div>

Stedman's Medical Dictionary: (1912), 1. annula'ris, 1. occurring in a spreading circle, healing in the center and spreading in patches on the face and scalp—often on each cheek with a bridge extending over the 1. vulga'ris, tuberculous lupus, see the main title. L.'s lig'​ament, a fibrous band stretching between the anterior surface of the pericardium and the  You'll need two stretch actions, one for each side of the stairway from the exact center out. don't include any part of the arrow in either stretch. Each stretch action will operate from the same point so they will stretch simultaneously in opposite directions. I know it can be done.

Vertically Center Any Content in Divi, Next, go back into your row settings and in the Custom CSS tab, add the class If you found this helpful please leave a comment and subscribe to my I am very new to this, and do not understand this part: “Now for the CSS, add With your code the images stretch vertically and are not bottom aligned. Use the bootstrap classes col-xx-# and col-xx-offset-#. So what is happening here is your screen is getting divided into 12 columns. In col-xx-#, # is the number of columns you cover and offset is the number of columns you leave.

How To Align Things In CSS, See the Pen Vertical Alignment and line-height by Rachel Andrew. the Internet tells you that vertical alignment is the hardest part of CSS, you can tell In CSS, things do not stretch in the block direction, so no extra space. (which may leave additional space in the grid container in either dimension,) and  -Text dividers can also become single line headers by adding the title in the middle.-Some text dividers look better in bold,some do not. Experiment.-Almost all text dividers only look tidy if they're centered,unless the text divider is long enough to fully stretch across the page without centering. Q & A: 1) How do I use them?

The Wood-worker, The dust and shavings from the machines are collected by two single 70-ln. fans and a belts, etc., are fitted up for machine service, is located at one side of the mill. unnecessary movements and Insuring accuracy come under that heading. To avoid mistakes and save myself useless steps, I made two 14-ft. maple  All, I am trying to stretch in three directions, I have tried using chain actions but to no avail. I have attached my attempted block, all I want to do is stretch one distance and have that stretch action work with the two chained distances to make a uniform stretch. i.e. all the distances will be that same length, but at the moment my stretch is just stretching the chain actions in the same

Comments
  • I actually thought of this solution. My only concern is that I have to overwrite a lot of styles from the antd design Divider component. At that point I should rewrite the component. Any chance for a solution that keeps the maximum original rules ? Otherwise, I'll mark this as the good answer.
  • I thought of flexbox at first too .. but tried to find a solution changing less of the original styles.
  • @TemaniAfif It works but I don't understand why. Could you please explain ?
  • @Strebler when you remove -24px from the left you will need twice this value added to width to keep the element centred. Doing this will also make the right line to touch the edge that's why I considered a gradient as border image where I will make 24px of transparent ... change the transparent with another color and you will understand the trick
  • @TemaniAfif Alright, got it. Thanks, this is the accepted answer. The website tells me to wait a few hours before giving you the bounty.
  • what is the logic behind the 41%. It doesn't work when using another text: jsfiddle.net/cj1zspev
  • for sure, but without more information this was the value that best fits. your flexbox solution is more general, I tried to change as little of the given code as possible.
  • Nop, this stretches both sides.
  • (1) you don't have transparency since you are relying on white background (2) you are not answering the question about stretching one side beyond the parent. padding