How does one remove the full width from this flexbox centered div or its child?
Ie. this:

Should be:

.main {
color: white;
background: blue;
position: relative;
height: 300px;
padding: 10px;
}
.wrapper {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
position: absolute;
width: calc(100% - 20px);
height: calc(100% - 20px);
}
.wrapper p {
color: #000;
background: lightgrey;
}
<div class="main">
<div class="wrapper">
<p>Please press Enter to continue installation</p>
</div>
<p>Welcome to Windows 95</p>
</div>
You can set margin: 0 auto to p element inside .wrapper:
.main {
color: white;
background: blue;
position: relative;
height: 300px;
padding: 10px;
}
.wrapper {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
position: absolute;
width: calc(100% - 20px);
height: calc(100% - 20px);
}
.wrapper p {
color: #000;
background: lightgrey;
margin: 0 auto;/*add margin 0 auto*/
}
<div class="main">
<div class="wrapper">
<p>Please press Enter to continue installation</p>
</div>
<p>Welcome to Windows 95</p>
</div>
You can add auto to the left and right margins of the <p> to center it, and specify a width less than 100% to make it not full width .
.main {
color: white;
background: blue;
position: relative;
height: 300px;
padding: 10px;
}
.wrapper {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
position: absolute;
width: calc(100% - 20px);
height: calc(100% - 20px);
}
.wrapper p {
color: #000;
background: lightgrey;
max-width: 50%;
margin: 0 auto;
}
<div class="main">
<div class="wrapper">
<p>Please press Enter to continue installation</p>
</div>
<p>Welcome to Windows 95</p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With