Learning to Code!
This is the begining point of part two of the learning to code series on OurBigAdventure.com so far we have covered how to use HTML tags to allow our content to be seen in our web browser!
By the end of this lesson we will have some images on our page and our display will look much less like a simple outline.
Image Tag
The image tag is fun! We can add them almost anywhere!
Let's add some fake text here so we have more to play with. Portland street art sustainable paleo wayfarers, mlkshk food truck pabst echo park salvia. …
Hella sartorial pitchfork, pabst typewriter plaid hoodie offal ethical godard before they sold out. Humblebrag stumptown 3 wolf moon four dollar toast fingerstache, gastropub slow-carb street art pitchfork sriracha asymmetrical craft beer mixtape schlitz. …
Whatever slow-carb trust fund, mixtape pabst flexitarian bitters ramps gluten-free. Marfa gluten-free selvage mixtape, venmo etsy master cleanse small batch DIY vice. …
You probably haven't heard of them ramps gentrify kitsch health goth, drinking vinegar bespoke. Ethical lumbersexual cronut, microdosing twee chartreuse humblebrag mlkshk. …
Sriracha you probably haven't heard of them small batch post-ironic etsy. Man bun crucifix fashion axe gluten-free deep v meditation yr. …
Salvia pour-over tattooed marfa offal. Pickled 8-bit celiac direct trade kale chips. Lumbersexual thundercats microdosing, keytar 8-bit messenger bag trust fund distillery vice. …
You can see that I have a few tags mixed in probably like you do. Just pick anywhere within your content (even between other tags) and add your image like this:The image tag is fun! We can add them almost anywhere!
Let's add some fake text here so we have more to play with. Portland street art sustainable paleo wayfarers, mlkshk food truck pabst echo park salvia. …
or this:The image tag is fun! We can add them almost anywhere!
Let's add some fake text here so we have more to play with.
Portland street art sustainable paleo wayfarers, mlkshk food truck pabst echo park salvia. …
The image tag is fun! We can add them almost anywhere!
Let's add some fake text here so we have more to play with.
Portland street art sustainable paleo wayfarers, mlkshk food truck pabst echo park salvia. …
or a
tag. The value we want to set varies, we can control the space around our tag, the space within it, where it aligns and many other things. For now, let's control the space around it with the ‘margin' value. There are four values for the margin, the ‘top', ‘right', ‘bottom', and ‘left'. You can set them together or separately. To set all of the margins to the same value you can do something like this:
Portland street art sustainable paleo wayfarers, mlkshk food truck pabst echo park salvia. …
This adds a 20 pixel buffer all around this paragraph. Try this on one of yours to see what it looks like. Then, also add it to your tag to see how that changes things. Fun stuff right! As you can imagine you could spend hours and hours moving things around to get them just right. Once we get a few more lessons under our belts I will show you how you can avoid that and just use your new skills to clean things up. :) Now, if we want to set our margins separately there are two ways to do that. You can set these separately: margin-top: VALUE; margin-right: VALUE; margin-bottom: VALUE; margin-left: VALUE; OR we can set them all on the same line like this: margin: TOP_VALUE RIGHT_VALUE BOTTOM_VALUE LEFT_VALUE; The values are listed clockwise starting at the top which makes it easier to remember the order. :) Oh, and did I mention that you can also set them as percent values? The percent will get a little tricky from time to time because it's not the percent value of the overall page, it's the percent value of the parent container. So if we set atag to have a top margin of 10%, that is equal to 10% of the
tag. So if our tag has any spacing set it will also adjust the value of that top margin that we set, much like you saw when you added the margin value to your body tag. Basically these styles cascade through the tags from outermost to innermost. (Which is why I had you indent your tags to begin with, it makes it easier to see the parent elements and will be helpful in this lesson.) Ok, take a deep breath. I know it's getting a little scary with sometimes unintended changes on your page but it's not really that bad, it just takes some practice. Now let's clear up the one thing that will confuse you if you have jumped ahead to the ‘padding' setting. Actually, let's just show you what that does so you can understand it really easily! Add a border to any tag on your page. You do that like this: Portland The border for this element is now set to be a 1 pixel thick solid blue line. You can make yours ‘dashed' if you want or even ‘dotted', it's entirely up to you. (I'll tell you where you can find out more about these styles in just a minute) Now that we have a border we can see the difference between ‘margin' and ‘padding'. Now add a padding value to the same element like this: Portland Can you see the change! Now the border has 10 pixels of padding all around the contents of this element, very cool. Ok, change it to say ‘margin' instead of ‘padding'. Portland What happened? The border is still there, everything is in the same place, but this time the 10 pixels is on the outside of the border. And keep in mind that the border is the outside edge of this element so the difference is that a margin is on the outside and padding is on the inside. That can be a tough concept in the beginning, so awesome job for getting that under your belt! It would be too much to walk you through all of the values that you can use for your new page so here is a great link for learning about everything you can set and how each one of them works: http://www.w3schools.com/cssref/ Some of the things you may want to look at for your layout would be the ‘font' options, the ‘float' options, and even the ‘max-height' and ‘max-width' options. Now let's tackle that image we added earlier. How do we set that sucker to a size that we want? Well if your image is REALLY BIG try to save a smaller version first (a size less than 1200 pixels wide or high would be great) then let's add a style attribute to that image and see how it looks:
Great! Our image has changed sizes but it also got weird. :} That's because we are setting the height and width to be a ratio that doesn't match the image. (Unless I guessed correctly on your image which would be really lucky) So let's change our style again and this time let's not be so rigid in our settings:
That's better! When we don't set the height our browser will calculate it for us, and we aren't really setting the width either, we are just setting the max-width so if our layout settings begin to squish our image it will scale and still look ok, but it will never stretch beyond 300 pixels wide.
Go play with your new style skills and see what you can create. We will pick up next time explaining links, file paths and how to organize your files to make your web pages easy for you to work with in the future.
OH! and before I forget, you will see ‘CSS' a lot as you play with your styles. CSS stand for Cascading Style Sheets. You understand the ‘cascade' part and the ‘style' part as well. We will cover why it is a ‘sheet' in the next lesson when we move all of your styles to their own file! It's going to be awesome. :)
Comments