简体   繁体   English

CSS Flexbox 纵横比

[英]CSS Flexbox aspect ratio

I hope someone can help me to end my 16 hour search.我希望有人可以帮助我结束 16 小时的搜索。 I have to make我必须做

  • six responsive squares in a 2 x 3 raster. 2 x 3 栅格中的六个响应方块。
  • Inside the square there has to be a responsive circle.在广场内必须有一个响应圈。
  • Inside the circle there has to be a centered letter.在圆圈内必须有一个居中的字母。
  • I have to use Flexbox.我必须使用 Flexbox。
  • I am not allowed to use Grid and/or tables.我不允许使用网格和/或表格。
  • The squares and circles need to keep their aspect ratio and must fill the container.正方形和圆形需要保持它们的纵横比并且必须填满容器。
  • CSS-only纯 CSS

 div { display: flex; flex: 1; justify-content: space-between; font-size: 10rem; }.blokrij { flex-direction: column; width: 50%; }.vierkant { background-color: hsla(26, 100%, 50%, 1.00); flex: 1 1 auto; max-width: 100%; border-radius: 10%; margin 1px; }.rond { background-color: blue; border-radius: 50%; }
 <div class="container"> <div class="blokrij"> <div class="vierkant"> <div class="rond"></div>L</div> <div class="vierkant"> <div class="rond"></div>O</div> <div class="vierkant"> <div class="rond"></div>I</div> </div> <div class="blokrij"> <div class="vierkant"> <div class="rond"></div>L</div> <div class="vierkant"> <div class="rond"></div>O</div> <div class="vierkant"> <div class="rond"></div>I</div> </div> </div>

I'm so frustrated I cant figure out what the hell I have to do.我很沮丧,我不知道我到底要做什么。 Especially because I know how to fix it with GRID.特别是因为我知道如何使用 GRID 来修复它。

Thansk for helping in Advance!感谢您提前提供帮助!

It is better to assign different codes to their own sections最好为自己的部分分配不同的代码

  • The text is not written inside the circle文字未写在圆圈内

  • The ratios are not set correctly比率设置不正确

  • Sizes are not set correctly尺寸设置不正确

I set margin: 10px;我设置margin: 10px; and padding: 10px;padding: 10px; for better and more clarity.为了更好,更清晰。

You might say that circles are not precise and are more like ellipses你可能会说圆不精确,更像椭圆

This is true because they are measured relative to the screen这是真的,因为它们是相对于屏幕测量的

They may have different sizes in different sizes它们可能有不同尺寸的不同尺寸

 .container{ width:100%; height: 100vh; display: flex; }.blokrij { display: flex; flex-direction: column; width: 50%; height: 100%; }.vierkant { background-color: hsla(26, 100%, 50%, 1.00); border-radius: 10%; margin 1px; height: 100%; margin: 10px; padding: 10px; }.rond { height: 100%; background-color: blue; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10rem; }
 <div class="container"> <div class="blokrij"> <div class="vierkant"> <div class="rond">L</div> </div> <div class="vierkant"> <div class="rond">O</div> </div> <div class="vierkant"> <div class="rond">I</div> </div> </div> <div class="blokrij"> <div class="vierkant"> <div class="rond">L</div> </div> <div class="vierkant"> <div class="rond">O</div> </div> <div class="vierkant"> <div class="rond">I</div> </div> </div> </div>

If you want the circles and squares to be exactly the exact circle and square, you can measure exactly with px , rem , ...如果您希望圆形和正方形与圆形和正方形完全相同,您可以使用pxrem 、...

For example:例如:

 .container{ width:400px; height: 400px; display: flex; }.blokrij { display: flex; flex-direction: column; width: 50%; height: 100%; }.vierkant { background-color: hsla(26, 100%, 50%, 1.00); border-radius: 10%; margin 1px; height: 100%; margin: 5px; padding: 5px; }.rond { height: 100%; background-color: blue; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10rem; }
 <div class="container"> <div class="blokrij"> <div class="vierkant"> <div class="rond">L</div> </div> <div class="vierkant"> <div class="rond">O</div> </div> <div class="vierkant"> <div class="rond">I</div> </div> </div> <div class="blokrij"> <div class="vierkant"> <div class="rond">L</div> </div> <div class="vierkant"> <div class="rond">O</div> </div> <div class="vierkant"> <div class="rond">I</div> </div> </div> </div>

You have to give the circles a dedicated width and height, put the letters inside them and define for all flex-items the centering with justify-content and align-items .你必须给圆圈一个专门的宽度和高度,把字母放在里面,并用justify-contentalign-items为所有弹性项目定义居中。 For the responsiveness you should define width and height of the circle and the font-size with the same responsive dimension, for example vw .对于响应性,您应该定义圆形的宽度和高度以及具有相同响应尺寸的字体大小,例如vw The width for the columns isn't necessary.列的宽度不是必需的。

Working example :工作示例

 div { display: inline-flex; flex: 1; justify-content: center; align-items: center; font-size: 10vw; }.blokrij { flex-direction: column; }.vierkant { background-color:hsla(26,100%,50%,1.00); border-radius: 10%; margin: 1px; }.rond { width: 20vw; height: 20vw; background-color: blue; border-radius: 50%; }
 <div class="container"> <div class="blokrij"> <div class="vierkant"> <div class="rond">L</div> </div> <div class="vierkant"> <div class="rond">O</div> </div> <div class="vierkant"> <div class="rond">I</div> </div> </div> <div class="blokrij"> <div class="vierkant"> <div class="rond">L</div> </div> <div class="vierkant"> <div class="rond">O</div> </div> <div class="vierkant"> <div class="rond">I</div> </div> </div> </div>

I am pretty busy with the same subject, and I have the same question as above.我很忙于同一主题,并且我有与上述相同的问题。 I would like to know if the answers for 'Kopshot' were helpfull.我想知道“Kopshot”的答案是否有帮助。 The squares must stay in the same form.正方形必须保持相同的形式。 I am not allowed to use grid.我不允许使用网格。 It has to be responsive from size 320 untill 1044 pixels.它必须响应从 320 到 1044 像素的大小。 I've tried to use percentages, and also aspect-ratio in CSS but it doesnt work.我尝试在 CSS 中使用百分比和纵横比,但它不起作用。 It has to move fluidly.它必须流畅地移动。 And the squires have to grow to fill the gap, so I don't think fixed sizes are the answer.乡绅必须成长以填补空白,所以我不认为固定尺寸是答案。 The images how it should look.图像应该如何看。 I see that the snippet doesnt look right, the images are what it looks likes on my computer.我看到该片段看起来不正确,图像是它在我的计算机上的样子。

Thanks if anyone can help me.....谢谢如果有人可以帮助我......

 .Letterblokjes_blok { margin: auto; display: flex; } @media screen and (min-width:1024px) {.Letterblokjes_blok { margin: auto; display: flow-root; inline-size: 100%; } }.blokjes { display: flow-root; margin: 0; inline-size: 49%; } @media screen and (min-width:768px) {.blokjes { display: flow-root; margin: 0; inline-size: 49%; float: left; } } @media screen and (min-width:1024px) {.blokjes, .blokjes2 { display: flex; flex-direction: row; justify-content: space-between; margin: 0; inline-size: 100%; } }.blokjes2 { float: right; } @media screen and (min-width:768px) {.blokjes2 { float: right; } }.letterblokje, .letterblokje2 { display: flex; float: left; inline-size: 148px; block-size: 148px; margin: 0 0 9px 0; background-color: cornflowerblue; justify-content: center; align-items: center; border-radius: 20%; border: 2px black solid; }.letterblokje2 { float: right; } @media screen and (min-width:768px) {.letterblokje, .letterblokje2 { inline-size: 360px; block-size: 360px; margin: 0 0 30px 0; } } @media screen and (min-width:1024px) {.letterblokje, .letterblokje2 { inline-size: 320px; block-size: 320px; margin: 0 0 21px 0; } } @media screen and (min-width:1044px) {.letterblokje, .letterblokje2 { inline-size: 330px; block-size: 330px; margin: 0 0 21px 0; } }.cirkel { display: flex; border:0.3px solid rgba(220, 220, 220); border-radius: 50%; inline-size: 90%; block-size: 90%; background-color: rgba(200, 200, 200); box-shadow: 0em 0em 0.4em 0.05em rgb(150, 150, 150) inset; align-items: center; justify-content: center; font: 700 60px 'Cabin Sketch', cursive; color: cornflowerblue; font-size: 80px; padding: 30px; } @media screen and (min-width:1044px) { body { inline-size: 1032px; margin:8px auto; } }
 <section class="Letterblokjes_blok"> <article class=blokjes> <div class="letterblokje"><div class="cirkel">L</div></div> <div class="letterblokje"><div class="cirkel">O</div></div> <div class="letterblokje"><div class="cirkel">I</div></div> </article> <article class="blokjes2"> <div class="letterblokje2"><div class="cirkel">L</div></div> <div class="letterblokje2"><div class="cirkel">O</div></div> <div class="letterblokje2"><div class="cirkel">I</div></div> </article> </section>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM