Reputation:
I am starting out with html and css and want to know how to give a line of text a background-color. For example :
#python-heading {
font-family: 'Arvo', serif;
position: absolute;
bottom: 600px;
left: 600px;
background-color: #DEE0D9;
}
<body>
<header>
<span><h1 id="python-heading">Python</h1></span>
<h2 id="python-subheading">Subtitle</h2>
</header>
</body>
but my text not the whole area behind the text. i mean that i want it like this:
hyphen => bg color
-------------------------------------------text--------------------------------------------------------
but it is like this:
-text-
what do i need to change/add?
Upvotes: 0
Views: 51
Reputation: 8098
I think you should avoid using h1
inside span
and simply go with h1
and following code change. ( If I have understood your question correctly then this may help)
#python-heading {
background-color: #DEE0D9;
text-align:center;
}
<header>
<h1 id="python-heading">Python</h1>
<h2 id="python-subheading">Subtitle</h2>
</header>
Upvotes: 1
Reputation: 3249
Add width:100%;
and change left:600px;
to padding-left:600px;
#python-heading {
font-family: 'Arvo', serif;
position: absolute;
width:100%;
bottom: 600px;
left:0;
padding-left: 600px;
background-color: #DEE0D9;
}
<body>
<header>
<span><h1 id="python-heading">Python</h1></span>
<h2 id="python-subheading">Subtitle</h2>
</header>
</body>
Upvotes: 0