I’m a beginner in HTML/CSS and I’m stumbling my way through building my own Neocities site. I was able to get the div centered by putting above and below it, but (understandably) the text is also centered.
This is my code:
<center>
<div style="width:1000px;height:150px;border:1px solid blue;overflow:scroll;padding:15px 25px 15px 25px;background-color:#A2E4B8;color:#000000;scrollbar-base-color:#DEBB07;box-shadow: 7px 7px rgb(0, 0, 0, 0.8);">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br><br>Fringilla urna porttitor rhoncus dolor purus. Id
venenatis a condimentum vitae. Scelerisque in dictum non consectetur a erat nam. Ultrices eros in cursus turpis. Facilisi cras fermentum odio eu feugiat. Pellentesque dignissim enim sit amet venenatis urna cursus eget nunc. Amet luctus venenatis lectus
magna. Nibh nisl condimentum id venenatis a. Nec dui nunc mattis enim ut tellus. At risus viverra adipiscing at in tellus integer. Placerat vestibulum lectus mauris ultrices. Semper viverra nam libero justo laoreet.
</div>
</center>
A screenshot of my Neocities HTML code
I tried using text-align: left; but that didn’t yield results. I am sure I’m doing something wrong, but I’m feeling quite lost as to what that is.
3
Answers
Set the left and right margins to auto.
Further reading here.
You should avoid using the "center" tag as it’s deprecated in HTML5. Instead, use CSS to center the div container.
I’ve added CSS styling directly within the "head" section using the "style" tag, but you can use it in an external css file.
I’ve used flexbox on the body to center the content both horizontally and vertically. The div element got a classname ".content-container" and by using the "text-align: left;" it aligns the text within the "div" to the left while keeping the entire "div" centered on the page.
Or if you dont want to style the body element, here is an alternative method:
Here the div with the classname ".content-container" is centered horizontally by using "margin: 0 auto;" and the text in it aligned left by using the "text-align: left;" property.
Try
text-align:left !important;