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

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

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 -->

.category-items-box {
    padding: 40px;
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(200px,260px));
    gap: 34px;
}

.category-item {
    display: flex;
    padding: 12px 21px;
    border-radius: 9px;
    border: 1px solid hsl(0, 0%, 85%);
    gap: 10px;
}

.category-img {
    background-color: var(--cultured);
    border: 1px solid hsl(0, 0%, 80%);
    border-radius: 9px;
    padding: 10px;
    width: 30px;
    height: 30px;
}
  
.category-content {
    display: flex;
}

.title-category {
    margin-top: 8px;
    margin-bottom: -14px;
    font-size: 14px;
    font-family: &#39;Poppins&#39;, Arial, Helvetica, sans-serif;
    white-space: nowrap; 
}
.quantity-category {
    font-size: 11px;
    color: hsl(0, 0%, 47%);
    transform: translateX(19px);
}
.category-btn {
    color: hsl(353, 100%, 78%);
    font-size: 0.78rem;
    font-weight: 600;
    font-family: &#39;Poppins&#39;, Arial, Helvetica, sans-serif;
    text-decoration: none;
    

}

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

&lt;div class=&quot;category&quot;&gt;
        &lt;div class=&quot;category-container&quot;&gt;
            &lt;div class=&quot;category-items-box&quot;&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &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;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;VESTIDO &amp; ROUPA&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(53)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                    
                &lt;/div&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &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;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;&#211;CULOS &amp; LENTES&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(22)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &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;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;SHORTS &amp; JEANS&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(64)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/tee.svg&quot; alt=&quot;camisa&quot;&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;CAMISAS&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(10)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;/div&gt;
                
            &lt;/div&gt;
        &lt;/div&gt;
    &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 -->

.category-items-box {
  padding: 40px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 300px));
  gap: 34px;
}

.category-item {
  display: flex;
  padding: 12px 21px;
  border-radius: 9px;
  border: 1px solid hsl(0, 0%, 85%);
  gap: 10px;
}

.category-texts{ flex-basis:100% }

.category-img {
  background-color: var(--cultured);
  border: 1px solid hsl(0, 0%, 80%);
  border-radius: 9px;
  padding: 10px;
  width: 30px;
  height: 30px;
  flex-shrink:0;
}

.category-content {
  display: flex;
  justify-content: space-between;
  gap:19px;
}

.title-category {
  margin-top: 8px;
  margin-bottom: -14px;
  font-size: 14px;
  font-family: &quot;Poppins&quot;, Arial, Helvetica, sans-serif;
  white-space: nowrap;
}
.quantity-category {
  font-size: 11px;
  color: hsl(0, 0%, 47%);

}
.category-btn {
  color: hsl(353, 100%, 78%);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: &quot;Poppins&quot;, Arial, Helvetica, sans-serif;
  text-decoration: none;
}

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

&lt;div class=&quot;category&quot;&gt;
        &lt;div class=&quot;category-container&quot;&gt;
            &lt;div class=&quot;category-items-box&quot;&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &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;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;VESTIDO &amp; ROUPA&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(53)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                    
                &lt;/div&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &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;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;&#211;CULOS &amp; LENTES&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(22)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &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;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;SHORTS &amp; JEANS&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(64)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class=&quot;category-item&quot;&gt;
                    &lt;div class=&quot;category-img&quot;&gt;
                        &lt;img src=&quot;https://codewithsadee.github.io/anon-ecommerce-website/assets/images/icons/tee.svg&quot; alt=&quot;camisa&quot;&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;category-texts&quot;&gt;
                        &lt;div class=&quot;category-content&quot;&gt;
                            &lt;h3 class=&quot;title-category&quot;&gt;CAMISAS&lt;/h3&gt;
                            &lt;p class=&quot;quantity-category&quot;&gt;(10)&lt;/p&gt;
                        &lt;/div&gt;
                        &lt;a href=&quot;#&quot; class=&quot;category-btn&quot;&gt;Mostrar Tudo&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;/div&gt;
                
            &lt;/div&gt;
        &lt;/div&gt;
    &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:

确定