Background
As far as I understand from the internet, SPAN and DIV fulfill pretty much the same basic purpose, namely group a bunch of HTML statements to perform some group actions. SPANs and DIVs should not affect colors.
Question
Can anyone tell me why background colors don't work when DIVs are replaces by SPANs?
Symptoms
In the code below I want the text surrounded by the DIV to have a red background color. Unfortunately it has a white background color. However, if I change the SPAN into a DIV (line number 1), then I get the color I asked for.
<span class="benefits" style="background-color: red;">
<div>2023 Survey of 10 billion Respondents!</div>
</span>
You can find a live Codepen example here.
What have I tried?
- Inline CSS
- External CSS
- Read about SPANs on MDN
- Read about DIVs on MDN
- Read about background-color on MDN
- Cross-browser testing on Browserling. I tried Windows with several versions of Chrome, several versions of Firefox and Safari
- Tested with Firefox 110.0.1 64-bit on a Linux machine
- Tested with Chromium 110.0.5481.100 on a Linux machine
- Tested with Codepen
- Search Google.