logo

Very Short Question and Answers - Dimension and Layout


Q 1.
What is the purpose of the height property in CSS?

Ans:

The height property is used to set how tall an element is on a webpage.

Q 2.
Write the syntax to set the width of a div to 300 pixels.

Ans:

div {
  width: 300px;
}
Q 3.
What are the common units used with height and width properties?

Ans:

Common units include pixels (px) for fixed size, percentage (%) for relative size, and auto for default size based on content or browser decision.

Q 4.
How does the width property differ from the height property?

Ans:

Width controls the horizontal size of an element, while height controls the vertical size.

Q 5.
Explain the float property and its common values.

Ans:

The float property moves an element to the left or right, allowing other content to wrap around it. Common values are left, right, and none.

Q 6.
Give an example of CSS code that floats an image to the left.

Ans:

img {
  float: left;
}
Q 7.
What happens to text when an image is floated to the right?

Ans:

The text wraps around the image on the left side.

Q 8.
What is the default value of the float property?

Ans:

The default value is none, which means the element does not float.

Q 9.
If a div has height set to 50%, what does it mean?

Ans:

It means the div’s height will be 50% of its parent element’s height.

Q 10.
Why might setting a very small height cause problems?

Ans:

Because content inside may overflow if the height is too small to contain it.

Q 11.
Write CSS to create a div that is 300px wide, 150px tall, and floats to the right.

Ans:

div {
  width: 300px;
  height: 150px;
  float: right;
}
Q 12.
Can the height property be used with inline elements like span?

Ans:

No, height applies only to block-level elements such as div, p, h1, etc.

Q 13.
What value of height lets the browser decide the height of an element?

Ans:

The value auto allows the browser to decide the element's height automatically.

Q 14.
How does percentage (%) work when setting width or height?

Ans:

Percentage values set the size relative to the parent element’s width or height.

Q 15.
What is a common use case of the float property in Class 10 level projects?

Ans:

A common use case is floating an image so that the text wraps around it, like placing an image to the left or right in a paragraph.

Q 16.
Does float property center an element?

Ans:

No, float does not center elements; it only moves elements to the left or right.

Q 17.
Explain with an example how to set an element’s width to 80% and height to auto.

Ans:

CSS example:

selector {
  width: 80%;
  height: auto;
}

This sets the element's width to 80% of its parent and height adapts automatically based on content.

Q 18.
What effect does float: left have on images inside a paragraph?

Ans:

The image moves to the left side of the paragraph, and the paragraph text flows on the right side of the image.

Q 19.
If a div has width: 100% and height: 200px, what does it mean?

Ans:

It means the div spans the entire width of its parent container and has a fixed height of 200 pixels.

Q 20.
Why is it important to use clear values and semicolons in CSS?

Ans:

Clear values and semicolons ensure the CSS code is correctly interpreted by the browser, preventing errors and unexpected behavior.