Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To center a wider child element in a parent container that is narrower, you can use the CSS property margin: 0 auto; on the child element. This will center the child element horizontally within the parent container.

For example, if your HTML looks like this:

<div class="parent">
  <div class="child">Wider content here</div>
</div>

You can use the following CSS for the child element:

.child {
  width: 80%; /* Or any other width */
  margin: 0 auto;
}

This will make the child element 80% of the width of the parent container and centered horizontally.