Mobile app version of vmapp.org
Login or Join
Shelton719

: Incorrect background color show on mobile devices I am using Bootstrap and wanted a colored background for my h2 title like this: So I wrapped the text in a tag. The problem is on mobile

@Shelton719

Posted in: #Background #Bootstrap

I am using Bootstrap and wanted a colored background for my h2 title like this:



So I wrapped the text in a tag.
The problem is on mobile devices it shows like this, which is not good



Can you please help with a solution ?
Thank you

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shelton719

1 Comments

Sorted by latest first Latest Oldest Best

 

@Berumen635

I believe the problem is that you're applying the background color to the inner tag (a span?) instead of to the outer h2. You haven't said exactly how you're using Bootstrap, so I put together an example (codepen) that I think shows what you have and what you want with just basic CSS.

Here's the HTML:

<h2 id="bad"><span>Restaurant Reservations & Take-Aways</span></h2>
<h2 id="good">Restaurant Reservations & Take-Aways</h2>


And the CSS; ignore the width=10em; that's just to simulate a narrow/mobile screen:

h2 { width: 10em; text-align: center; line-height: 0.9; color: white;}
h2#bad span {background-color: black;}
h2#good {background-color: black;}


So, the idea is to make sure the background applies to the block-level element, the h2, not the inline text, the span. Hope you can easily work that back into your Bootstrap setup.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme