Today we looked at structuring a webpage using CSS styles such as width, heights, floats and clears. The task was to create a series of trading cards using a combination of different divs, and I chose to make a halloween themed set of cards.
 |
| Spooky trading cards, made by floating different divs |
Firstly I created the main card, using a
div to create a '
cardcontainer'. This container then held four smaller
divs, one for heading, image, sub-heading and information. Naturally,
divs fall into place vertically so creating this cascading effect for the cards was easy, and was just a case of choosing different widths and heights for each section. The next thing was to center the information inside the card, which is achieved using the '
margin: auto;' CSS style. Once the four
divs lay centrally, one after the other inside the container, the next thing to do was to fill them with content, including a background image for each card and also a background image for the 'image'
div. After this I had one finished card.
After creating the remaining eight cards by copying and pasting, they all cascaded vertically, whereas I wanted to have three rows of three cards, as pictured above. To do this, I floated the cards using the '
float: left' style, which would have all of the cards next to each other, until there was no space left on the row, at which point the cards would move onto the next line. To get the three rows of three, I created '
div class="clearfix" ', a class which clears content onto the next line. I placed this
div in my code after every three cards, and this gave me my three rows of three.
To move all of the cards into the middle of the webpage, I created a '
maincontainer' div, that went around all of my cards. Giving this a '
margin:auto' style, and setting '
width:960px' centred my cards on the webpage, leaving plenty of space either side to show off the background image of the entire page.