So , when I add my width reference to my #information h1 id it completely ignores the text-align: center; reference and puts the text/background to the left instead of center
so basically i need help getting the headers centered with the proper background width so its not backgrounding whitespace
as you can tell im brand new - this is my first time experimenting with html and css - started my course a day or 2 ago
CSS
#information h1{
text-align: center;
font-family: Tahoma;
color: lightcoral;
background-color: whitesmoke;
width: 130px;
margin: 2px;
border-radius: 25px;
box-shadow: 2px 2px 2px grey;
font-size: 25px;
}
HTML
<section id="information">
<h1>Information</h1>
<p>Currently starting my course on becoming a full stack engineer while working on a BS in Computer Science. Open to pretty much anything!<br>
Looking for part time or full time work while I attend school and courses also open to any development projects!
</p>
<h1>Hobbies + More</h1>
WITH WIDTH REFERENCE
headers how i want but not centered
WITHOUT WIDTH REFERENCE Headers without width
Centering text using
text-align: centercenters the text within the element (in your case that'sh1). If you set the elementswidthto 130px, it centers the text within those 130px (which might even be less wide than the text actually spans, or at least hardly more than that). The element itself still starts at the left side of its container (in your case the body).Just don't set the width, as you did before.
Addition after comment:
You can use a
spanelement for the text inside theh1, usetext-align: centeron theh1and all the other settings on thespaninside it: