Tuesday, July 15, 2014

How to use CSS Styles

What if we want to make styles in all the Labels in our website maybe we want to make the same style to the paragraph too so how can we do that its very easy lets do it like this :
<style type="text/css">
p
 {
Font-family:Arial;
}
Label
{
Font-family:Arial;
}
</style>

  • Do you think that was the right way sure its correct but its not dynamic if we want to make all the paragraphs and labels and maybe <h1> headers and alot alot do you think this is the best way
sure its not so whats the best way that best way is to use class and what is class its something we give it a name and then inherit this class to all objects we want to  for example :
<html>
<head>
<style type="text/css">
.myclass */ its very important to put dot before the name 
{
Font-family:Arial;
}
</head>
<body>
<p class="myclass"> helloooooo</p>
<h1 class="myclass">it has the same font family of hellooooo</h1>
<label class="myclass">and this too :) Imagine :D</label>
</body>
</html>

  • now what if we want to let only a specific element to has it unique class just like humans elements in websites can have ID too so if we give each element an ID and then in our style file say make this style available only for the element of that ID lets see this example :
      <html>
      <head>
           <style type="text/css">
       #text
      {
          padding:100px;
          font-size:20px;
          color :red;
      }
</style>
<body>
<p id="text"> hello</p> */ so only this paraghrap which has a unique ID will get that style in our css style
</body>
</html>
i hope its fine till now.
what if we want to use various classes for the same object or tag its not that complicated lets see
<html>
<head>
<style type="text/css">
p.color
{
     color: FFFFFF */white color
}
p.font
{
font-size:20%;
font-family:Romani;
}
</style>
<body>
<p class="color"> how are you guys i hope you like my lessons</p>
<p class="font">i'd love to share me your questions and i'll do my best to answer it</p>
</body>
</html>

No comments:

Post a Comment