# Div's wont align to center

**URL:** <https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745>\
**Category:** General\
**Created:** [July 28, 2017, 1:49pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745 "2017-07-28T13:49:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ap987](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@ap987](https://forum.freecodecamp.org/u/ap987)\
**Post date:** [July 28, 2017, 1:49pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/1 "2017-07-28T13:49:13Z")

</div>

I have a div which contains several other div’s and I am trying to center them so there isn’t a huge gap on the right(see image)  
I have tried `margin: 0 auto` & `display:block` but I can’t get all the div’s to align into the center.

I am adding each card(from materialize) with javascript into a div:  
`<div id="projects" >`  
` <div class="row" id="projectRow">`  
`</div>`  
`</div>`  
Card code:  
`<div class='col s8 m4' id='projectCard'><div class='card blue-grey darken-1'><div class='card-content white-text'><span class='card-title'>"+ json[i].name +"</span><p>"+ json[i].description +"</p></div><div class='card-action'><a href='"+ json[i].repository +"'>Repository</a></div></div>`

CSS:  
`#projectCard{`  
` width: 483.888px;`  
` height: 210.700px;`  
` max-width: 483.888px;`  
` max-height: 210.700px;`  
` }`  
` #projects{`  
` text-align: center;`  
` }`

How would I be able to align these into the center

---

<div class="post-metadata">

**Author:** ![michaelhenderson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/michaelhenderson/32/356215_2.png) [@michaelhenderson](https://forum.freecodecamp.org/u/michaelhenderson)\
**Post date:** [July 28, 2017, 3:13pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/2 "2017-07-28T15:13:59Z")

</div>

are you doing this in codePen?

---

<div class="post-metadata">

**Author:** ![cndragn](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/cndragn/32/159093_2.png) [@cndragn](https://forum.freecodecamp.org/u/cndragn)\
**Post date:** [July 28, 2017, 3:33pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/3 "2017-07-28T15:33:01Z")

</div>

If you have this up live it would help to share the link… the problem may be that you’re focused on just the styles for projects and projectCard that you posted here for us to see,when the problem may be (probably is) somewhere else entirely.

---

<div class="post-metadata">

**Author:** ![nr-mihaylov](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nr-mihaylov/32/60307_2.png) [@nr-mihaylov](https://forum.freecodecamp.org/u/nr-mihaylov)\
**Post date:** [July 28, 2017, 3:47pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/4 "2017-07-28T15:47:47Z")

</div>

Is [this](https://codepen.io/nr-mihaylov/pen/JyYmgR) what you are trying to do ?

---

<div class="post-metadata">

**Author:** ![ap987](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@ap987](https://forum.freecodecamp.org/u/ap987)\
**Post date:** [July 28, 2017, 3:58pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/5 "2017-07-28T15:58:42Z")

</div>

@nr-mihaylov Yes, That was what I was trying to do. Thanks

---

<div class="post-metadata">

**Author:** ![ap987](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@ap987](https://forum.freecodecamp.org/u/ap987)\
**Post date:** [July 28, 2017, 4:11pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/6 "2017-07-28T16:11:42Z")

</div>

@cndragn If you want to take a look at the rest of the code, it’s here:

---

<div class="post-metadata">

**Author:** ![nr-mihaylov](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nr-mihaylov/32/60307_2.png) [@nr-mihaylov](https://forum.freecodecamp.org/u/nr-mihaylov)\
**Post date:** [July 28, 2017, 4:25pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/7 "2017-07-28T16:25:12Z")

</div>

Add the container class to the tag with the projects id and remove those width and height properties from the cards.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:58pm UTC](https://forum.freecodecamp.org/t/divs-wont-align-to-center/138745/9 "2021-01-16T17:58:35Z")

</div>

Closed on January 16, 2021, 5:58pm UTC


