logo

Very Short Question and Answers - Borders and Box


Q 1.
What does the CSS property 'border-style' control?

Ans:

'border-style' specifies the type of border around an element, such as solid, dashed, dotted, double, or none.

Q 2.
List three common values of the 'border-style' property.

Ans:

Common values include solid (a single solid line), dashed (dashes instead of a line), and dotted (series of dots).

Q 3.
What is the syntax to specify a solid border around paragraph elements using 'border-style'?

Ans:

p { border-style: solid; }

Q 4.
What does the 'border-width' property specify in CSS?

Ans:

'border-width' sets how thick the border around an element will be.

Q 5.
Name two types of units that can be used with 'border-width'.

Ans:

Pixels (px) and predefined sizes like thin, medium, and thick.

Q 6.
How do you set a border width of 2 pixels for a div element?

Ans:

div { border-width: 2px; }

Q 7.
What type of values can be used for the 'border-color' property?

Ans:

Named colors (like red, blue), hex values (e.g., #ff0000), and RGB values (e.g., rgb(0, 0, 0)).

Q 8.
How can you set a blue border color to an h1 element in CSS?

Ans:

h1 { border-color: blue; }

Q 9.
Explain what the following CSS does: p { border-style: solid; border-width: 2px; border-color: red; }

Ans:

It creates a 2px thick red solid border around all paragraph elements.

Q 10.
Define the 'margin' property in CSS.

Ans:

'margin' is the space outside the border of an element and controls the distance between elements.

Q 11.
What units can be used with the 'margin' property?

Ans:

Pixels (px), em, percentages (%), and the keyword 'auto' which lets the browser decide the margin.

Q 12.
In the margin shorthand property 'margin: 10px 20px 30px 40px;', what does each value represent?

Ans:

The order is top (10px), right (20px), bottom (30px), and left (40px).

Q 13.
What does the CSS 'padding' property define?

Ans:

'padding' defines the space inside the border, between the content and the border.

Q 14.
Why is padding important in designing webpage elements?

Ans:

Padding increases space around text inside a box, making content easier to read.

Q 15.
What is the main difference between margin and padding?

Ans:

Margin is the space outside the border creating distance between elements, while padding is the space inside the border creating space between content and border.

Q 16.
Does margin affect the size of an element? Explain.

Ans:

No, margin does not affect the element's size; it only creates space outside the element.

Q 17.
What is the 'outline' property in CSS and how does it differ from border?

Ans:

'Outline' draws a line outside the border and does not take up space or affect the layout, unlike border which is part of the box model and affects element size.

Q 18.
Provide an example of a CSS 'outline' property with dashed style, 2px width, and blue color applied to paragraphs.

Ans:

p { outline: dashed 2px blue; }

Q 19.
In the box model, which property increases the total box size: margin or padding?

Ans:

Padding increases the total box size, while margin does not.

Q 20.
Interpret this CSS block: div { border-style: solid; border-width: 3px; border-color: green; padding: 15px; margin: 20px; outline: dashed 2px red; }

Ans:

The div has a green solid border 3px thick, with 15px padding (space between content and border), 20px margin (space outside the border), and a red dashed outline 2px thick outside the border.