সিএসএস কিভাবে… (CSS How To…)

যখন একটি ব্রাউজার স্টাইল শীট পরে, এটি স্টাইল শীট এর তথ্য অনুসারে ডকুমেন্টকে ফরমেট করে।

সিএসএস প্রবেশ করানোর তিনটি উপায় আছে

  • বহিস্থিত স্টাইল শীট
  • অন্তস্থিত স্টাইল শীট
  • ইনলাইন স্টাইল

 

বহিস্থিত স্টাইল শীট

বহিস্থিত স্টাইল শীট দিয়ে, মাত্র একটি ফাইল পরিবর্তনের মাধ্যমে ওয়েব সাইটের চেহারা পরিবর্তন করে ফেলতে পারবেন।

প্রতিটি পেজের <link> এলিমেন্ট এর মধ্যে অবশ্যই বহিস্থিত স্টাইল শীটের একটি রেফারেন্স দিয়ে দিতে হবে। <link> এলিমেন্ট হেড সেকশন এর মধ্যে লিখতে হবেঃ


 <head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

 

বহিস্তিত স্টাইল শীট যেকোন টেক্স্ট এডিটর এ লেখা যেতে পারে। এই ফাইলে কোন এইচটিএমএল ট্যাগ থাকতে পারবে না। স্টাইল শীট ফাইলটি অবশ্যই .css এক্সটেনশন দিয়ে সেভ করতে হবে।

“myStyle.css” নামের একটি স্টাইল শীটে ফাইলের উদাহরণ দেয়া হলোঃ


body {
    background-color: lightblue;
}

h1 {
    color: navy;
    margin-left: 20px;
}

নোটঃ প্রোপার্টি মান এবং ইউনিট এর মধ্যে কোন স্পেস দিবেন না (যেমন margin-left: 20 px;)। সঠিক পদ্ধতি হচ্ছে margin-left: 20px;

 

অন্তস্থিত স্টাইল শীট

যদি একটি নির্দিষ্ট পেজ এর স্টাইল ইউনিক (অনন্য) হয় তাহলে অন্তস্থিত স্টাইল শীট ব্যবহার করা হয়।

অন্তস্থিত স্টাইল শীট হেড সেকশন এর <style> এলিমেন্ট এর মাঝে লেখা হয়।


 <head>
<style>
body {
    background-color: linen;
}

h1 {
    color: maroon;
    margin-left: 40px;
}
</style>
</head>

 

ইনলাইন স্টাইল

ইনলাইন স্টাইল মাত্র একটি এলিমেন্ট এর উপর অনন্য স্টাইল প্রয়োগ করতে ব্যবহৃত হয়।

একটি ইনলাইন স্টাইল স্টাইল শীটের অনেক সবিধা গ্রহণ করা থেকে বঞ্চিত হয়। সংযতভাবে এই পদ্ধতি ব্যবহার করুন।

ইনলাইন স্টাইল ব্যবহার করার জন্য কাঙ্খিত ট্যাগ এর সাথে স্টাইল এট্রিবিউট যোগ করুন। স্টাইল এট্রিবিউট যেকোন সিএসএস প্রোপার্টি ধারণ করতে পারে। নিচের উদাহরণে <h1> এলিমেন্ট এর রঙ এবং বাম মার্জিন কিভাবে পরিবর্তন করা যায় তা দেখানো হলোঃ


 <h1 style="color:blue;margin-left:30px;">This is a heading.</h1>

 

একাধিক স্টাইল শীট

যদি কিছু প্রোপার্টি ভিন্ন স্টাইল শটের একই সিলেক্টর দ্বারা নির্ধারিত হয় তাহলে মানগুলো একত্রিত হয়ে আরো সুনির্ধিষ্ট হয়।

উদাহরণ স্বরুপ, একটি বহিস্থিত স্টাইল শটি এর <h1> এলিমেন্ট নিম্নোক্ত প্রোপার্টি রয়েছে:


h1 {
    color: navy;
    margin-left: 20px;
}

 

একটি অন্তস্থিত স্টাইল শীটেরও <h1> এলিমেন্ট এর নিম্নোক্ত প্রোপার্টি রয়েছে:


h1 {
    color: orange;   
}

 

যদি পেজটির অন্তস্থিত স্টাইল শীটের সাথে বহিস্থিত স্টাইল শীট সংযুক্ত থাকে তাহলে <h1> এলিমেন্ট এর প্রোপার্টি হবে:


color: orange;
margin-left: 20px;

বাম মার্জিনটি বহিস্থিত স্টাইল শীটের সাথে মিলিত হয়েছে এবং রঙ অন্তস্থিত স্টাইল শীটের অনুরূপ পরিবর্তিত হয়েছে।

 

একাধিক স্টাইল একটির মধ্যে ক্যাসকেড করবে

স্টাইল নির্ধারণ করা যেতে পারে:

  • একটি বহিস্থিত স্টাইল ফাইলের মধ্যেে
  • এইচটিএমএল পেজ এর <head> সেকশন এর মাঝেে
  • এইচটিএমএল এলিমেন্ট এর মাঝে

ক্যাসকেড ক্রম

এইচটিএমএল এলিমেন্ট এর জন্য একের অধিক স্টাইল ব্যবহার করা হলে কোন স্টাইলটি ব্যবহৃত হবে?

সাধারণভাবে বলা যায়, নিম্নোক্ত নিয়ম অনুসরণ করে সকল স্টাইল একটি নতুন ভার্চুয়্যাল স্টাইল শীটের মধ্যে ক্যাসকেড করবে যেখানে তৃতীয় নিয়মটি সর্বোচ্চ গুরুত্ব পাবে:

  1. ব্রাউজার ডিফল্ট
  2. বহিস্থিত এবং অন্তস্থিত স্টাইল শীট (হেড সেকশনের মাঝে)
  3. ইনলাইন স্টাইল (এইচটিএমএল এলিমেন্ট এর ভিতরে)

সুতরাং, একটি ইনলাইন স্টাইল (এইচটিএমএল এলিমেন্ট এর ভিতরে) সর্বোচ্চ গুরুত্ব পাবে, যার মানে হচ্ছে <head> ট্যাগ বা বহিস্থিত স্টাইল শীট বা ব্রাউজার এ নির্ধারিত মান এর মান ধারণকারী।

নোটঃ যদি বহিস্তিত স্টাইল শীট এর লিঙ্ক অন্তস্থিত স্টাইল শীট এর  এইচটিএমএল <head> এর নিচে অবস্থান করে, তাহলে বহিস্তিত স্টাইল শীট অন্তস্থিত স্টাইল শীটকে ওভাররাইড করবে।

 

নিজে নিজে চেষ্টা করো

 

অনুশীলন ০১ঃ

“mystyle.css” নামক বহিস্থিত স্টাইল শীট যোগ করো


 

<!DOCTYPE html>
<html>
<head>

</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>

 

 

অনুশীলন ০২ঃ

অন্তস্থিত স্টাইল শীট ব্যবহার করে পেজ এর “background-color: linen” নির্ধারণ করোঃ


 

<!DOCTYPE html>
<html>
<head>

</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>

 

 

অনুশীলন ০৩ঃ

ইনলাইন স্টাইল শীট ব্যবহার করে পেজ এর “background-color: linen” নির্ধারণ করোঃ


 

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>

 

অনুশীলন ০৪ঃ

বহিস্থিত স্টাইল শীট “mystyle.css” ব্যতীত সকল স্টাইল মুছে ফেলঃ


 

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
p {
    color: red;
}
</style>
</head>
<body style="background-color: lightcyan">

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>

 

 

 

সিএসএস ইমেজ গ্যালারী (CSS Image Gallery)

সি এস এস এ তৈরি ইমেজ গ্যালারী

Klematis

Add a description of the image here

Klematis

Add a description of the image here

Klematis

Add a description of the image here

Klematis

Add a description of the image here

 

 

 

 

 

 

 

উদাহরণঃ


<head>
<style>
div.img {
    margin: 5px;
    padding: 5px;
    border: 1px solid #0000ff;
    height: auto;
    width: auto;
    float: left;
    text-align: center;
}

div.img img {
    display: inline;
    margin: 5px;
    border: 1px solid #ffffff;
}

div.img a:hover img {
    border:1px solid #0000ff;
}

div.desc {
    text-align: center;
    font-weight: normal;
    width: 120px;
    margin: 5px;
}
</style>
</head>
<body>

<div class="img">
  <a target="_blank" href="klematis_big.htm">
    <img src="klematis_small.jpg" alt="Klematis" width="110" height="90">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>
<div class="img">
  <a target="_blank" href="klematis2_big.htm">
    <img src="klematis2_small.jpg" alt="Klematis" width="110" height="90">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>
<div class="img">
  <a target="_blank" href="klematis3_big.htm">
    <img src="klematis3_small.jpg" alt="Klematis" width="110" height="90">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>
<div class="img">
  <a target="_blank" href="klematis4_big.htm">
    <img src="klematis4_small.jpg" alt="Klematis" width="110" height="90">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>

</body>
</html>

 

Balsamic/বালসামিক – ওয়েব সাইট মকআপ টুল এর উপর ধারণা । Balsamic Wire Framing Tool Overview

Balsamic/বালসামিক – ওয়েব সাইট মকআপ টুল এর উপর ধারণা । Balsamic Wire Framing Tool Overview

মুডল এর Backend বৈশিষ্ট্য । Moodle backend features and options for site administration

Moodle backend features and options for site administration

JavaScript Code

                var browser=navigator.appName;
                var b_version=navigator.appVersion;



<a href="http://www.justetc.net" target="_blank">
<img border="0" alt="hello" src="b_pink.gif" id="b1" width="26" height="26" onmouseover="mouseOver()" onmouseout="mouseOut()" />



Place the following code under script tag/in a javascript file

function mouseOver()
{
   document.getElementById("b1").src ="b_blue.gif";
}

function mouseOut()
{
   document.getElementById("b1").src ="b_pink.gif";
}






<map name="planetmap">

<area shape ="rect" coords ="0,0,82,126"
onMouseOver="writeText('You are over the target area')"
href ="target.htm" target ="_blank" alt="target" />

var t1=setTimeout("document.getElementById('id1').value='2 seconds!'",2000);
var t2=setTimeout("document.getElementById('id1').value='4 seconds!'",4000);
var t3=setTimeout("document.getElementById('id1').value='6 seconds!'",6000);

Direct Instance: 

pObj=new Object();
pObj.firstname="John";
pObj.lastname="Doe";
pObj.age=50;
pObj.eyecolor="blue";

document.write(pObj.firstname + " is " + pObj.age + " years 

function car(brand,make,model)
{
this.brand=brand;
this.make=make;
this.model=model;
}
var myCar=new car("Honda","2009","Accord");
document.write(myCar.brand +  myCar.make + myCar.model );

try
{
}
catch(err)
{
}


Under script tag/javascript file:

onerror=handleErr;
var alertTxt = "" 

function handleErr(msg, url, l)
{
   alertTxt = "Error Information:.\n\n";
   alertTxt += msg + "\n";
   alertTxt += url + "\n";
   alertTxt += l + "\n\n";
   alertTxt += "Click OK to continue.\n\n";
   alert(alertTxt);
   return true;
}


var x;
var myFriends= new Array();
myFriends[0] = "Shafiq";
myFriends[1] = "Rafiq";
myFriends[2] = "Abba";
myFriends[3] = "Amma";

for (x in myFriends)
{
   document.write(myFriends[x] + "
");
}


var d = new Date();
theDay=d.getDay();
switch (theDay)
{
case 5:
  document.write("Friday");
  break;
case 6:
  document.write("Saturday");
  break;
case 0:
  document.write("Sunday");
  break;
}

   var pattern = new RegExp("e","g");
   do
   {
     result=pattern .exec("This is the line where the regular expression will be searched on");
     document.write(result);
   }
   while (result!=null)

JavaScript Form Validation: Validate a Form Collecting Credit Card Information

    function validateCollectPaymentInformationForm()
    {
        var method, name, number, expiry, errMsg
        
        errMsg = "";
        
        method = document.getElementById('paymentMethod');
        name =   document.getElementById('txtCCName');
        number = document.getElementById('txtCCNumber');
        
        if (method.value == "" || method.value == "0" || method.value == null){
            
            errMsg = "Please select a payment method \n";
            
            
        }
        
        if (name.value == "" || name.value == null){
            
            errMsg = errMsg + 'Please write down your name  \n';
            
            
        }
        
        if (number.value == "" || number.value == null){
            
            errMsg = errMsg + 'Please provide credit card number  \n';
                
        }else if (number.value.length < 16 ){
            errMsg = errMsg + 'Invalid credit card number  \n';
        }
        
        
        
        if (errMsg.length > 0 ){
            alert(errMsg);
            method.focus();
            return false;            
        }else{        
            return true;
        }        
        return false;    
    }


    function validateCollectPaymentInformationForm()
    {
        var method, name, number, expiry, errMsg
        
        
        
        method = document.getElementById('paymentMethod');
        name =   document.getElementById('txtCCName');
        number = document.getElementById('txtCCNumber');
        
        if (method.value == "" || method.value == "0" || method.value == null){
            alert('Please select a payment method');
            method.focus();
            return false;
            
        }
        
        if (name.value == "" || name.value == null){
            alert('Please write down your name');            
            name.focus();
            return false;
            
        }
        
        if (number.value == "" || number.value == null){
            alert('Please provide credit card number');            
            number.focus();
            return false;            
        }else if (number.value.length < 16 ){
            alert('Invalid card number');            
            number.focus();
            return false;    
        }
        
        
            
        return true;
    }

Print three-dimensional valarray line-by-line

/* The following code example is taken from the book
 * "The C++ Standard Library - A Tutorial and Reference"
 * by Nicolai M. Josuttis, Addison-Wesley, 1999
 *
 * (C) Copyright Nicolai M. Josuttis 1999.
 * Permission to copy, use, modify, sell and distribute this software
 * is granted provided this copyright notice appears in all copies.
 * This software is provided "as is" without express or implied
 * warranty, and with no claim as to its suitability for any purpose.
 */
#include <iostream>
#include <valarray>
using namespace std;

// print three-dimensional valarray line-by-line
template<class T>
void printValarray3D (const valarray<T>& va, int dim1, int dim2)
{
    for (int i=0; i<va.size()/(dim1*dim2); ++i) {
        for (int j=0; j<dim2; ++j) {
            for (int k=0; k<dim1; ++k) {
                cout << va[i*dim1*dim2+j*dim1+k] << ' ';
            }
            cout << '\n';
        }
        cout << '\n';
    }
    cout << endl;
}

int main()
{
    /* valarray with 24 elements
     * - two groups
     * - four rows
     * - three columns
     */
    valarray<double> va(24);

    // fill valarray with values
    for (int i=0; i<24; i++) {
        va[i] = i;
    }

    // print valarray
    printValarray3D (va, 3, 4);

    // we need two two-dimensional subsets of three times 3 values
    // in two 12-element arrays
    size_t lengthvalues[] = {  2, 3 };
    size_t stridevalues[] = { 12, 3 };
    valarray<size_t> length(lengthvalues,2);
    valarray<size_t> stride(stridevalues,2);

    // assign the second column of the first three rows
    // to the first column of the first three rows
    va[gslice(0,length,stride)]
        = valarray<double>(va[gslice(1,length,stride)]);

    // add and assign the third of the first three rows
    // to the first of the first three rows
    va[gslice(0,length,stride)]
        += valarray<double>(va[gslice(2,length,stride)]);

    // print valarray
    printValarray3D (va, 3, 4);
}

/*
0 1 2
3 4 5
6 7 8
9 10 11

12 13 14
15 16 17
18 19 20
21 22 23


3 1 2
9 4 5
15 7 8
9 10 11

27 13 14
33 16 17
39 19 20
21 22 23



 */

C++ Template Example

/* The following code example is taken from the book
 * "The C++ Standard Library - A Tutorial and Reference"
 * by Nicolai M. Josuttis, Addison-Wesley, 1999
 *
 * (C) Copyright Nicolai M. Josuttis 1999.
 * Permission to copy, use, modify, sell and distribute this software
 * is granted provided this copyright notice appears in all copies.
 * This software is provided "as is" without express or implied
 * warranty, and with no claim as to its suitability for any purpose.
 */

#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <numeric>

using namespace std;

/* PRINT_ELEMENTS()
 * - prints optional C-string optcstr followed by
 * - all elements of the collection coll
 * - separated by spaces
 */
template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
{
    typename T::const_iterator pos;

    std::cout << optcstr;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {
        std::cout << *pos << ' ';
    }
    std::cout << std::endl;
}

/* INSERT_ELEMENTS (collection, first, last)
 * - fill values from first to last into the collection
 * - NOTE: NO half-open range
 */
template <class T>
inline void INSERT_ELEMENTS (T& coll, int first, int last)
{
    for (int i=first; i<=last; ++i) {
        coll.insert(coll.end(),i);
    }
}



// return whether the second object has double the value of the first
bool doubled (int elem1, int elem2)
{
   return elem1 * 2 == elem2;
}

int main()
{
   vector<int> coll;

   coll.push_back(1);
   coll.push_back(3);
   coll.push_back(2);
   coll.push_back(4);
   coll.push_back(5);
   coll.push_back(5);
   coll.push_back(0);

   PRINT_ELEMENTS(coll,"coll: ");

   // search first two elements with equal value
   vector<int>::iterator pos;
   pos = adjacent_find (coll.begin(), coll.end());

   if (pos != coll.end()) {
       cout << "first two elements with equal value have position "
            << distance(coll.begin(),pos) + 1
            << endl;
   }

}

/*
coll: 1 3 2 4 5 5 0
first two elements with equal value have position 5

 */

Javascript : Miscellaneous Code

                var browser=navigator.appName;
                var b_version=navigator.appVersion;



<a href="http://www.justetc.net" target="_blank">
<img border="0" alt="hello" src="b_pink.gif" id="b1" width="26" height="26" onmouseover="mouseOver()" onmouseout="mouseOut()" />



Place the following code under script tag/in a javascript file

function mouseOver()
{
   document.getElementById("b1").src ="b_blue.gif";
}

function mouseOut()
{
   document.getElementById("b1").src ="b_pink.gif";
}






<map name="planetmap">

<area shape ="rect" coords ="0,0,82,126"
onMouseOver="writeText('You are over the target area')"
href ="target.htm" target ="_blank" alt="target" />

var t1=setTimeout("document.getElementById('id1').value='2 seconds!'",2000);
var t2=setTimeout("document.getElementById('id1').value='4 seconds!'",4000);
var t3=setTimeout("document.getElementById('id1').value='6 seconds!'",6000);

Direct Instance: 

pObj=new Object();
pObj.firstname="John";
pObj.lastname="Doe";
pObj.age=50;
pObj.eyecolor="blue";

document.write(pObj.firstname + " is " + pObj.age + " years 

function car(brand,make,model)
{
this.brand=brand;
this.make=make;
this.model=model;
}
var myCar=new car("Honda","2009","Accord");
document.write(myCar.brand +  myCar.make + myCar.model );

try
{
}
catch(err)
{
}


Under script tag/javascript file:

onerror=handleErr;
var alertTxt = "" 

function handleErr(msg, url, l)
{
   alertTxt = "Error Information:.\n\n";
   alertTxt += msg + "\n";
   alertTxt += url + "\n";
   alertTxt += l + "\n\n";
   alertTxt += "Click OK to continue.\n\n";
   alert(alertTxt);
   return true;
}


var x;
var myFriends= new Array();
myFriends[0] = "Shafiq";
myFriends[1] = "Rafiq";
myFriends[2] = "Abba";
myFriends[3] = "Amma";

for (x in myFriends)
{
   document.write(myFriends[x] + "
");
}


var d = new Date();
theDay=d.getDay();
switch (theDay)
{
case 5:
  document.write("Friday");
  break;
case 6:
  document.write("Saturday");
  break;
case 0:
  document.write("Sunday");
  break;
}

   var pattern = new RegExp("e","g");
   do
   {
     result=pattern .exec("This is the line where the regular expression will be searched on");
     document.write(result);
   }
   while (result!=null)

Example demonstrating the use of packages

&&&&&&&&&&&&&&&&&&&
Example demonstrating the use of packages.

    * Class1.java defined in package1.
    * Class2.java defined in package2.
    * Class3.java defined in package2.package3.
    * Class1.java defined in package4.
    * PackageExample.java Driver for package example
&&&&&&&&&&&&&&&&&&&&&
~~~~~~~~~~~~~~~~~~~~~
Class1.java defined in package1.
~~~~~~~~~~~~~~~~~~~~~
package package1;

*****************
 
public class Class1 {
  public static void printInfo() {
    System.out.println("This is Class1 in package1.");
  }
}
&&&&&&&&&&&&&&&&&&&&&
~~~~~~~~~~~~~~~~~~~~~
Class2.java defined in package2. 
~~~~~~~~~~~~~~~~~~~~~
package package2;
$$$$$$$$$$$$$$$$

public class Class2 {
  public static void printInfo() {
    System.out.println("This is Class2 in package2.");
  }
}
&&&&&&&&&&&&&&&&&&&&&&
~~~~~~~~~~~~~~~~~~~~~~
Class3.java defined in package2.package3
~~~~~~~~~~~~~~~~~~~~~~
package package2.package3;

@@@@@@@@@@@@@@@@@@@@@@@@@

public class Class3 {
  public static void printInfo() {
    System.out.println("This is Class3 in " +
                       "package2.package3.");
  }
}
&&&&&&&&&&&&&&&&&&&&&&&&&
~~~~~~~~~~~~~~~~~~~~~~~~~
Class1.java defined in package4.
~~~~~~~~~~~~~~~~~~~~~~~~~
package package4;

@@@@@@@@@@@@@@@@

public class Class1 {
  public static void printInfo() {
    System.out.println("This is Class1 in package4.");
  }
}
&&&&&&&&&&&&&&&&&&&&&&&&&&
~~~~~~~~~~~~~~~~~~~~~~~~~~
PackageExample.java Driver for package example.
~~~~~~~~~~~~~~~~~~~~~~~~~~
import package1.*;
import package2.Class2;
import package2.package3.*;

***************************

public class PackageExample {
  public static void main(String[] args) {
    Class1.printInfo();
    Class2.printInfo();
    Class3.printInfo();
    package4.Class1.printInfo();
  }
}
****************************