2017-09-13 53 views
-1

问题是我无法将框的大小调整为50%,它们只是保持全宽。如何将div的大小调整为50%

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
} 
 

 

 
/* Mobile Styles */ 
 

 
@media only screen and (max-width: 400px) { 
 
    body { 
 
    background-color: #F09A9D; 
 
    /* Red */ 
 
    } 
 
} 
 

 

 
/* Tablet Styles */ 
 

 
@media only screen and (min-width: 401px) and (max-width: 960px) { 
 
    .sign-up, 
 
    .feature-1, 
 
    .feature-2, 
 
    .feature-3 { 
 
    width: 50%; 
 
    } 
 
} 
 

 

 
/* Desktop Styles */ 
 

 
@media only screen and (min-width: 961px) { 
 
    body { 
 
    background-color: #B2D6FF; 
 
    /* Blue */ 
 
    } 
 
} 
 

 
.page { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
} 
 

 
.section { 
 
    width: 100%; 
 
    height: 300px; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
} 
 

 
.menu { 
 
    background-color: #5995DA; 
 
    height: 80px; 
 
} 
 

 
.header { 
 
    background-color: #B2D6FF; 
 
} 
 

 
.content { 
 
    background-color: #EAEDF0; 
 
    height: 600px; 
 
} 
 

 
.sign-up { 
 
    background-color: #D6E9FE; 
 
} 
 

 
.feature-1 { 
 
    background-color: #F5CF8E; 
 
} 
 

 
.feature-2 { 
 
    background-color: #F09A9D; 
 
} 
 

 
.feature-3 { 
 
    background-color: #C8C6FA; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8" /> 
 
    <meta name="viewport" content="width=device-width,initial-scale=1"> 
 
    <title>Responsive Design</title> 
 
    <link rel="stylesheet" href="styles.css" /> 
 
</head> 
 

 
<body> 
 
    <div class="page"> 
 
    <div class="section menu"></div> 
 
    <div class="section header"> 
 
     <img src="images/header.svg" /> 
 
    </div> 
 
    <div class="section content"> 
 
     <img src="images/content.svg" /> 
 
    </div> 
 
    <div class="section sign-up"> 
 
     <img src="images/sign-up.svg" /> 
 
    </div> 
 
    <div class="section feature-1"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    <div class="section feature-2"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    <div class="section feature-3"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

+0

可以你给什么ü要实现屏幕截图? –

+0

不确定没有工作示例,但尝试添加“flex:1 1 50%;”以及平板电脑风格的最小/最大宽度为50%。 – niorad

回答

-1

给“重要”的风格

width: 50% !important; 
+0

在作出判断之前使用该代码 –

+0

这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 - [来自评论](/ review/low-quality-posts/17318069) – Jerodev

0

div的与类feature有另一个类称为section,我看到你所提到的部分的宽度即使在提及要素类的宽度为50%之后,这也是为什么它占据整个宽度的原因。

您可以删除在媒体屏幕部分的width属性和用50%的宽度设定的特征类或设置部分类的50%的宽度在媒体屏幕

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
} 
 

 

 
/* Mobile Styles */ 
 

 
@media only screen and (max-width: 400px) { 
 
    body { 
 
    background-color: #F09A9D; 
 
    width: 100%!important; 
 
    /* Red */ 
 
    } 
 
} 
 

 

 
/* Tablet Styles */ 
 

 
@media only screen and (min-width: 401px) and (max-width: 960px) { 
 
    .sign-up, 
 
    .feature-1, 
 
    .feature-2, 
 
    .feature-3 { 
 
    width: 50%; 
 
    } 
 
} 
 

 

 
/* Desktop Styles */ 
 

 
@media only screen and (min-width: 961px) { 
 
    body { 
 
    background-color: #B2D6FF; 
 
    /* Blue */ 
 
    } 
 
} 
 

 
.page { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
} 
 

 
.section { 
 
    /* width: 100%; this is overriding your feature class properties*/ 
 
    height: 300px; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
} 
 

 
.menu { 
 
    background-color: #5995DA; 
 
    height: 80px; 
 
} 
 

 
.header { 
 
    background-color: #B2D6FF; 
 
} 
 

 
.content { 
 
    background-color: #EAEDF0; 
 
    height: 600px; 
 
} 
 

 
.sign-up { 
 
    background-color: #D6E9FE; 
 
} 
 

 
.feature-1 { 
 
    background-color: #F5CF8E; 
 
} 
 

 
.feature-2 { 
 
    background-color: #F09A9D; 
 
} 
 

 
.feature-3 { 
 
    background-color: #C8C6FA; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8" /> 
 
    <meta name="viewport" content="width=device-width,initial-scale=1"> 
 
    <title>Responsive Design</title> 
 
    <link rel="stylesheet" href="styles.css" /> 
 
</head> 
 

 
<body> 
 
    <div class="page"> 
 
    <div class="section menu"></div> 
 
    <div class="section header"> 
 
     <img src="images/header.svg" /> 
 
    </div> 
 
    <div class="section content"> 
 
     <img src="images/content.svg" /> 
 
    </div> 
 
    <div class="section sign-up"> 
 
     <img src="images/sign-up.svg" /> 
 
    </div> 
 
    <div class="section feature-1"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    <div class="section feature-2"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    <div class="section feature-3"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

0

移动媒体查询,以便在.section之后出现。否则,你压倒他们。

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
} 
 

 
.page { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
} 
 

 
.section { 
 
    width: 100%; 
 
    height: 300px; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
} 
 

 
.menu { 
 
    background-color: #5995DA; 
 
    height: 80px; 
 
} 
 

 
.header { 
 
    background-color: #B2D6FF; 
 
} 
 

 
.content { 
 
    background-color: #EAEDF0; 
 
    height: 600px; 
 
} 
 

 
.sign-up { 
 
    background-color: #D6E9FE; 
 
} 
 

 
.feature-1 { 
 
    background-color: #F5CF8E; 
 
} 
 

 
.feature-2 { 
 
    background-color: #F09A9D; 
 
} 
 

 
.feature-3 { 
 
    background-color: #C8C6FA; 
 
} 
 

 

 
/* Mobile Styles */ 
 

 
@media only screen and (max-width: 400px) { 
 
    body { 
 
    background-color: #F09A9D; 
 
    /* Red */ 
 
    } 
 
} 
 

 

 
/* Tablet Styles */ 
 

 
@media only screen and (min-width: 401px) and (max-width: 960px) { 
 
    .sign-up, 
 
    .feature-1, 
 
    .feature-2, 
 
    .feature-3 { 
 
    width: 50%; 
 
    } 
 
} 
 

 

 
/* Desktop Styles */ 
 

 
@media only screen and (min-width: 961px) { 
 
    body { 
 
    background-color: #B2D6FF; 
 
    /* Blue */ 
 
    } 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8" /> 
 
    <meta name="viewport" content="width=device-width,initial-scale=1"> 
 
    <title>Responsive Design</title> 
 
    <link rel="stylesheet" href="styles.css" /> 
 
</head> 
 

 
<body> 
 
    <div class="page"> 
 
    <div class="section menu"></div> 
 
    <div class="section header"> 
 
     <img src="images/header.svg" /> 
 
    </div> 
 
    <div class="section content"> 
 
     <img src="images/content.svg" /> 
 
    </div> 
 
    <div class="section sign-up"> 
 
     <img src="images/sign-up.svg" /> 
 
    </div> 
 
    <div class="section feature-1"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    <div class="section feature-2"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    <div class="section feature-3"> 
 
     <img src="images/feature.svg" /> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>