logo

Very Short Question and Answers - Alignment and Display


Q 1.
What is the purpose of the text-align property in CSS?

Ans:

The text-align property is used to set the horizontal alignment of text inside an element such as paragraphs, headings, or divs.

Q 2.
Which types of content does the text-align property affect?

Ans:

The text-align property affects inline content including text, inline elements, and inline-block elements.

Q 3.
What is the default text alignment value for most web pages?

Ans:

The default text alignment for most web pages is left.

Q 4.
List the common values of the text-align property.

Ans:

The common values of text-align are left, right, center, and justify.

Q 5.
Explain what the justify value of text-align does.

Ans:

The justify value stretches text so that all lines have equal width, creating clean aligned edges on both left and right sides.

Q 6.
Give an example of when you might use center alignment in text-align.

Ans:

Center alignment can be used for headings to make them stand out and look balanced.

Q 7.
How would you align a date or signature using text-align?

Ans:

You would use text-align: right to align dates or signatures to the right side.

Q 8.
What is the purpose of the float property in CSS?

Ans:

The float property is used to place an element to the left or right of its container, allowing other content to wrap around it.

Q 9.
Name two common uses of the float property.

Ans:

Float is commonly used for placing images beside text and creating basic layouts.

Q 10.
What are the common values of the float property?

Ans:

The common values of float are left, right, none, and inherit.

Q 11.
What happens to other content when an element is floated using float: left or float: right?

Ans:

Other content such as text or inline elements wraps around the floated element.

Q 12.
How can multiple elements be placed side by side using float?

Ans:

By applying float: left or float: right to multiple block elements with defined widths and margins, they will align horizontally side by side.

Q 13.
What is the purpose of the clear property in CSS in relation to float?

Ans:

The clear property is used to stop elements from wrapping around floated elements, effectively clearing the float.

Q 14.
Which value of clear stops wrapping from both left and right floated elements?

Ans:

clear: both stops wrapping from both left and right floated elements.

Q 15.
When should the clear: both style be used in a webpage layout?

Ans:

It should be used after floated elements to ensure the following content starts below floated sections rather than wrapping around them.

Q 16.
If no float property is applied, what is the default behavior of an element?

Ans:

By default, float is none, meaning the element is positioned according to normal document flow without floating.

Q 17.
How can floating images improve webpage design?

Ans:

Floating images left or right allows text to wrap around them neatly, making the content more visually appealing and better organized.

Q 18.
What is the difference between text-align and float properties?

Ans:

Text-align controls the horizontal alignment of inline text inside an element, while float moves an entire element left or right so other content can wrap around it.

Q 19.
Can float be used to create multi-column layouts? If yes, how?

Ans:

Yes, float: left or float: right on multiple block elements with set widths can create simple two-column or multi-column layouts.

Q 20.
Why is it important to clear floats after using float in CSS?

Ans:

Clearing floats prevents subsequent elements from wrapping around floated elements, maintaining the intended page structure and layout.