How to make a child centered on both axis with the other childs surrounding it?

How to make a child centered on both axis with the other childs surrounding it?



enter image description hereLet's see an example:




.wrapper
width: 100vw;
height: 100vh;
display: flex;
flex-wrap: wrap;
overflow-y: hidden

.you
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
font-size: 300%

.others
margin: 0 10px


<div class="wrapper">
<h1 class="you">you</h1>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
<p class="others">others</p>
</div>



I want to perfectly center the you in the way that it doesn't overlap the others. I always use flexbox, but it looks like that it will not be the solution. I'm thinking about grid, and to calculate the rows and columns manually, but there must be an elegant way to do this. Please let me know if it is.





if it is possible, could you share a screenshot of the desired final results?
– Matt
Sep 3 at 15:25





No, not possible without knowing row heights / element widths.
– Paulie_D
Sep 3 at 16:08





you can do it with grid, each 'others' word can be in a column, and the 'you' can be an merged area.
– B.J. A.A.
Sep 3 at 16:12




1 Answer
1



Using display:grid, you can achieve the effect that you are looking for:


display:grid


<style>
.grid-container
display: grid;
grid-template-columns:repeat(8,1fr) ;
background-color: #2196F3;
padding: 10px;

.others

padding: 20px;
font-size: 12px;
text-align: center;

.you
font-size: 82px;
grid-area: 4 / 3 / 6 / 7;
text-align: center;

</style>
</head>
<body>



<div class="grid-container">
<div class="you">you</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
<div class="others">others</div>
</div>

</body>



grid-area: 4 / 3 / 6 / 7; this line makes the word 'others' wrap around the 'you' word, how? by using the space in columns and rows that if the word 'others' were there.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)