Flexbox内嵌盒子

huangapple go评论105阅读模式
英文:

Flex box inside a box

问题

  1. 将内部框与外部框的中心右侧对齐是我的问题之一。
  2. 使用 flexbox 将内部框变成一个“行”,并在较小的显示屏上移到外部框的底部是我的问题之二。

大屏幕结果

小屏幕结果

  1. <p class="inline-block-buttons">
  2. 文本1
  3. <a>文本2</a>
  4. </p>
  1. p {
  2. border: 1px solid black;
  3. margin: 2rem 0;
  4. padding: 0.25rem;
  5. }
  6. a {
  7. padding: 1rem 2rem;
  8. border: 1px solid black;
  9. text-decoration: none;
  10. margin: 1rem;
  11. border-radius: 2px;
  12. }
  13. .inline-block-buttons a {
  14. display: inline-block;
  15. align-self: right;
  16. }
  17. body {
  18. margin: 2rem;
  19. }
  20. @media (max-width: 500px) {
  21. .inline-block-buttons {
  22. flex-direction: column;
  23. }
  24. }
英文:

I'm trying to fit a box inside a box, where the layout changes depending on the screen size e.g. if under 400px.

I'm having trouble at two points:

  1. Aligning the inner box to the centre right of the outer box and
  2. Using flexboxes to make the inner box into a 'row' and fall to the bottom of the outer box on smaller displays

Large display results

Small display results

  1. &lt;p class=&quot;inline-block-buttons&quot;&gt;
  2. Text 1
  3. &lt;a&gt;Text 2&lt;/a&gt;
  4. &lt;/p&gt;
  1. p {
  2. border: 1px solid black;
  3. margin: 2rem 0;
  4. padding: 0.25rem;
  5. }
  6. a {
  7. padding: 1rem 2rem;
  8. border: 1px solid black;
  9. text-decoration: none;
  10. margin: 1rem;
  11. border-radius: 2px;
  12. }
  13. .inline-block-buttons a {
  14. display: inline-block;
  15. align-self: right;
  16. }
  17. body {
  18. margin: 2rem;
  19. }
  20. @media (max-width: 500px) {
  21. .inline-block-buttons {
  22. flex-direction: column;
  23. }

答案1

得分: 0

以下是您要翻译的代码部分:

  1. p {
  2. border: 1px solid black;
  3. margin: 2rem 0;
  4. padding: 1rem 2rem;
  5. display: flex;
  6. align-items: center;
  7. border-radius: 10px;
  8. }
  9. a {
  10. padding: 1rem 2rem;
  11. border: 1px solid black;
  12. text-decoration: none;
  13. margin: 1rem;
  14. border-radius: 10px;
  15. }
  16. .inline-block-buttons a {
  17. margin-left: auto;
  18. }
  19. body {
  20. margin: 2rem;
  21. flex-direction: column;
  22. font-weight: bold;
  23. }
  24. @media (max-width: 500px) {
  25. .inline-block-buttons {
  26. flex-direction: column;
  27. }
  28. .inline-block-buttons a {
  29. margin: 1rem;
  30. }
  31. }
  1. <body>
  2. <p class="inline-block-buttons">
  3. Text 1
  4. <a>Text 2</a>
  5. </p>
  6. </body>
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

  1. p {
  2. border: 1px solid black;
  3. margin: 2rem 0;
  4. padding: 1rem 2rem;
  5. display:flex;
  6. align-items: center;
  7. border-radius: 10px;
  8. }
  9. a {
  10. padding: 1rem 2rem;
  11. border: 1px solid black;
  12. text-decoration: none;
  13. margin: 1rem;
  14. border-radius: 10px;
  15. }
  16. .inline-block-buttons a {
  17. margin-left: auto;
  18. }
  19. body {
  20. margin: 2rem;
  21. flex-direction: column;
  22. font-weight: bold;
  23. }
  24. @media (max-width: 500px) {
  25. .inline-block-buttons {
  26. flex-direction: column;
  27. }
  28. .inline-block-buttons a{
  29. margin: 1rem;
  30. }
  31. }

<!-- language: lang-html -->

  1. &lt;body&gt;
  2. &lt;p class=&quot;inline-block-buttons&quot;&gt;
  3. Text 1
  4. &lt;a&gt;Text 2&lt;/a&gt;
  5. &lt;/p&gt;
  6. &lt;/body&gt;

<!-- end snippet -->

答案2

得分: 0

以下是您要翻译的内容:

  1. 尝试这个:
  2. <!-- 开始代码片段:js 隐藏:false 控制台:true Babelfalse -->
  3. <!-- 语言:lang-css -->
  4. div.inline-block-buttons {
  5. display: flex;
  6. justify-content: space-between;
  7. padding: 30px;
  8. flex-wrap: wrap;
  9. }
  10. .inline-block-buttons {
  11. border: 1px solid black;
  12. border-radius: 10px;
  13. padding: 15px 100px;
  14. }
  15. @media (max-width: 500px) {
  16. .inline-block-buttons {
  17. flex-direction: column;
  18. text-align: center;
  19. }
  20. .inline-block-buttons p {
  21. margin-bottom: 50px;
  22. }
  23. }
  24. <!-- 语言:lang-html -->
  25. <div class="inline-block-buttons">
  26. <p>Text 1</p>
  27. <a class="inline-block-buttons">Text 2</a>
  28. </div>
  29. <!-- 结束代码片段 -->

请注意,我已经保留了代码部分的原始标记,以便您可以在需要时使用它们。

英文:

Try this :

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

  1. div.inline-block-buttons {
  2. display: flex;
  3. justify-content: space-between;
  4. padding: 30px;
  5. flex-wrap: wrap;
  6. }
  7. .inline-block-buttons {
  8. border: 1px solid black;
  9. border-radius: 10px;
  10. padding: 15px 100px;
  11. }
  12. @media (max-width: 500px) {
  13. .inline-block-buttons {
  14. flex-direction: column;
  15. text-align: center;
  16. }
  17. .inline-block-buttons p {
  18. margin-bottom: 50px;
  19. }
  20. }

<!-- language: lang-html -->

  1. &lt;div class=&quot;inline-block-buttons&quot;&gt;
  2. &lt;p&gt;Text 1&lt;/p&gt;
  3. &lt;a class=&quot;inline-block-buttons&quot;&gt;Text 2&lt;/a&gt;
  4. &lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月19日 20:43:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定