英文:
css command justify-content: space-between does not work for one of the product but works fine for the last two
问题
我有三个产品,每个产品旁边都有图像和描述,之间的空间我使用了"justify-content: space-between"。对于最后两个产品来说,这似乎有效,但对于第一个产品却不行,非常恼人。
我尝试将宽度设置为100%,以便"justify-content"有足够的空间来进行间距,但仍然无效。
请注意,代码部分我不会进行翻译。
英文:
I have three products with imag and discription side by side and for the space in between i have used justify-content: space-between; It seems to work for the last two products but not the first one, very annoying.
I have tried making the width 100% so that the justify-content has enough room to do the spacing but still no use.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.products-container {
margin-left: 10px;
margin-right: 20px;
outline: 2px solid yellow;
position: relative;
}
.products-container-title {
border-top: 3px solid black;
padding-top: 25px;
text-align: center;
text-transform: none;
font-family: /*"Sofia",*/ "Neutra Book", sans-serif;
font-size: 1.7rem;
color: black;
margin-bottom: 80px;
max-width: 287px;
margin-left: auto;
margin-right: auto;
}
.product {
display: flex;
justify-content: space-between;
margin-bottom: 80px;
}
<!-- language: lang-html -->
<div class="products-container">
<h2 class="products-container-title">REPLACEMENT BRUSH HEADS</h2>
<div class="product">
<div class="product-1-image">
<img src="img/precision-clean.png">
</div>
<div class="product-1-info">
<h2>PRECISION CLEAN</h2>
<p>Features cup-shaped bristles to reach deep between teeth, for cleaner teeth and healthier gums*</p>
<p>*vs a regular manual toothbrush</p>
<a href="" class="button-product-1">Learn More/Buy</a>
</div>
</div>
<div class="product">
<div class="product-2-info">
<h2>FLOSSACTION</h2>
<p>Features soft MicroPulseTM bristles for deep cleaning between teeth.</p>
<a href="" class="button-product-2">Learn More/Buy</a>
</div>
<div class="product-2-image">
<img src="img/floss-action.png">
</div>
</div>
<div class="product">
<div class="product-3-image">
<img src="img/sensitive-clean.png">
</div>
<div class="product-3-info">
<h2>SENSITIVE CLEAN</h2>
<p>Provides a gentle brushing experience, ideal for sensitive teeth and gums.</p>
<a href="" class="button-product-3">Learn More/Buy</a>
</div>
</div>
</div>
<!-- end snippet -->
答案1
得分: 2
根据您的图片,我认为您对于justify-content: space-between所创建的内容和未创建的内容存在一些误解。
在您的第二个产品的图片中,额外的空间是由display: flex创建的,每个元素都被赋予了50%的宽度(因为有两个子div元素),而**.product-2-info**中的文本没有占满整个宽度,因此剩下的部分是紫色的部分。
然而,对于**.product-1-info**,文本占满了整个宽度并换行,所以没有紫色的部分。
要解决这个问题,您需要将信息和图片类的宽度设为小于50%。
另外需要注意的是,类应该在需要将样式应用于多个元素时使用,而ID应该在样式需要是唯一的情况下使用。因此,在这种情况下,如果您希望所有信息和图片类具有相同的样式,只需使用以下方式:
.product-image
和
.product-info
英文:
I think based on your images that you're misunderstanding what is and is not being created by justify-content: space-between.
In your image with product 2, that additional space is being created by display: flex, each element has been given 50% width to take up (because there's 2 child div elements), the text in .product-2-info isn't taking full width so the remainder is the purple section.
For .product-1-info however the text takes the full width and wraps, so there's no purple section.
To fix this you'll need to apply a width less than 50% to the info and image classes.
An additional side note, classes should be used when the styles need to be applied to more than one element, id's should be used when the styles should be unique, so in this case if you wanted all info and image classes to have the same styles you could just use:
.product-image
and
.product-info
答案2
得分: 0
我已添加以下CSS样式以使其工作。
.product-image {
max-width: 500px;
}
.product-info {
max-width: 500px;
}
英文:
I have added the following css style to work.
.product-image {
max-width: 500px;
}
.product-info {
max-width: 500px;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论