Jump to content

Inline background breaks the text alignment

Recommended Posts

Site URL: https://www.ekustik.cz

Hi all,

I would like to ask you for a help with background color for my h2 headers. When I set a background with the following code, it breaks the text alignment and all the text is suddenly on the far left in the text block.

h2 { display: inline;

  background-color: #B58D3C; 

}

It looks like this: (note that i set the text alignment in the block to the center)image.thumb.png.c48a8d571c1dafb706fb0738f61e6a9a.png

If I don't set it inline, in some of my text blocks, the background looks horrible because it's the whole block:

image.png.64901ff6c5303859be7d95b3057974e4.png

My goal is to have the background only behind the text. however, I want to have some of the text block with left, right or center text alignment. For example, like we can see here:

image.png.b8523f12aaae0fbae9e9736c415c0dbb.png

image.png.1b8256e844b772a7de8bab5e8380aded.png

Is there any code for the display to be inline. but it does not break the text alignment of the whole h2 style?

Thank you, David

Link to comment
  • Replies 4
  • Views 404
  • Created
  • Last Reply

Hi, yes, exactly.

I solved it by creating h4 style that has the golden background and then inserted code block with:

<h4> TEXT </>

However, this still work only when:

display:inline

That means that the text can't be aligned otherwise than on the left. I think I am missing something important. Do you think there is way how to set the colored background of just the text so it does not interfere with the text alignment at all?

Link to comment
On 1/14/2021 at 2:57 AM, DavidHortvik said:

Hi, yes, exactly.

I solved it by creating h4 style that has the golden background and then inserted code block with:

<h4> TEXT </>

However, this still work only when:

display:inline

That means that the text can't be aligned otherwise than on the left. I think I am missing something important. Do you think there is way how to set the colored background of just the text so it does not interfere with the text alignment at all?

Keep the current code & add this to Design > Custom CSS

div#block-yui_3_17_2_1_1610468698876_27228>div {
    text-align: center;
}

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.