我有一个在主css中显示为网格的表单元素
.mainDiv {
.displayNone {
display: none;
}
.generalInfoSection {
.generalInfoTitle {
font-family: Montserrat;
font-style: normal;
font-weight: 600;
font-size: 20px;
line-height: 30px;
color: #23282d;
text-align: left;
}
.generalInfoFormSection {
.generalInfoForm {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto auto auto 150px;
grid-column-gap: 17px;
grid-row-gap: 25px;
margin-top: 16px;
这是我的媒体查询
@media (max-width: 768px) {
.mainDiv {
.displayNone {
display: none;
}
.generalInfoSection {
.generalInfoTitle {
font-family: Montserrat;
font-style: normal;
font-weight: 600;
font-size: 20px;
line-height: 30px;
color: #23282d;
text-align: left;
}
.generalInfoFormSection {
.generalInfoForm {
grid-template-columns: 1fr 1fr;
/* grid-template-rows: unset; */
grid-column-gap: 17px;
grid-row-gap: 25px;
margin-top: 16px;
每当我试图覆盖grid-template-columns时,为了使它只有2列,它保持在3列网格。我检查了检查器,样式正在应用,但输出仍然是3列而不是2列。这是使用react with styled-components。
1条答案
按热度按时间uurv41yg1#
如果你在获取媒体查询覆盖CSS中的grid-template-columns属性时遇到问题,可能有几个原因。下面是一些需要检查的事项:
1.专属性:请确保媒体查询的特定性等于或大于原始grid-template-columns属性。例如,如果原始CSS规则如下所示:
然后,您的媒体查询应类似于以下内容:
请注意,介质查询与原始规则具有相同的选择器,因此特异性相同。如果要增加介质查询的特异性,可以添加父选择器,如下所示:
1.缺少视口元标记:请确保您的HTML文档具有viewport meta标记,以确保浏览器在不同设备上正确呈现页面。如果没有此标记,媒体查询可能无法按预期工作。以下是viewport meta标记的示例: