M2- Text alignment Flashcards

1
Q

Which CSS property do you use to align text?

A

text-align: Text alignment can be set to left, right, center and justify.

EXAMPLE:
p {
text-align: center;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between text alignment and HTML element alignment in CSS?

A

Text alignment is straightforward and handled with the text-align property. HTML element alignment is more complex because it involves the box model and document flow. Aligning an HTML element requires changing its box model properties and understanding how it interacts with the document flow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you center-align an HTML element in CSS?

A

To center-align an HTML element:

1) Set a width on the element.
2) Set the element’s margin property to auto.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you center-align an inline element like an img in CSS?

A

To center-align an inline element like an img, you must first change it to a block-level element and then set its margins to auto. For example:
HTML
< div class=”parent”>
< img src=”photo.png” class=”child”>
< /div>

CSS
.child {
display: block;
width: 50%;
margin: auto;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you be more precise with margin settings when centering elements?

A

You can set only the left and right margins to auto while specifying specific values for the top and bottom margins. For example:
.child {
display: block;
width: 50%;
margin-left: auto;
margin-right: auto;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you left or right align elements using CSS?

A

The two most common ways to left or right align elements are by using the float property and the position property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you right-align an element with the float property?

A

To right-align an element using the float property:

1) Use the float property set to right.
2) The text content within the parent element will wrap around the floated element.

HTML
< div class=”parent”>
< img src=”photo.png” class=”child”>
Lorem ipsum dolor sit amet, consectetur adipiscing elit…
< /div>

CSS
.child {
float: right;
}

CSS rule will align image to the right, and the text will wrap around it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly