Skip to content

Instantly share code, notes, and snippets.

@milkman4
Last active August 24, 2016 17:21
Show Gist options
  • Save milkman4/c2223f9838787be357644626867e97ab to your computer and use it in GitHub Desktop.
Save milkman4/c2223f9838787be357644626867e97ab to your computer and use it in GitHub Desktop.
CSS Positioning Challenges

###Challenge 1

Created three separate divs and put them all on the same line with inline-block. We then used float to put both div 2 and div 3 on the right side, then added a margin-left to div 3 to separate them.

Challenge 1

###Challenge 2

all three divs are in their own block, all we had to do was add float: right to div 3 and margin: auto to div 2 to center it.

Challenge 2

###Challenge 3

we placed div 2 inside of div 1 in the html to have div 1 be the container. then we used margin: auto to center div 1, then we used margin - auto to center div 2 in the middle of div 1, then used margin-top to move div 2 down because 25% of the size is the right amount to place in the middle.

Challenge 3

###Challenge 4

giving div 2 a position of absolute, we can move it anywhere on the page regardless of what's in the way. so, we moved it up with margin top of -75, and then to the right with magin-left of 75.

Challenge 4

###Challenge 5

first, we floated div 1 to the right. then, it moved div 2 into the center of the same line as div 1, but then we used clear: both to disallow other elements to float on the left or right side of div 2;

[Challenge 5] (http://codepen.io/milkman90/pen/Krjzmz?editors=1100#)

###Challenge 6

we put div 2 and div 3 inside of div 1, floated div 1 to the right and added a margin-top to bring it down the page. then, i floated div 2 to the left, and div 3 to the right. in order to get div 2 to not affect the div 1 text, i used absolute to bring it in front of the div 2 elements and added a margin-top to bring it down the box to the bottom, while testing the right px count in order to get it to the right place.

Challenge 6

###Challenge 7

we had to put div 2 inside of div 1, and increased the size of div 1. all that was required was adding a float: right to div 2 and adding a margin-top of 100px to move to the bottom right of div 1.

Challenge 7

###Challenge 8

we put div 2 inside of div 1, and increased the size of div 1. all we had to do was add a float right to div 2. in fact it's the same as challenge 7 but just with margin-top removed.

Challenge 8

###Challenge 9

div 2 and 3 had to be placed inside div 1 in the html, then i added a display: inline-block with div 2 to move it to the top of div 1, in line with the text, then added a pixel margin to move it to the center. div 3 then needed a margin-auto to center it, then moved to the bottom with margin-top.

Challenge 9

###Challenge 10

div 2/3 had to be placed inside div 1 while div 1 (and everything inside) was moved to the center of the page. using display: absolute on div 2/3 to allow them to move anywhere, we used margins to get them in the correct position.

Challenge 10

###Challenge 11

div 3 was placed inside div 2, which was placed inside div 1 in the html. we set the size of the divs accordingly, and then used margins to place div 2 to the bottom right corner, and then used margin-left and margin-top to move div 3 to the correct place inside div 2.

Challenge 11

###Challenge 12

challenge 12 has the same html structure as 11, with all divs nested inside the previous one. for this one, i changed the margins to shift the divs around. for div 3 we had to use a margin-left value that was negative to move it to the other side of the margin.

Challenge 12

###Challenge 13

for this one, all divs were nested inside the higher div in HTML. then, we just added a margin-top and a margin-left to move to the right location, and added the same selectors to each subsequent div.

[Challenge 13] (http://codepen.io/milkman90/pen/kXKXkJ)

###Challenge 14

div 2 was nested inside of div 1, div 1 was floated to the right and div 2 was given a margin-top to bring it to the bottom of div 1.

Challenge 14

###Challenge 15

div 1 and div 4 are the same size and color, and div 2 and 3 are the same size and color. div 1 and div 2 are display: in-line block ahile div 2 was given a margin-left to move to the right. then, div 3 is a block level element on the next line, with a margin-top to move it down. then, div 4 was given a display: absolute to move out and above all other elements, with a margin-left to move right and a negative margin-top to move up.

Challenge 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment