CSS

CSS Subjective Questions And Answers

More interview questions and answers

How to set CSS font?

 We can set the CSS font by using them.

Example:

<html>

<head>

<style type=\"text/css\">

h3 {font-family: arial}

p {font-family: courier

    font-weight: bold;}

p.sansserif {font-family: sans-serif}

</style>

</head>

<body>

<h3>This is my third header</h3>

<p>Write here a paragraph</p>

<p class=\"sansserif\">Write here a paragraph</p>

</body>

</html>

How to set background with CSS?

 Using the background of CSS we can changed the background effect of element. 

Example:

<html>

<head>

<style type=\"text/css\">

body {background-color: yellow}

h1 {background-color: #00ff00}

h2 {background-color: transparent}

p {background-color: rgb(250,0,255)}

</style>

</head>

<body>

<h1>This is my first header</h1>

<h2>This is my second header</h2>

<p>This is our paragraph</p>

</body>

</html>

How you define CSS Padding?

 Using CSS Padding we can set the spaces between the border and element.The top, right, bottom and left padding can be changed independently using separate properties.

Example:

<html>

<head>

<style type=\"text/css\">

td.test1 {padding: 2.0cm}

td.test2 {padding: 1.0cm 3.5cm}

</style>

</head>

<body>

<table border=\"1\">

<tr>

<td class=\"test1\">

This tablecell use equal padding on each side.

</td>

</tr>

</table>

<br />

<table border=\"1\">

<tr>

<td class=\"test2\">

This tablecell has a top and bottom padding of 1cm and a left and right padding of 3.5cm.

</td>

</tr>

</table>

</body>

</html>

How you define at-rule in CSS?

 We use at-rule in CSS by using \'@\' character.I have given below some at-rules of CSS are,
Example:\'@import\',\'@page\'. 

Tell me about types of CSS rule?

 CSS rule are of three types.These are,

HTML Selector
class
ID.

How you define CSS?

 CSS is stands for Cascading Style Sheets.Where as style is used to show how HTML elements looks like.We use style with in the Style Sheets.We use style in HTML 4.We stored External Style Sheets in CSS. 

Syntax:

selector {property: value}

How we use CSS?

I have given a basic syntax of CSS.

selector {property: value}

CSS Syntax consist of three parts.These are: Selector,their property and value.

Selector is not other than HTML tags or element.We seperate property with their value by an colon(:) which is surrounded by curly braces.

Example:

body {color: red}

Using above we set the body color red.

 If we want to write mutiple words.Than we can write those with in the double quotes(\").

p {font-family: \"Rajesh Kumar\"}

You can also use the more than one property togather by  only seperated with semicolon(;).

p {text-align:left;color:yellow;font-family: arial}

         \'OR\'

p

{

text-align: center;

color: black;

font-family: arial

}

How you define grouping in CSS?

Grouping means that we can combine more than one selector like group.These selector are separated with comma(,). I have given you a example how to group the selector.


Example:

h1,h2,h3,h4

{

   color: red

}

How you define class Selector?

 Using class Selector we can set the  different style for same type HTML element.Below, I have shown three paragraphs.Where each paragraph have different align.

Example:

p.right {text-align: right}

p.center {text-align: center}

p.left {text-align: left}

 Now,I tell you how to use them,

<p class=\"right\">

This paragraph is right-aligned.

</p>

<p class=\"center\">

This paragraph is center-aligned.

</p>

<p class=\"left\">

This paragraph is left-aligned.

</p>

How you define id Selector?

Using id selector we can set the style for HTML elements.We set id selector as #.

Below,I have shows you how to use id selector.

#green {color: yellow}

Where, yellow is called as value of an id attribute.

How to set CSS comment?

Generally, We use comment when we want ro say something about code.We can also also use as reminder means using comment get some main information about code.

We write comment inside these /* and */.

Example:

/* Here write your comment */

p

{

text-align: left;

/* here you can write some other comment */

color: green;

font-family: arial

}

How you insert Style Sheet in the HTML document?

 I have given you three ways using them you can insert the Style Sheet on HTML page.

1.External Style Sheet

2.Internal Style Sheet

3.Multiple Style Sheet

External Style Sheet: We use external syle sheet when we apply style on many pages.Because using them if we change the style sheet of one page than other page associated with them are automatically changed.Like that using them we can change the style of whole website with only change on one page.

 We link these pages by using <link> tag.

Example:

<head>

<link rel=\"stylesheet\" type=\"text/css\"

href=\"firststylesheet.css\" />

</head>

than our page will change definition of firststylesheet.css file.

Internal Style Sheet: Using internal style sheet we can set the unique style to a single document.We use internal with <style> tag.

<head>

<style type=\"text/css\">

hr {color: yellow}

p {margin-center: 10px}

body {background-image: url(\"image.gif\")}

</style>

</head>

Inline Styles: Using inline style we can set the style of occurrence of an element.This stylesheet applied on a particular element.

 In this example I have shown you how to the color and the left margin of a paragraph: 

Example:

<p style=\"color: sienna; margin-center: 10px\">

inline style is applied on this paragraph.


Multiple Style Sheets: Suppose that if we set properties for same selector in different style sheet.Than using multiple style sheet we can set the value of this selector with more specific style sheet.

Example:

 Here,I set the property of h1 by using external style sheet.

h1 

{

color: yellow;

text-align: left;

font-size: 10pt

}

If I set the properties of h1 with internal style sheet.

h1 

{

text-align: right; 

font-size: 20pt

}

If we links internal style sheet with the external style sheet than the properties for h1 will be:

color: yellow; 

text-align: right; 

font-size: 20pt

In this color is inherited from the external style sheet and the text-alignment and the font-size is changed by internal style sheet.


How to create CSS Border?

 Using CSS Border we can set the border around a text.

Example:

<html>

<head>

<style type=\"text/css\">

{

border: medium double rgb(250,0,255)

}

</style>

</head>

<body>

<p>write here some text</p>

</body>

</html>


How to set CSS Outlines?

 Using CSS Outlines we can set the outlines around the some text.

Example:

<html>

<head>

<style type=\"text/css\">

p

{

border: green solid thin;

}

p.dotted {outline-style: dotted}

p.dashed {outline-style: dashed}

p.solid {outline-style: solid}

p.double {outline-style: double}

p.groove {outline-style: groove}

p.ridge {outline-style: ridge}

p.inset {outline-style: inset}

p.outset {outline-style: outset}

</style>

</head>

<body>

<p class=\"dotted\">A dotted outline</p>


<p class=\"dashed\">A dashed outline</p>


<p class=\"solid\">A solid outline</p>


<p class=\"double\">A double outline</p>


<p class=\"groove\">A groove outline</p>


<p class=\"ridge\">A ridge outline</p>


<p class=\"inset\">An inset outline</p>


<p class=\"outset\">An outset outline</p>

</body>

</html>

How you define CSS Margin?

 Using CSS Margin we can set the spaces around the elements. 

<html>

<head>

<style type=\"text/css\">

p.margin {margin: 3cm 5cm 4cm 5cm}

</style>

</head>

<body>

<p>In this paragraph we not set any margins</p>

<p class=\"margin\">This paragraph we set margins </p>

<p>In this paragraph we not set any margins</p>

</body>

</html>

How you define relationships b/w CSS and HTML?

 Using HTML we can create web pages.When we attach HTML with CSS than it may modify the design,page content,color,buttons etc on the HTML page.

How you define CSS,CSS2 and CSS3?

 If we create superset of CSS, CSS2 than they have contain a number of new capabilities like absolute, relative, and fixed positioning of elements, the concept of media types, support for aural style sheets and bidirectional text, and new font properties such as shadows.

 CSS3 is currently under development. The W3C maintains a CSS3 progress report. CSS3 is modularized and will consist of several separate recommendations.

 

How you define floating element in CSS?

 You can float the HTML element by using CSS.

Example:

To set a DIV element or text/image inside an HTML element

How you define ruleset inCSS?

 CSS syntax is a combination of a selector,a property and with a value.

Syntax:

Selector {property: value}

Selector is a HTML element/tag.

Property is the attribute. 

 We seperated properties and their values by using colon(:).

Example:

body {color: yellow}



 

How you define First-line pseudo-element in CSS?

 We use first line pseudo element display the first line of a text in selector with some special style.

Syntax:

selector:pseudo-element {property: value}

What are the advantages of CSS?

 The main advantage of CSS are given below:

1.Using them we can increase the downloading speed of web page.

2.Using CSS we can represent the content different from styles. 

Is CSS case-sensitive or not?

 No

CSS is not case-sensitive.But it may be different for specific browsers.But font,Url etc are case-sensitive.

Example:

div.myclass { ...}

div.myClass { ... }

CSS Subjective Questions And Answers