How to repeat text using ::before and ::after

https://codepen.io/stressunfit/pen/OJdJQxq I want to achieve similar affect as this hero section of this website: https://fatfish.ca/en/. How to achieve this using ::before and ::after, cause i want to keep the main text (text in black) to be centered in any screen size.
fatfish [identity + web + strategy] | We take care of everything, f...
For nearly 15 years, fatfish has driven its clients' projects with the full power of digital. Our small, talent-packed team takes care of everything, from the initial idea to performance tracking.
No description
22 Replies
Hashir Akbar
Hashir Akbarโ€ข8mo ago
you can do this using span
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
@hashir_001 Then i would have to manually type span element many times right?. I think there is some javascript involved. cause the number of elements before and after the main element (text in black) varies based on screen size.
Hashir Akbar
Hashir Akbarโ€ข8mo ago
Before and after is not best in this case you can make a div with grid, and check the layout give each heading the column and its spanning according to the layout
Jochem
Jochemโ€ข8mo ago
I'm not sure what you want to achieve that isn't already in your codepen?
clevermissfox
clevermissfoxโ€ข8mo ago
You want the icons/illustrations to be the pseudo elements?
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
@Jochem @hart_ache I want to know how he created those lighter texts in this website hero section.: https://fatfish.ca/en/. Like the main text in black remain in center in all screen size and text besides them increase and decrease in numbers on different screen size.
fatfish [identity + web + strategy] | We take care of everything, f...
For nearly 15 years, fatfish has driven its clients' projects with the full power of digital. Our small, talent-packed team takes care of everything, from the initial idea to performance tracking.
Jochem
Jochemโ€ข8mo ago
there's a :before and :after defined like this on the h1:
.expertises-marquees__expertise-link::after, .expertises-marquees__expertise-link::before {
content: attr(data-title);
position: absolute;
top: 0;
color: transparent;
-webkit-text-stroke: .1rem var(--stroke_color);
transition: color var(--link_trans),-webkit-text-stroke 475ms cubic-bezier(.455,.03,.515,.955);
white-space: nowrap;
pointer-events: none;
z-index: -1;
}
.expertises-marquees__expertise-link::after, .expertises-marquees__expertise-link::before {
content: attr(data-title);
position: absolute;
top: 0;
color: transparent;
-webkit-text-stroke: .1rem var(--stroke_color);
transition: color var(--link_trans),-webkit-text-stroke 475ms cubic-bezier(.455,.03,.515,.955);
white-space: nowrap;
pointer-events: none;
z-index: -1;
}
<h1 class="expertises-marquees__expertise-link u-text-stroke " data-title="Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding " data-expertise="0" style=""><a class="u-text-fill u-text-fill--hover-alt" href="https://fatfish.ca/en/expertises/branding/" data-title="Branding">Branding<span class="u-text-fill__fill" style="clip-path: circle(0% at -4.46702% 48.6043%);">Branding</span></a></h1>
<h1 class="expertises-marquees__expertise-link u-text-stroke " data-title="Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding Branding " data-expertise="0" style=""><a class="u-text-fill u-text-fill--hover-alt" href="https://fatfish.ca/en/expertises/branding/" data-title="Branding">Branding<span class="u-text-fill__fill" style="clip-path: circle(0% at -4.46702% 48.6043%);">Branding</span></a></h1>
clevermissfox
clevermissfoxโ€ข8mo ago
Oh the outlines! I didnโ€™t even see those the first time. I wonder if thereโ€™s a way to use shadows with a translate to do soโ€ฆ hmm. But sure thing pseudo elements make sense
Jochem
Jochemโ€ข8mo ago
the text is just repeated a ton of times in that data-title attribute I'd recommend poking around with the dev tools, it's all there ๐Ÿ™‚
clevermissfox
clevermissfoxโ€ข8mo ago
I see it just didnโ€™t know what I was looking for. Iโ€™m not the op btw, just was confused what was even going on
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
@Jochem yes i did that, but felt it isn't the right way.
Jochem
Jochemโ€ข8mo ago
the number of repeats is a bit excessive, but I don't see anything wrong with it as a solution
clevermissfox
clevermissfoxโ€ข8mo ago
Since they are a decorative element you wouldnโ€™t want extra tags in your markup for decoration. I think pseudo elements make sense for this Agree that the amount of repeats is a bit excessive
Jochem
Jochemโ€ข8mo ago
could be that they're needed on an ultrawide, but even with two 1080p monitors and the browser stretched across I don't see more than two repeated values
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
@hart_ache @Jochem How to view this, i am not able to see this in firefox browser.
Jochem
Jochemโ€ข8mo ago
right click, inspect element
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
Found it!, @Jochem thanks!
Jochem
Jochemโ€ข8mo ago
you may have to expand a couple of nodes, it'll pick some element in the tree that's under your mouse
clevermissfox
clevermissfoxโ€ข8mo ago
Especially with that font and font size
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
@Jochem @hart_ache <div className={styles.heroSectionTextWrapper}> <h2 data-title="BRANDING BRANDING" className={styles.nameWrapper}> Branding </h2> </div> css : .nameWrapper { border: 2px solid orange; max-width: 900px; white-space: nowrap; margin-right: auto; } .nameWrapper::before { content: attr(data-title); color: transparent; -webkit-text-stroke-width: 2px; -webkit-text-stroke-color: red; opacity: 0.3; } i want the content inside h2 to be inside nameWrapper div, and ::before and ::after can overflow out of nameWrapper div, but i am getting this result, where ::before is starting from .nameWrapper , i want h2 content (<h2>Branding</h2> ) to start inside the orange box, How can i do it?
No description
No description
Jus Sus || ๐Ÿ’€
Jus Sus || ๐Ÿ’€โ€ข8mo ago
like here the text in black starts inside the box, and ::before and ::after elements overflow from it.
No description
clevermissfox
clevermissfoxโ€ข8mo ago
The pseudo elements ::before( ๐ŸŸ ) and ::after (๐ŸŸฃ) dont start here:
<div class="heroSectionTextWrapper">๐ŸŸ <h2 class="nameWrapper">Branding</h2>๐ŸŸฃ</div>
<div class="heroSectionTextWrapper">๐ŸŸ <h2 class="nameWrapper">Branding</h2>๐ŸŸฃ</div>
They are INSIDE the tag but before and after the content like this:
<div class="heroSectionTextWrapper"><h2 class="nameWrapper">๐ŸŸ Branding๐ŸŸฃ</h2></div>
<div class="heroSectionTextWrapper"><h2 class="nameWrapper">๐ŸŸ Branding๐ŸŸฃ</h2></div>
when you inspect the reference page you'll see how they sit in the dom. You'll have to make them position: absolute; with probably the heroSectionTextWrapper as position: relative; but they are stuck in the same orange box as the h2 because the same rules apply to the pseudo elements of an element as the rules apply to the element itself until you change it explicitly.