height property in CSS. How does setting height in percentages differ from using pixels?Answer:
height property sets the vertical size of an element on a webpage. It controls how tall the element appears.height: 200px; means the element is exactly 200 pixels tall regardless of screen size or parent element.height: 50%; it becomes relative to the height of the parent element. This allows flexible, responsive designs. If the parent element's height changes, so does the child element’s height.auto lets the browser decide the height based on the content inside.width property in web design, and give examples of how it can be used for fixed and flexible layouts.Answer:
width property controls the horizontal size of an element, determining how wide it appears on a webpage.width: 300px;, so the element is always 300 pixels wide, regardless of the device or screen size.width: 80%;, which means the element takes 80% of the parent container’s width, adjusting dynamically with screen size changes.auto width is based on the content’s size.float property help in arranging text and images on a webpage? Give a practical example.Answer:
float property moves an element to the left or right side of its container and allows surrounding text or inline elements to wrap around it.img {
float: left;
width: 150px;
height: 150px;
margin: 10px;
}
This CSS moves the image to the left side, and the paragraph text wraps on the image’s right side.Answer:
| Height | Width |
|---|---|
| Controls the vertical size of an element. | Controls the horizontal size. |
| Setting height too small may cause vertical overflow if content is taller than height. | Setting width too small may cause text to wrap or break onto multiple lines. |
| Commonly set using px, %, or auto. | Also set using px, %, or auto. |
Examples: height: 200px; | Examples: width: 300px; |
Both properties must be chosen carefully to avoid content being cut off or displayed awkwardly.
float: right to a div with specified height and width? Explain with an example.Answer:
Applying float: right to a div moves the element to the right side of its container.
Other content, such as text or inline elements, will wrap around this floated div on its left side.
For example,
div {
width: 300px;
height: 150px;
float: right;
background-color: lightblue;
}
This creates a box that is 300px wide, 150px tall, with a light blue background. It will appear on the right edge of its container. Text following the div in HTML will flow on the left side of it.
This is useful to create sidebars or image panels aligned right while letting main content appear to the left.
Answer:
float: left or float: right, they are taken out of the normal document flow.clear property after floated elements to stop content wrapping improperly..clearfix::after {
content: "";
display: block;
clear: both;
}
.clearfix to the container element to fix height issues and maintain a proper layout.Answer:
float: left on the image to move it to the left and let the text wrap on the right side.img {
float: left;
width: 150px;
height: 150px;
margin: 0 10px 10px 0;
}
<p> or <div>) that follows the image, no special CSS required since text wraps automatically around floated elements.img {
float: center;
width: 150px;
height: 150px;
}
Answer:
float: center; which is invalid.float property accepts only left, right, or none values, never center.center is invalid, the float will not be applied, so the image stays in default flow and text will not wrap around it.float: center; with either float: left; or float: right; depending on where you want the image positioned. For example:
img {
float: left;
width: 150px;
height: 150px;
}
Answer:
% for width or height helps maintain proportion and fit within different screen sizes.width, height, and float to implement this?Answer:
.sidebar {
width: 25%;
height: 400px;
float: right;
background-color: #f0f0f0; /* for visibility */
}
.main-content {
width: 70%; /* or 75% if margin/padding */
float: left;
}
.main-content will wrap naturally and not overlap the floated sidebar.