# How to make the last row automatically center itself when resizing

**URL:** <https://forum.freecodecamp.org/t/how-to-make-the-last-row-automatically-center-itself-when-resizing/165962>\
**Category:** General\
**Created:** [December 29, 2017, 10:47pm UTC](https://forum.freecodecamp.org/t/how-to-make-the-last-row-automatically-center-itself-when-resizing/165962 "2017-12-29T22:47:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmking0728](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@dmking0728](https://forum.freecodecamp.org/u/dmking0728)\
**Post date:** [December 29, 2017, 10:47pm UTC](https://forum.freecodecamp.org/t/how-to-make-the-last-row-automatically-center-itself-when-resizing/165962/1 "2017-12-29T22:47:12Z")

</div>

So i’m building a website and on one page i have a 3x12 video grid of many youtube videos. currently i have it so when there is a large screen it is 3 videos across. when it is a medium screen it shrinks down to 2 videos across and the videos slide down. small screen is 1 video across. the problem is when i have an odd number of videos, the last row at the bottom of the grid looks odd because it will have only 2 in the row with a large screen size, and 1 in the row with a medium screen. Is there a way to make it so if there is an odd number of videos for the page it will automatically center the last videos in the grid? I’m a newbie so easy with the technical terms please lol. thanks!

```auto
<div class="container-fluid">
	<div class="row">
		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='w38rpW_QBQA'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='xx418GwydNg'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='7C4VVfc6IKc'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='rnCn9Qw49ls'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='ICEAwQrNufk'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='BtP4Itw08ew'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='S2BjavO8IME'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='fjwylknK_m0'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='qP4aZVPCXn0'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='u03B9s4o7eA'></div>
		</div>

		<div class="col-lg-4 col-md-6 col-sm-12 video">
			<div class='youtube-player' data-id='C8QI5lGhjz4'></div>
		</div>

	</div>
</div>

```

The css:

````auto
.videowrapper {
    float: none;
    clear: both;
    width: 100%;
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 25px;
    height: 0;
}

 .youtube-player {
  position: relative;
  padding-bottom: 56.23%;
  /* Use 75% for 4:3 videos */
  height: 0;
  overflow: hidden;
  max-width: 100%;
  background: #000;
  margin: 5px;
}
.youtube-player iframe {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: transparent;
}
    
.youtube-player img {
  bottom: 0;
  display: block;
  left: 0;
  margin: auto;
  max-width: 100%;
  width: 100%;
  position: absolute;
  right: 0;
  top: 0;
  border: none;
  height: auto;
  cursor: pointer;
  -webkit-transition: .4s all;
  -o-transition: .4s all;
  -moz-transition: .4s all;
  transition: .4s all;
}
.youtube-player img:hover {
  -webkit-filter: brightness(75%);
}
.youtube-player .play {
  height: 72px;
  width: 72px;
  left: 50%;
  top: 50%;
  margin-left: -36px;
  margin-top: -36px;
  position: absolute;
  background: url("http://i.imgur.com/TxzC70f.png") no-repeat;
  cursor: pointer;
}```
````

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [December 30, 2017, 12:27am UTC](https://forum.freecodecamp.org/t/how-to-make-the-last-row-automatically-center-itself-when-resizing/165962/2 "2017-12-30T00:27:44Z")

</div>

How about offsetting every third col when the `col-md` kicks in?

```auto
<div class "col-lg-4 col-md-6 col-sm-12 video">...</div>
<div class "col-lg-4 col-md-6 col-sm-12 video">...</div>
<div class "col-lg-4 col-md-6 col-md-offset-3 col-sm-12 video">...</div>

```

You might have to add `col-lg-offset-0` if the `md-offset` also offsets the div on large displays.

---

<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:12pm UTC](https://forum.freecodecamp.org/t/how-to-make-the-last-row-automatically-center-itself-when-resizing/165962/3 "2021-01-16T17:12:56Z")

</div>

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


