Jump to content

How to keep padding on heading text highlight when line breaks

Recommended Posts

 

I'm using the following code to add a highlight to my h2 when bolded but the highlight is abrupt when the line breaks in mobile or smaller browser size. Is there a better way to do this so that the highlight feels more like a background around all letters with equal space?

   
h2 strong {
  background: #1b1b1a;
  padding-top: 7px;
  padding-bottom: 7px;
  font-weight:normal !important;
}

 

URL: https://cantina-loca.squarespace.com/

Password: 8989

1856486637_ScreenShot2021-10-20at12_52_15AM.thumb.png.a6ae41ca8349392f1d76eb61512835b6.png

Link to comment
  • Replies 9
  • Views 1.8k
  • Created
  • Last Reply

Top Posters In This Topic

9 hours ago, lamdra said:

 

I'm using the following code to add a highlight to my h2 when bolded but the highlight is abrupt when the line breaks in mobile or smaller browser size. Is there a better way to do this so that the highlight feels more like a background around all letters with equal space?

   
h2 strong {
  background: #1b1b1a;
  padding-top: 7px;
  padding-bottom: 7px;
  font-weight:normal !important;
}

 

URL: https://cantina-loca.squarespace.com/

Password: 8989

1856486637_ScreenShot2021-10-20at12_52_15AM.thumb.png.a6ae41ca8349392f1d76eb61512835b6.png

It seems that you 've solved your issue on your own, doesn't it?

image.png.b449d66d7df8e50645db90bd42a18002.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
4 minutes ago, bangank36 said:

It seems that you 've solved your issue on your own, doesn't it?

No, I haven't actually. I worked around it for now by doing a hard return and adding a space before the line. But that's not ideal. Do you know how I can fix this without the forced return?

Link to comment
2 hours ago, lamdra said:

No, I haven't actually. I worked around it for now by doing a hard return and adding a space before the line. But that's not ideal. Do you know how I can fix this without the forced return?

Still happens on longer headlines where I can't control the line breaks.

1574470603_ScreenShot2021-10-20at2_00_44PM.thumb.png.436f66e7d7c2de771f5a78768221619b.png

Link to comment
On 10/28/2021 at 10:30 AM, lamdra said:

@bangank36 @tuanphan Any thoughts? Site is no longer password protected. You can recreate the issue on mobile version of this page

https://www.cantinaloca.com/our-story

Thanks for your help!

How do you want the text to appear on the desktop-tablet-mobile?

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
On 10/30/2021 at 7:37 PM, tuanphan said:

How do you want the text to appear on the desktop-tablet-mobile?

 

I'd like there to be padding on the left of the text when it drops down a line. The way "Call Loca" looks is what I'm after but unless I manually add a return and a space I can't get it. For example what you see before "Time" is what it looks like if it just automatically drops a line in smaller screens.

Is there a way to keep that left padding even when the sentence breaks into multiple lines?

Screen Shot 2021-10-20 at 2.00.44 PM.png

Link to comment
  • 2 years later...

I know this is an old thread, but I recently ran into a similar situation and came across this post while I was looking for a solution. I found something that worked for my situation by including the following css attributes I found on this article: https://dev.to/nhuynh1/highlighter-effect-adding-box-decorations-like-padding-to-inline-elements-that-wrap-onto-multiple-lines-10ip. Hope you find it useful!

{
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

 

I tested out this solution on your site and see if it would work. While looking at it, I noticed a lot of the css is missing semicolons after a lot of attributes. Don't know if this is a Squarespace issue or not, since I have not worked with their builder. There were also an element style I needed to remove in order to make the spacing even for all sides as well. These were my changes:

h2 strong {
    background: #1b1b1a;
    padding-top: 6px;
    padding-bottom: 6px;
    font-weight: normal !important;
    padding-left: 30px;
    padding-right: 30px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

h2 element style attribute  {
    text-align: center;
    /* white-space: pre-wrap; */
}

 

Note missing line numbers and semicolons in original css on the left.

Screenshot2024-04-04at1_15_37PM.png.89b689139c3dce3d8627b8247d0bff8d.png

 

Site unchanged - no padding on headline lines 2 and 3.

Screenshot2024-04-04at1_17_31PM.thumb.png.57046c90055c4ff013567f7a3115458b.png

 

Addition of box-decoration-break - padding now visible on headlines 2 and 3, but greater on line 1 left & right, and on line 2 right only.

Screenshot2024-04-04at1_04_08PM.thumb.png.90aa9a4c5c71be7b246cff313e35a50a.png

 

Removal of h2 element style attribute white-space: pre-wrap - padding now even on all lines.Screenshot2024-04-04at1_24_34PM.png.a39c939d00d10fd3f43290fd6aad839c.png

Screenshot2024-04-04at1_04_23PM.thumb.png.98b3ae1ccd6db825a6d390b329f43bf8.png

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.