Skip to main content

CSS Basics for Beginners -Technoob Technology

CASCADE STYLE SHEETS which is simply called as CSS is one of the nicest and advanced styling languages came up with the development of technology and this is the main styling language which is used for HTML documents. CSS defines how the HTML elements should be while HTML creates the page structure. CSS is easy to learn easy to use and well performing. CSS allows you to style the HTML elements without including the codes in the same HTML file. You can separate the codes and include them in a  new file and link that file to your HTML document. 

CSS-Cascade_style_sheets-Technoob Technology



CSS structure 

CSS structure is very easy to understand. Enter the ID, class or tag name, then open curly brackets and write your code within those brackets. 



CSS-Cascade_style_sheets-Technoob Technology


body{
background-color:red;
font-size:25 px;
}

When selecting the elements there are 3 different ways and we'll talk about it later.


Adding CSS

You can add CSS to your HTML files using 3 different ways.


  • Inline CSS
  • Internal CSS
  • External CSS




Inline CSS 

Inline CSS is easy to use. You can simply add the style attribute to any tag you want and enter the codes within that style attribute. 

  <p style="color:red;></P>

This is easy to use but when you master CSS and start coding a lot, then this system would feel like a mess. So only use this type when its necessary, else it would become so hard to understand your code and even editing would be much harder.


Internal CSS

Internal CSS is adding your CSS codes within the head tags of your HTML document. Within the head tags open the style tags,  <style></style>   and enter your code within the style tags. 

It's a good practice to add style tags like this.

<style type="text/css" media="all"></style>

When you become familiar with CSS you would get to know how to change these things as you want. For now, try the codes using as given above.



External CSS 

External CSS is very valuable when adding the same styles to different HTML pages. You can link the same CSS file to any amount of HTML files. And the other importance of external CSS is you can easily understand the code, and you can separate the files according to different elements. 

When writing an external CSS code you should remember to save it in the .css file extension.

Ex-    filename.css

To link this CSS file to your HTML file you can use the code given below.

<link rel="stylesheet" href="filename.css">


NOTE: If the CSS file is stored in a different folder remember to specify the in href attribute.




CSS selectors

Selecting an element of an HTML document can be done using four main ways.


  1. Type selectors
  2. ID selectors
  3. Class selectors
  4. Descendant Selectors



Type selectors

Type selector is the easiest way. Simply enter the type of the element. 

<p>here goes text</p>

p{
    color:red;}

This colors the text of the paragraph element in red.


NOTE: Type selector selects all the elements of the same type and applies the style to all elements, and to avoid that you can use ID and class selectors.




ID selectors

Selecting the element using its id is called an ID selector. You can add an id to each and every element and select the element using its id. When selecting with the id you should remember to use # tag before the id.

<p id="text"> Hello! </p>
#text{
color:red;}

This CSS code selects the p element using the id "text" and sets it color to red. 

NOTE: never add an id which starts with a number.





Class selectors

You can even select an element using its class. You can add the same class to many HTML elements as much as you want. Select the class using "." before the class name.

<p class="text"> Hello! </p>
.text{
color:red;}

This selects the class text and applies the styles into that element.



Descendant Selector


This is used to select elements within other elements. You can simply do this by writing the element name while keeping spaces between them. 

<div id="first">
<p id="second">Hello <div class="color">World</div></p>
</div>

#first #second .color{  color:red;}

This code sets the color of word world into red color.




CSS Comments 

There is only one way to add comments in CSS.  Start the comment with " /* " and end it with " */  ".

/* this is a comment */


NOTE: Always remember that if you haven't described any styles for an element, it takes the styles of its parent element.  For an example, if you have written body{color: green;} all the other text elements within the body tags will take the color green.


Let's see an example of a simple web page designing using CSS


<html><head><title>title</title>

<style type="text/css" media="all">

body{     background-color:cyan;}
h1{ text-align:center;
color:red;
font-size:30px;}

#welcome text{
border:2px dotted black;
background-color:yellow;
font-style:italic;}

</style>
</head>
<body>
<h1> HELLO </h1>
<p id="welcome text">We warmly welcome you to our site"</p>
</body>


This will simply output this page. 


CSS-Cascade_style_sheets-Technoob Technology


CSS easy to learn and easy to use keep practicing on it and you will be able to amazing things to your web pages including animations. 



Related Articles 





Comments

Popular posts from this blog

How to make a first person character controller - Unity

A first-person character controller script is the starting point of any fps shooter game. Even new Unity game developers tend to write their own fps controller script before learning anything else as it is challenging and very exciting. In this article, we gonna create two simple fps controllers from scratch and will guide you step by step on how it works. First, let's understand the basic concept of an fps controller. You should have a rotating camera that rotates in the x-axis to look up and down and the character should rotate on the y-axis to look around. There are two ways to create an fps controller in the Unity Engine.  Using Character controller component Using the RigidBody component Both have different advantages and disadvantages when using them. It depends on your game to select the best fps controller according to your needs.  Character controller based fps controller Pros: Is grounded check is built-in Has its own methods to move the chara

Unity Get Post web requests - Technoob Technology

Web requests in unity are super easy to use. We gonna use the UnityWebRequest class as the WWW class is deprecated now. UnityWebRequest class can be used for both Get and Post methods. The 'UnityEngine.Networking' namespace is required to work with UnityWebRequests.  This tutorial is made with some simple UI elements. First Let's see how the GET method works. 01. UnityWebRequest.GET We use this method to receive data from the server as normal get requests. Using coroutines in web requests is mandatory as we have to wait until the download is complete before showing the results, and the coroutines make this much easier. A simple button calls the method and a text element will show the result. The script contains a reference to the text element and the string URL of your PHP file.  When the button is pressed the button executes the ButtonGetData method and that method simply starts the GetData coroutine. We use the using keyword as this data

How to make an Advanced Audio Manager for Unity - Technoob Technology

Unity engine gives us a good control on audio clips we use, But the problem is when we add several audio sources for several audio clips it's gonna get hard to control them all. And if you want to make some changes to only one audio source you have to find it first.  This will become a mess if you gonna work with more than 10 audio clips. In this case, we can Create an AudioManager and include all the audio clips in it and make some static methods to play, pause the audio from other scripts. This Audio Manager is written in C# and if you use unity-script you have to convert this into unity script first. In this tutorial, we gonna create an audio manager which contains 7 methods. 1.Play 2.Pause 3.Unpause 4.Stop 5.FadeIn 6.FadeOut 7.lower volume for a duration First, we need a Custom class which contains some strings, floats, bools and an audio clip. This class is not derived from unity mono behavior so we should add [System.Serializable] to mak