一个容器与其他容器不同,因为单词长度不同。

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

One container is different from the others bacause of the word length

问题

我想要使所有这些容器都相等,但由于我认为最后一个容器("CAMISAS")的字数较短,所以最后一个容器的表现有些奇怪,无法将括号中的数字放在与其他容器相同的位置。那么,我该如何解决这个问题?

英文:

I want to make all these containers equal, but for some reason - that I believe it is because of the word length of the last container ("CAMISAS") that is shorter compared to the others container - the last container is acting strangely, in a way that I can't put the number in parentheses in the same position as it is in the other containers. So, how can I solve it?

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

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

  1. .category-items-box {
  2. padding: 40px;
  3. display: grid;
  4. grid-template-columns: repeat(auto-fit,minmax(200px,260px));
  5. gap: 34px;
  6. }
  7. .category-item {
  8. display: flex;
  9. padding: 12px 21px;
  10. border-radius: 9px;
  11. border: 1px solid hsl(0, 0%, 85%);
  12. gap: 10px;
  13. }
  14. .category-img {
  15. background-color: var(--cultured);
  16. border: 1px solid hsl(0, 0%, 80%);
  17. border-radius: 9px;
  18. padding: 10px;
  19. width: 30px;
  20. height: 30px;
  21. }
  22. .category-content {
  23. display: flex;
  24. }
  25. .title-category {
  26. margin-top: 8px;
  27. margin-bottom: -14px;
  28. font-size: 14px;
  29. font-family: &#39;Poppins&#39;, Arial, Helvetica, sans-serif;
  30. white-space: nowrap;
  31. }
  32. .quantity-category {
  33. font-size: 11px;
  34. color: hsl(0, 0%, 47%);
  35. transform: translateX(19px);
  36. }
  37. .category-btn {
  38. color: hsl(353, 100%, 78%);
  39. font-size: 0.78rem;
  40. font-weight: 600;
  41. font-family: &#39;Poppins&#39;, Arial, Helvetica, sans-serif;
  42. text-decoration: none;
  43. }

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

  1. &lt;div class=&quot;category&quot;&gt;
  2. &lt;div class=&quot;category-container&quot;&gt;
  3. &lt;div class=&quot;category-items-box&quot;&gt;
  4. &lt;div class=&quot;category-item&quot;&gt;
  5. &lt;div class=&quot;category-img&quot;&gt;
  6. &lt;img class=&quot;image&quot; src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/dress.svg&quot; alt=&quot;foto de um vestido&quot;&gt;
  7. &lt;/div&gt;
  8. &lt;div class=&quot;category-texts&quot;&gt;
  9. &lt;div class=&quot;category-content&quot;&gt;
  10. &lt;h3 class=&quot;title-category&quot;&gt;VESTIDO &amp; ROUPA&lt;/h3&gt;
  11. &lt;p class=&quot;quantity-category&quot;&gt;(53)&lt;/p&gt;
  12. &lt;/div&gt;
  13. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  14. &lt;/div&gt;
  15. &lt;/div&gt;
  16. &lt;div class=&quot;category-item&quot;&gt;
  17. &lt;div class=&quot;category-img&quot;&gt;
  18. &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/glasses.svg&quot; alt=&quot;foto de um &#243;culus&quot;&gt;
  19. &lt;/div&gt;
  20. &lt;div class=&quot;category-texts&quot;&gt;
  21. &lt;div class=&quot;category-content&quot;&gt;
  22. &lt;h3 class=&quot;title-category&quot;&gt;&#211;CULOS &amp; LENTES&lt;/h3&gt;
  23. &lt;p class=&quot;quantity-category&quot;&gt;(22)&lt;/p&gt;
  24. &lt;/div&gt;
  25. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  26. &lt;/div&gt;
  27. &lt;/div&gt;
  28. &lt;div class=&quot;category-item&quot;&gt;
  29. &lt;div class=&quot;category-img&quot;&gt;
  30. &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/shorts.svg&quot; alt=&quot;foto de uma cal&#231;a jeans&quot;&gt;
  31. &lt;/div&gt;
  32. &lt;div class=&quot;category-texts&quot;&gt;
  33. &lt;div class=&quot;category-content&quot;&gt;
  34. &lt;h3 class=&quot;title-category&quot;&gt;SHORTS &amp; JEANS&lt;/h3&gt;
  35. &lt;p class=&quot;quantity-category&quot;&gt;(64)&lt;/p&gt;
  36. &lt;/div&gt;
  37. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  38. &lt;/div&gt;
  39. &lt;/div&gt;
  40. &lt;div class=&quot;category-item&quot;&gt;
  41. &lt;div class=&quot;category-img&quot;&gt;
  42. &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/tee.svg&quot; alt=&quot;camisa&quot;&gt;
  43. &lt;/div&gt;
  44. &lt;div class=&quot;category-texts&quot;&gt;
  45. &lt;div class=&quot;category-content&quot;&gt;
  46. &lt;h3 class=&quot;title-category&quot;&gt;CAMISAS&lt;/h3&gt;
  47. &lt;p class=&quot;quantity-category&quot;&gt;(10)&lt;/p&gt;
  48. &lt;/div&gt;
  49. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  50. &lt;/div&gt;
  51. &lt;/div&gt;
  52. &lt;/div&gt;
  53. &lt;/div&gt;
  54. &lt;/div&gt;
  55. &lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

因为您在.category-item上设置了display:flex.category-texts变成了一个弹性项目,占据了适合其内容的最小宽度。所以,您的布局是基于文本长度的。

您可以通过添加.category-texts{ flex-basis:100% }来修复这个问题,以使其占据所有可用的宽度,并在.category-content上设置justify-content: space-between

我还进行了一些其他小的更改。

英文:

Because you have set a display:flex on .category-item, .category-texts is becoming a flex item taking the minimum width that fits its content. So yeah, the layout you have there is based on the text length.

You could fix this with .category-texts{ flex-basis:100% }, so it takes all the available width, and set justify-content: space-between on .category-content.

I also made some other small changes:

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

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

  1. .category-items-box {
  2. padding: 40px;
  3. display: grid;
  4. grid-template-columns: repeat(auto-fit, minmax(200px, 300px));
  5. gap: 34px;
  6. }
  7. .category-item {
  8. display: flex;
  9. padding: 12px 21px;
  10. border-radius: 9px;
  11. border: 1px solid hsl(0, 0%, 85%);
  12. gap: 10px;
  13. }
  14. .category-texts{ flex-basis:100% }
  15. .category-img {
  16. background-color: var(--cultured);
  17. border: 1px solid hsl(0, 0%, 80%);
  18. border-radius: 9px;
  19. padding: 10px;
  20. width: 30px;
  21. height: 30px;
  22. flex-shrink:0;
  23. }
  24. .category-content {
  25. display: flex;
  26. justify-content: space-between;
  27. gap:19px;
  28. }
  29. .title-category {
  30. margin-top: 8px;
  31. margin-bottom: -14px;
  32. font-size: 14px;
  33. font-family: &quot;Poppins&quot;, Arial, Helvetica, sans-serif;
  34. white-space: nowrap;
  35. }
  36. .quantity-category {
  37. font-size: 11px;
  38. color: hsl(0, 0%, 47%);
  39. }
  40. .category-btn {
  41. color: hsl(353, 100%, 78%);
  42. font-size: 0.78rem;
  43. font-weight: 600;
  44. font-family: &quot;Poppins&quot;, Arial, Helvetica, sans-serif;
  45. text-decoration: none;
  46. }

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

  1. &lt;div class=&quot;category&quot;&gt;
  2. &lt;div class=&quot;category-container&quot;&gt;
  3. &lt;div class=&quot;category-items-box&quot;&gt;
  4. &lt;div class=&quot;category-item&quot;&gt;
  5. &lt;div class=&quot;category-img&quot;&gt;
  6. &lt;img class=&quot;image&quot; src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/dress.svg&quot; alt=&quot;foto de um vestido&quot;&gt;
  7. &lt;/div&gt;
  8. &lt;div class=&quot;category-texts&quot;&gt;
  9. &lt;div class=&quot;category-content&quot;&gt;
  10. &lt;h3 class=&quot;title-category&quot;&gt;VESTIDO &amp; ROUPA&lt;/h3&gt;
  11. &lt;p class=&quot;quantity-category&quot;&gt;(53)&lt;/p&gt;
  12. &lt;/div&gt;
  13. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  14. &lt;/div&gt;
  15. &lt;/div&gt;
  16. &lt;div class=&quot;category-item&quot;&gt;
  17. &lt;div class=&quot;category-img&quot;&gt;
  18. &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/glasses.svg&quot; alt=&quot;foto de um &#243;culus&quot;&gt;
  19. &lt;/div&gt;
  20. &lt;div class=&quot;category-texts&quot;&gt;
  21. &lt;div class=&quot;category-content&quot;&gt;
  22. &lt;h3 class=&quot;title-category&quot;&gt;&#211;CULOS &amp; LENTES&lt;/h3&gt;
  23. &lt;p class=&quot;quantity-category&quot;&gt;(22)&lt;/p&gt;
  24. &lt;/div&gt;
  25. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  26. &lt;/div&gt;
  27. &lt;/div&gt;
  28. &lt;div class=&quot;category-item&quot;&gt;
  29. &lt;div class=&quot;category-img&quot;&gt;
  30. &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/shorts.svg&quot; alt=&quot;foto de uma cal&#231;a jeans&quot;&gt;
  31. &lt;/div&gt;
  32. &lt;div class=&quot;category-texts&quot;&gt;
  33. &lt;div class=&quot;category-content&quot;&gt;
  34. &lt;h3 class=&quot;title-category&quot;&gt;SHORTS &amp; JEANS&lt;/h3&gt;
  35. &lt;p class=&quot;quantity-category&quot;&gt;(64)&lt;/p&gt;
  36. &lt;/div&gt;
  37. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  38. &lt;/div&gt;
  39. &lt;/div&gt;
  40. &lt;div class=&quot;category-item&quot;&gt;
  41. &lt;div class=&quot;category-img&quot;&gt;
  42. &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/tee.svg&quot; alt=&quot;camisa&quot;&gt;
  43. &lt;/div&gt;
  44. &lt;div class=&quot;category-texts&quot;&gt;
  45. &lt;div class=&quot;category-content&quot;&gt;
  46. &lt;h3 class=&quot;title-category&quot;&gt;CAMISAS&lt;/h3&gt;
  47. &lt;p class=&quot;quantity-category&quot;&gt;(10)&lt;/p&gt;
  48. &lt;/div&gt;
  49. &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
  50. &lt;/div&gt;
  51. &lt;/div&gt;
  52. &lt;/div&gt;
  53. &lt;/div&gt;
  54. &lt;/div&gt;
  55. &lt;/div&gt;

<!-- end snippet -->

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

发表评论

匿名网友

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

确定