Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Margin left is moving my whole div to the left instead of just the text inside it

I am trying to position my "My Header" by adding margin-left to it, but it keeps moving the whole div object instead of just the text.

Check it out here: https://jsfiddle.net/8denfw3h/

I am just trying to use the margin-left to add space to "My Header", which should shift it towards to the right, but it is not working.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The margin-left is adding the margin to the entire div object, not the "My Header" like I want it to.

What am I doing wrong?

>Solution :

You’ll have to use h1#aboutTitle in order to get that margin-left. However, if you’re just trying to align the text to the center I would remove the margin-left and use text-align: center; on the h1#aboutTitle CSS.

Also, you forgot your > on your myDiv in your fiddle.

.myDiv {
  overflow: hidden;
  width: 500px;
  height: 500px;
  background-color: #EB3A6A;
}

h1#aboutTitle{
  margin-left: 30px;
  font-family: 'Poppins', sans-serif;
  font-size: 65px;
  color: white;
  font-weight: 600;

}
<div class="myDiv">
 <h1 id="aboutTitle">My Header</h1>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading