为几乎所有其他像素编写媒体查询
我的React项目上有一个页面,其中包含以卡格式的客户数据,现在我的屏幕上有3张卡片,现在问题是,我正在尝试使其响应迅速,并且当我尝试使用时,稍微降低了屏幕的宽度,最后一张卡上了下一行,并在最后一行留下了很大一部分空间,为了克服这个问题,我开始添加媒体查询并降低了我的卡宽度,但出现的问题是我已经出现了要在每2个像素后进行一次,我是否必须为每2个像素编写媒体查询?还是还有其他方法?这是问题的屏幕截图: -
Here is my JSX for this card only:-
<div className={`${customercss.parts} ${customercss.customer_card}`}>
<div className={customercss.card_wrap}>
<div className={customercss.customer_card_details} id={customercss.heading}>
<div className={customercss.customer_name}>
{elem.customer_name}
</div>
<label className={customercss.select_option}>
<input type="checkbox" name="checks" value={elem._id} id="checkbox" onClick={(e)=>selected_items(e,elem)} />
<span class={customercss.checkmark_span} ></span>
</label>
</div>
<div className={customercss.customer_card_details} id={customercss.customer_address}> <LocationOnOutlined htmlColor='#f7c6c6'/> {elem.customer_address}</div>
<div className={customercss.customer_card_details} id={customercss.date}> <CalendarToday htmlColor='#f7c6c6'/> {elem.date}</div>
<div className={customercss.customer_card_details} id={customercss.customer_other_options}>
<div className={customercss.customer_other_options_parts} id={customercss.option1}>
<div id={customercss.option1_1}>Subscriptions</div>
<div id={customercss.option1_2}>{elem.customer_items.length}</div>
</div>
<div className={customercss.customer_other_options_parts} id={customercss.option2}>
<MoreHoriz id={customercss.threedots} onClick={()=>{editcustomer(elem); show_edit_customer_details(elem)}} />
</div>
</div>
</div>
</div>
这是CSS(我刚刚添加了主框的CSS,而不是内部CSS): -
.customer_card_box{
display: flex;
flex-wrap: wrap;
}
.customer_card{
box-shadow: 0 2px 4px rgb(0 0 0 / 10%), 0 8px 16px rgb(0 0 0 / 10%);
background-color: white;
width: 15rem;
height: 13rem;
border-radius: 20px;
margin-left: 3%;
}
@media (max-width:1034px){
.customer_card{
width: 14rem;
}
}
@media (max-width:979px){
.customer_card{
width: 13.5rem;
}
}
@media (max-width:949px){
.customer_card{
width: 13rem;
}
}
@media (max-width:920px){
.customer_card{
width: 13rem;
}
}
.card_wrap{
margin: 1rem;
}
I have a page on my react project which contains the data of customers in card format and right now there are 3 card horizontally on my screen, now the problem is , i am trying to make it responsive and when i tried to do it whenever I slightly decrease the width of the screen the last card goes to next line and leaving a big chunk of space on the last line, for overcoming this problem i started to add media queries and decreasing my card width slighlty , but the problem arised that i have to do it after every 2 pixels, do i have to write the media query for every 2 pixels? Or is there any other way ? Here is the screenshot of the problem :-
Here is my JSX for this card only:-
<div className={`${customercss.parts} ${customercss.customer_card}`}>
<div className={customercss.card_wrap}>
<div className={customercss.customer_card_details} id={customercss.heading}>
<div className={customercss.customer_name}>
{elem.customer_name}
</div>
<label className={customercss.select_option}>
<input type="checkbox" name="checks" value={elem._id} id="checkbox" onClick={(e)=>selected_items(e,elem)} />
<span class={customercss.checkmark_span} ></span>
</label>
</div>
<div className={customercss.customer_card_details} id={customercss.customer_address}> <LocationOnOutlined htmlColor='#f7c6c6'/> {elem.customer_address}</div>
<div className={customercss.customer_card_details} id={customercss.date}> <CalendarToday htmlColor='#f7c6c6'/> {elem.date}</div>
<div className={customercss.customer_card_details} id={customercss.customer_other_options}>
<div className={customercss.customer_other_options_parts} id={customercss.option1}>
<div id={customercss.option1_1}>Subscriptions</div>
<div id={customercss.option1_2}>{elem.customer_items.length}</div>
</div>
<div className={customercss.customer_other_options_parts} id={customercss.option2}>
<MoreHoriz id={customercss.threedots} onClick={()=>{editcustomer(elem); show_edit_customer_details(elem)}} />
</div>
</div>
</div>
</div>
Here is the CSS(I have just added the css of the main box not the inside css) :-
.customer_card_box{
display: flex;
flex-wrap: wrap;
}
.customer_card{
box-shadow: 0 2px 4px rgb(0 0 0 / 10%), 0 8px 16px rgb(0 0 0 / 10%);
background-color: white;
width: 15rem;
height: 13rem;
border-radius: 20px;
margin-left: 3%;
}
@media (max-width:1034px){
.customer_card{
width: 14rem;
}
}
@media (max-width:979px){
.customer_card{
width: 13.5rem;
}
}
@media (max-width:949px){
.customer_card{
width: 13rem;
}
}
@media (max-width:920px){
.customer_card{
width: 13rem;
}
}
.card_wrap{
margin: 1rem;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用col-md-12的课程:
fin fin your.css文件使用媒体征服。
希望它能起作用。尝试一下。
You must use the class with col-md-12:
and after this fin your.css file use media-queries.
Hope it will work. Try this out.