neosanctuary

css tutorial

Dec 2nd, 2021
1,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. [ WORK IN PROGRESS ]
  2.  
  3. welcome to my first tutorial! in this i will show you how HTML CSS (cascading style sheets) coding works! i hope my explanations will make sense :')
  4.  
  5. DISCLAIMER AND NOTE: please do keep in mind that at least basic html coding knowledge is required to understand this tutorial! given this, i am not a professional coder nor am i proficient in html, i am just making this as a reference for myself & other people who might be looking to use these for carrd and website making services akin to it, or who just want to learn something about css! in case you're more of a visual learner, i have created a folder with all html files containing demonstrations and examples: https://mega.nz/folder/DxwRkIIB#tszEEpCNwJzspfMpcZV4XA (written in visual studio code 1.62.3)
  6.  
  7. with all that said, let's begin!
  8.  
  9. HOW TO START A CSS CODE?
  10.  
  11. a css code has two basic components:
  12. - the <style></style> section
  13. - the label of the class where the code will be, separated by {}
  14.  
  15. which means that a css code would look like this at the baseline:
  16. <style>
  17. .your-class-name {
  18. your properties go here!
  19. }
  20. </style>
  21.  
  22. usually in the case of a website built from scratch, the css code will be in a .css file separate from the .html file, but you can just put the <style> section in the .html file if you don't mind long codes!
  23.  
  24. to refer back to these classes in text, you would use <p></p> or your relevant text style and insert the class:
  25. <p class='your-class-name'>text here</p>
  26.  
  27. of course, css codes don't only pertain to text! you can use them on images too with the right properties! there are also codes that only come into the conversation once you hover over or click on an object, i will mention these later on! given that <style> is a section, you can put differently labelled css properties pertaining to different objects too!
  28.  
  29. TEXT CSS PROPERTIES
  30.  
  31. the most basic text properties include:
  32. font-size (works with specified px, percentage, em with 1em being 2in or keywords like 'large' and 'small')
  33. font-family (built in or custom - tutorial for custom fonts in carrd: https://www.youtube.com/watch?v=sctl4iZEIqo&t=9s)
  34. text-align
  35. text-decoration (i usually use this to remove any underlines)
  36. text-color (hex code, keywords like 'red' and 'blue' or rgb code)
  37.  
  38. the text classes can still be transformed outside of the style, i.e if you only want certain parts italicized for emphasis!
  39. in the code below, only the word 'emphasis' would be italicized
  40. <style>
  41. .red-text {
  42. color: red;
  43. }
  44. </style>
  45. <p class='red-text'>the <em>emphasis</em> is here</p>
  46.  
  47. MISC (IMAGE, GENERAL, BACKGROUND/CONTAINER) PROPERTIES
  48.  
  49. there are a myriad of other properties that can apply to either all objects, images or containers (boxes). such include:
  50. transform
  51. position
  52. z-index (specifies stack order)
  53. border
  54. padding (top/left/bottom/right)
  55. height & width
  56. color
  57. background properties, such as color, position, size etc.
  58.  
  59. i will explain each of these and how to use them (to an extent)!
  60.  
  61. 1. TRANSFORM
  62.  
  63. there are many transform functions, i will only list some - website containing all transform functions: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
  64.  
  65. rotate (3d, X, Y, Z), scale (X, Y, Z), skew (X, Y), translate (3d, X, Y, Z)
  66. these are pretty self explanatory, however there are some where you need to specify multiple numbers or a specific type of value - ex. rotate and skew would need a degree: rotateX(10deg), skewY(50deg); 3d functions need multiple values, ex. rotate3d(1, 2, 3, 10deg)
  67.  
  68. translate works in a similar way to the position property, however it can also provide placement in a 3d perspective, i.e translate3d(10px, 10px, 50px) would bring an object seemingly closer and above other objects without this property
  69.  
  70. you can also put multiple function values into one transform function:
  71. transform: rotateX(5deg) translate(50px, 50px, 0) scale(1.7);
  72.  
  73. 2. POSITION
  74.  
  75. position is exactly what it says - it can change the position of objects. there are three important types of position properties:
  76.  
  77. position: static; positions the element according to the document flow with top, right, left, bottom and z-index having *no effect* on it. this is the default value
  78.  
  79. position: relative; positions the element according to the document flow and relative to itself taking into account the top, right, left, bottom and z-index values. this will not affect other objects without the property
  80.  
  81. position: absolute; removes the element from the document flow and does not create space for the object. it positions the element relative to its closest positioned ancestor, meaning if there are three images next to eachother and the one with this property is in the middle, it will be placed relative to the first image. the final position is determined by the top, bottom, right and left values and a new stacking context will be created if the value of z-index is not auto - if your middle image overlaps with its ancestor, it will be on top unless you specify the z-index value
  82.  
  83. the usage of the position value:
  84. <style>
  85. .pos {
  86. position: relative | absolute;
  87. left: 50px;
  88. top: 50px;
  89. }
  90. </style>
  91.  
  92. !!! it is important to note that the direction values do not equal the direction the object will be moved in; if increased, 'left' will move objects to the right, 'right' to the left, 'top' to the bottom and 'bottom' to the top and vice versa when decreased !!!
  93.  
  94. !!! OTHER IMPORTANT NOTE !!! that one object's position value WILL NOT affect other objects', i.e if you move something downward and want to put other objects right below it, you would also need to adjust the position value of the other objects
  95.  
  96. 3. Z-INDEX
  97.  
  98. z-index defines stack order - the higher the value of the z-index property, the higher it will be if it overlaps with other items. the default value for this is 'auto'. if you have 7 items you want to stack on top of eachother, the object you want to be on top would have the z-index value of 7, and the one on the very bottom would have the value of -7.
  99.  
  100. usage of the z-index value:
  101. <style>
  102. .ind {
  103. z-index: [value]
  104. }
  105. </style>
  106.  
  107. although this property is mostly used when elements are moved around with the position value, it may be useful in itself aswell!
Add Comment
Please, Sign In to add comment