CSS Interview Questions Flashcards Preview

Interview Questions > CSS Interview Questions > Flashcards

Flashcards in CSS Interview Questions Deck (98)
Loading flashcards...
1
Q

What are the components of a CSS Style?

A

A style rule is made of three parts −

Selector − A selector is an HTML tag at which a style will be applied. This could be any tag like <h1> or </h1> etc.

Property − A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color, border etc.

Value − Values are assigned to properties. For example, color property can have value either red or #F1F1F1 etc.

2
Q

Type selector quite simply matches the name of an element type. To give a color to all level 1 headings −

A

h1 {
color: #36CFFF;
}

3
Q

Rather than selecting elements of a specific type, the universal selector quite simply matches the name of any element type −

A
  • {
    color: #000000;
    }
    This rule renders the content of every element in our document in black.
4
Q

What is Descendant Selector?

A

Suppose you want to apply a style rule to a particular element only when it lies inside a particular element. As given in the following example, style rule will apply to <em> element only when it lies inside <ul> tag.</em>

ul em {
color: #000000;
}

</ul></em>

5
Q

What is class selector?

A

You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule.

6
Q

Can you make a class selector particular to an element type?

A

You can make it a bit more particular. For example −

h1.black {
color: #000000;
}

This rule renders the content in black for only <h1> elements with class attribute set to black.</h1>

7
Q

What is id selector?

A

You can define style rules based on the id attribute of the elements. All the elements having that id will be formatted according to the defined rule.

#black {
   color: #000000; 
}
This rule renders the content in black for every element with id attribute set to black in our document.
8
Q

Can you make a id selector particular to an element type?

A

You can make it a bit more particular. For example −

h1#black {
color: #000000;
}
This rule renders the content in black for only <h1> elements with id attribute set to black.</h1>

9
Q

What is a child selector?

A

Consider the following example −

body > p {
color: #000000;
}
This rule will render all the paragraphs in black if they are direct child of element. Other paragraphs put inside other elements like <div> or would not have any effect of this rule.</div>

10
Q

What is an attribute selector?

A

You can also apply styles to HTML elements with particular attributes. The style rule below will match all the input elements having a type attribute with a value of text −

input[type = “text”]{
color: #000000;
}
The advantage to this method is that the element is unaffected, and the color applied only to the desired text fields.

11
Q

How to select all paragraph elements with a lang attribute?

A

p[lang] : Selects all paragraph elements with a lang attribute.

12
Q

How to select all paragraph elements whose lang attribute has a value of exactly “fr”?

A

p[lang=”fr”] - Selects all paragraph elements whose lang attribute has a value of exactly “fr”.

13
Q

How to select all paragraph elements whose lang attribute contains the word “fr”?

A

p[lang~=”fr”] - Selects all paragraph elements whose lang attribute contains the word “fr”.

14
Q

How to select all paragraph elements whose lang attribute contains values that are exactly “en”, or begin with “en-“?

A

p[lang|=”en”] - Selects all paragraph elements whose lang attribute contains values that are exactly “en”, or begin with “en-“.

15
Q

What are the various ways of using CSS in an HTML page?

A

There are four ways to associate styles with your HTML document. Most commonly used methods are inline CSS and External CSS.

Embedded CSS − The Element: You can put your CSS rules into an HTML document using the element.

Inline CSS − The style Attribute: You can use style attribute of any HTML element to define style rules.

External CSS − The <link></link> Element: The <link></link> element can be used to include an external stylesheet file in your HTML document.

Imported CSS − @import Rule: @import is used to import an external stylesheet in a manner similar to the <link></link> element.

16
Q

How CSS style overriding works?

A

ollowing is the rule to override any Style Sheet Rule −

Any inline style sheet takes highest priority. So, it will override any rule defined in … tags or rules defined in any external style sheet file.

Any rule defined in … tags will override rules defined in any external style sheet file.

Any rule defined in external style sheet file takes lowest priority, and rules defined in this file will be applied only when above two rules are not applicable.

17
Q

What is the purpose of % measurement unit?

A

% - Defines a measurement as a percentage relative to another value, typically an enclosing element.

p {font-size: 16pt; line-height: 125%;}

18
Q

What is the purpose of cm measurement unit?

A

cm − Defines a measurement in centimeters.

div {margin-bottom: 2cm;}

19
Q

What is the purpose of em measurement unit?

A

em − A relative measurement for the height of a font in em spaces. Because an em unit is equivalent to the size of a given font, if you assign a font to 12pt, each “em” unit would be 12pt; thus, 2em would be 24pt.

p {letter-spacing: 7em;}

20
Q

What is the purpose of ex measurement unit?

A

ex − This value defines a measurement relative to a font’s x-height. The x-height is determined by the height of the font’s lowercase letter.

p {font-size: 24pt; line-height: 3ex;}

21
Q

What is the purpose of in measurement unit?

A

in − Defines a measurement in inches.

p {word-spacing: .15in;}

22
Q

What is the purpose of mm measurement unit?

A

mm − Defines a measurement in millimeters.

p {word-spacing: 15mm;}

23
Q

What is the purpose of pc measurement unit?

A

pc − Defines a measurement in picas. A pica is equivalent to 12 points; thus, there are 6 picas per inch.

p {font-size: 20pc;}

24
Q

What is the purpose of pt measurement unit?

A

pt − Defines a measurement in points. A point is defined as 1/72nd of an inch.

body {font-size: 18pt;}

25
Q

What is the purpose of px measurement unit?

A

px − Defines a measurement in screen pixels.

p {padding: 25px;}

26
Q

What is the purpose of vh measurement unit?

A

vh − 1% of viewport height.

h2 { font-size: 3.0vh; }

27
Q

What is the purpose of vw measurement unit?

A

vw − 1% of viewport width.

h1 { font-size: 5.9vw; }

28
Q

What is the purpose of vmin measurement unit?

A

vmin 1vw or 1vh, whichever is smaller.

p { font-size: 2vmin;}

29
Q

In how many formats can you specify a CSS color?

You can specify your color values in various formats.

A

5 -> Following table lists all the possible formats −

  • Hex code
  • Short hex code
  • RGB absolute
  • RGB %
  • Keyword
30
Q

What are browser safe colors?

A

There is the list of 216 colors which are supposed to be most safe and computer independent colors. These colors vary from hexa code 000000 to FFFFFF. These colors are safe to use because they ensure that all computers would display the colors correctly when running a 256 color palette.

31
Q

Which property is used to set the background color of an element?

A

The background-color property is used to set the background color of an element.

32
Q

Which property is used to set the background image of an element?

A

The background-image property is used to set the background image of an element.

33
Q

Which property is used to control the repetition of an image in the background?

A

The background-repeat property is used to control the repetition of an image in the background.

34
Q

Which property is used to control the position of an image in the background?

A

The background-position property is used to control the position of an image in the background.

35
Q

Which property is used to control the scrolling of an image in the background?

A

The background-attachment property is used to control the scrolling of an image in the background.

36
Q

Which property is used as a shorthand to specify a number of other background properties?

A

The background property is used as a shorthand to specify a number of other background properties.

37
Q

Which property is used to change the face of a font?

A

The font-family property is used to change the face of a font.

38
Q

Which property is used to make a font italic or oblique?

A

The font-style property is used to make a font italic or oblique.

39
Q

Which property is used to create a small-caps effect?

A

The font-variant property is used to create a small-caps effect.

40
Q

Which property is used to increase or decrease how bold or light a font appears?

A

The font-weight property is used to increase or decrease how bold or light a font appears.

41
Q

Which property is used to increase or decrease the size of a font?

A

The font-size property is used to increase or decrease the size of a font.

42
Q

Which property is used as shorthand to specify a number of other font properties?

A

The font property is used as shorthand to specify a number of other font properties.

43
Q

Which property is used to set the color of a text?

A

The color property is used to set the color of a text.

44
Q

Which property is used to set the text direction?

A

The direction property is used to set the text direction.

45
Q

Which property is used to add or subtract space between the letters that make up a word?

A

The letter-spacing property is used to add or subtract space between the letters that make up a word.

46
Q

Which property is used to add or subtract space between the words of a sentence?

A

The word-spacing property is used to add or subtract space between the words of a sentence.

47
Q

Which property is used to indent the text of a paragraph?

A

The text-indent property is used to indent the text of a paragraph.

48
Q

Which property is used to align the text of a document?

A

The text-align property is used to align the text of a document.

49
Q

Which property is used to underline, overline, and strikethrough text?

A

The text-decoration property is used to underline, overline, and strikethrough text.

50
Q

Which property is used to capitalize text or convert text to uppercase or lowercase letters?

A

The text-transform property is used to capitalize text or convert text to uppercase or lowercase letters.

51
Q

Which property is used to control the flow and formatting of text?

A

The white-space property is used to control the flow and formatting of text.

52
Q

Which property is used to set the text shadow around a text?

A

The text-shadow property is used to set the text shadow around a text.

53
Q

Which property is used to set the width of an image border?

A

The border property is used to set the width of an image border.

54
Q

Which property is used to set the height of an image?

A

The height property is used to set the height of an image.

55
Q

Which property is used to set the width of an image?

A

The width property is used to set the width of an image.

56
Q

Which property is used to set the opacity of an image?

A

The -moz-opacity property is used to set the opacity of an image.

57
Q

Which property of a hyperlink signifies unvisited hyperlinks?

A

The :link signifies unvisited hyperlinks.

58
Q

Which property of a hyperlink signifies visited hyperlinks?

A

The :visited signifies visited hyperlinks.

59
Q

Which property of a hyperlink signifies an element that currently has the user’s mouse pointer hovering over it?

A

The :hover signifies an element that currently has the user’s mouse pointer hovering over it.

60
Q

Which property of a hyperlink signifies an element on which the user is currently clicking?

A

The :active signifies an element on which the user is currently clicking.

61
Q

Which property of a table specifies whether the browser should control the appearance of the adjacent borders?

A

The border-collapse specifies whether the browser should control the appearance of the adjacent borders that touch each other or whether each cell should maintain its style.

62
Q

Which property of a table specifies the width that should appear between table cells?

A

The border-spacing specifies the width that should appear between table cells.

63
Q

Which property of a table controls the placement of the table caption?

A

The caption-side captions are presented in the element. By default, these are rendered above the table in the document. You use the caption-side property to control the placement of the table caption.

64
Q

Which property of a table specifies whether the border should be shown if a cell is empty?

A

The empty-cells specifies whether the border should be shown if a cell is empty.

65
Q

Which property of a table allows browsers to speed up layout of a table by using the first width properties?

A

The table-layout allows browsers to speed up layout of a table by using the first width properties it comes across for the rest of a column rather than having to load the whole table before rendering it.

66
Q

Which property specifies the color of a border?

A

The border-color specifies the color of a border.

67
Q

Which property specifies whether a border should be solid, dashed line, double line, or one of the other possible values?

A

The border-style specifies whether a border should be solid, dashed line, double line, or one of the other possible values.

68
Q

Which property specifies the width of a border?

A

The border-width specifies the width of a border.

69
Q

Which property specifies a shorthand property for setting the margin properties in one declaration?

A

The margin specifies a shorthand property for setting the margin properties in one declaration.

70
Q

Which property specifies the bottom margin of an element?

A

The margin-bottom specifies the bottom margin of an element.

71
Q

Which property specifies the top margin of an element?

A

The margin-top specifies the top margin of an element.

72
Q

Which property specifies the left margin of an element?

A

The margin-left specifies the left margin of an element.

73
Q

Which property specifies the right margin of an element?

A

The margin-right specifies the right margin of an element.

74
Q

Which property allows you to control the shape or appearance of the marker of a list?

A

The list-style-type allows you to control the shape or appearance of the marker.

75
Q

Which property specifies whether a long point that wraps to a second line should align with the first line or start underneath the start of the marker of a list?

A

The list-style-position specifies whether a long point that wraps to a second line should align with the first line or start underneath the start of the marker.

76
Q

Which property specifies an image rather than a bullet point or number for the marker of a list?

A

The list-style-image specifies an image for the marker rather than a bullet point or number.

77
Q

Which property serves as shorthand for the styling properties of a list?

A

The list-style serves as shorthand for the styling properties.

78
Q

Which property specifies the distance between a marker and the text in the list?

A

The marker-offset specifies the distance between a marker and the text in the list.

79
Q

Which property specifies the bottom padding of an element?

A

The padding-bottom specifies the bottom padding of an element.

80
Q

Which property specifies the top padding of an element?

A

The padding-top specifies the top padding of an element.

81
Q

Which property specifies the left padding of an element?

A

The padding-left specifies the left padding of an element.

82
Q

Which property specifies the right padding of an element?

A

The padding-right specifies the right padding of an element.

83
Q

Which property serves as shorthand for the all the padding properties of an element?

A

The padding serves as shorthand for the all the padding properties.

84
Q

Which property allows you to specify the type of cursor that should be displayed to the user?

A

The cursor property of CSS allows you to specify the type of cursor that should be displayed to the user.

85
Q

Which value of cursor property changes the cursor based on context area it is over?

A

auto − Shape of the cursor depends on the context area it is over. For example, an ‘I’ over text, a ‘hand’ over a link, and so on.

86
Q

Which value of cursor property changes the cursor to a crosshair or plus sign?

A

crosshair − A crosshair or plus sign.

87
Q

Which value of cursor property changes the cursor to an arrow?

A

default − An arrow.

88
Q

Which value of cursor property changes the cursor to a pointer?

A

pointer − A pointing hand (in IE 4 this value is hand).

89
Q

Which value of cursor property changes the cursor to the ‘I’ bar?

A

move or text − The ‘I’ bar.

90
Q

Which value of cursor property changes the cursor to the an hour glass?

A

wait − An hour glass.

91
Q

Which value of cursor property changes the cursor to a question mark?

A

help − A question mark or balloon, ideal for use over help buttons.

92
Q

Can you set an image to be shown as cursor?

A

Yes! set the url as the source of a cursor image file.

93
Q

Which property is used to set the width of the outline?

A

The outline-width property is used to set the width of the outline.

94
Q

Which property is used to set the line style for the outline?

A

The outline-style property is used to set the line style for the outline.

95
Q

Which property is used to set the color of the outline?

A

The outline-color property is used to set the color of the outline.

96
Q

Which property is used to set all the outlining properties in a single statement?

A

The outline property is used to set all the outlining properties in a single statement.

97
Q

Which property is used to set the height of a box?

A

The height property is used to set the height of a box.

98
Q

Which property is used to set the width of a box?

A

The width property is used to set the width of a box.