我正在尝试使用display:grid;
更改我创建的图像网格,因此它在IE上看起来很不错。换句话说,找到一个解决方案,并排显示一些图像,而不使用网格或弹性框。
以下代码运行良好,您可以使用或不使用display:grid;
查看。但是,不是在Internet Explorer上 - IE。
要看的元素:
.about__asseenon-images
- 家长
.about__asseenon-logos
- 儿童
body {
padding: 5rem;
}
@media screen and (max-width: 900px) {
body {
padding: 3rem;
}
}
@media screen and (max-width: 750px) {
body {
padding: 1rem;
}
}
img {
width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
.secondary-heading {
font-family: "Dancing Script", cursive;
color: #662d91;
font-size: 2.5rem;
text-align: center;
font-weight: normal;
}
@media screen and (max-width: 1350px) {
.secondary-heading {
font-size: 2rem;
margin: 1rem 0;
}
}
@media screen and (max-width: 1100px) {
.secondary-heading {
font-size: 1.6rem;
}
}
@media screen and (max-width: 750px) {
.secondary-heading {
font-size: 1.3rem;
}
}
@media screen and (max-width: 600px) {
.secondary-heading {
font-size: 1.1rem;
}
}
.tablets {
display: none;
}
@media screen and (max-width: 900px) {
.tablets {
display: unset;
}
}
.about {
font-family: "Roboto", sans-serif;
font-size: 1.3rem;
text-align: justify;
border-width: 5px;
border-style: solid;
border-color: #662d91;
}
.about__extras {
display: flex;
justify-content: space-around;
margin: 2rem;
margin-top: 1rem;
}
.about__extras-figure {
margin: 0;
flex-basis: 30%;
flex-shrink: 0;
}
.about__extras-img {
margin: 0 auto;
}
.about__extras-info {
flex-shrink: 1;
flex-basis: 60%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.about__asseenon-logos {
height: auto;
width: 5%;
display: inline;
margin: 0.3rem;
}
/*
1 - Comment The @support to see the result I am trying to get to.
2 - Test this code on IE. You will see that the 'logos' will cross the screen and increase size.
*/
@supports ((display: -ms-grid) or (display: grid)) {
.about__asseenon-images {
display: -ms-grid;
display: grid;
-ms-grid-columns: (minmax(min-content, 1fr)) [8];
grid-template-columns: repeat(8, minmax(-webkit-min-content, 1fr));
grid-template-columns: repeat(8, minmax(min-content, 1fr));
-ms-grid-rows: (min-content) [3];
grid-template-rows: repeat(3, -webkit-min-content);
grid-template-rows: repeat(3, min-content);
grid-column-gap: 1rem;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
justify-items: center;
}
.about__asseenon-logos {
width: 90%;
grid-column: span 2;
}
.about__asseenon-logos:nth-child(5) {
-ms-grid-column: 2;
-ms-grid-column-span: 2;
grid-column: 2 / span 2;
}
}
<section class="about__extras">
<figure class="about__extras-figure">
<img src="http://via.placeholder.com/350x1150" alt="" class="about__extras-img">
</figure>
<div class="about__extras-info">
<div class="about__extras-asseenon">
<h2 class="secondary-heading">Beauty and Lifestyle Expert As Seen On:</h2>
<div class="about__asseenon-images">
<img src="http://via.placeholder.com/250x250" alt="nbc" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="cnn" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="Seventeen" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="FOX" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="style networks" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="girls life" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="Rolling-Out-Logo" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="Hope" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="elev8" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="hello beautyful" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="wdbr" class="about__asseenon-logos">
</div>
</div>
</div>
</section>
修改
这就是它在IE中的样子
这应该是它的外观(以及它在普通浏览器中的外观
)答案 0 :(得分:1)
如果不是使用与任何版本的Internet Explorer(外观Documentation on Mozilla Developer)不兼容的@supports
,而是通过JavaScript检测浏览器并向主体添加类,那该怎么办?
要检测浏览器,有一个很好的帖子like this。
在页面中添加包含课程的行
为Internet Explorer添加行:我不想在Internet Explorer中使用'Flex'我从来没有取得好成绩,我更喜欢使用经典的'display:inline-block'或'float:left'
if ((navigator.userAgent.indexOf("MSIE") != -1)
|| (!!document.documentMode == true)) // if IE > 10
{
document.body.className += 'InternetExplorer';
}
body {
padding: 5rem;
}
@media screen and (max-width: 900px) {
body {
padding: 3rem;
}
}
@media screen and (max-width: 750px) {
body {
padding: 1rem;
}
}
img {
width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
.secondary-heading {
font-family: "Dancing Script", cursive;
color: #662d91;
font-size: 2.5rem;
text-align: center;
font-weight: normal;
}
@media screen and (max-width: 1350px) {
.secondary-heading {
font-size: 2rem;
margin: 1rem 0;
}
}
@media screen and (max-width: 1100px) {
.secondary-heading {
font-size: 1.6rem;
}
}
@media screen and (max-width: 750px) {
.secondary-heading {
font-size: 1.3rem;
}
}
@media screen and (max-width: 600px) {
.secondary-heading {
font-size: 1.1rem;
}
}
.tablets {
display: none;
}
@media screen and (max-width: 900px) {
.tablets {
display: unset;
}
}
.about {
font-family: "Roboto", sans-serif;
font-size: 1.3rem;
text-align: justify;
border-width: 5px;
border-style: solid;
border-color: #662d91;
}
.about__extras {
display: flex;
justify-content: space-around;
margin: 2rem;
margin-top: 1rem;
}
.about__extras-figure {
margin: 0;
flex-basis: 30%;
flex-shrink: 0;
}
.about__extras-img {
margin: 0 auto;
}
.about__extras-info {
flex-shrink: 1;
flex-basis: 60%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.about__asseenon-logos {
height: auto;
width: 5%;
display: inline;
margin: 0.3rem;
}
/*
1 - Comment The @support to see the result I am trying to get to.
2 - Test this code on IE. You will see that the 'logos' will cross the screen and increase size.
*/
@supports ((display: -ms-grid) or (display: grid)) {
.about__asseenon-images {
display: -ms-grid;
display: grid;
-ms-grid-columns: (minmax(min-content, 1fr)) [8];
grid-template-columns: repeat(8, minmax(-webkit-min-content, 1fr));
grid-template-columns: repeat(8, minmax(min-content, 1fr));
-ms-grid-rows: (min-content) [3];
grid-template-rows: repeat(3, -webkit-min-content);
grid-template-rows: repeat(3, min-content);
grid-column-gap: 1rem;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
justify-items: center;
}
.about__asseenon-logos {
width: 90%;
grid-column: span 2;
}
.about__asseenon-logos:nth-child(5) {
-ms-grid-column: 2;
-ms-grid-column-span: 2;
grid-column: 2 / span 2;
}
}
/* Internet Explorer Fix */
.InternetExplorer .about__extras {
display: relative;
}
.InternetExplorer .about__extras-figure {
width: 30%;
display: inline-block
}
.InternetExplorer .about__extras-info {
width: 60%;
display: inline-block
}
.InternetExplorer .about__asseenon-images {
text-align: center;
}
.InternetExplorer .about__asseenon-logos {
display: inline-block;
margin: 2% 2%;
width: 19%;
}
.InternetExplorer .about__asseenon-logos:nth-of-type(7) {
margin-right: 5%;
}
.InternetExplorer .about__asseenon-logos:nth-of-type(5) {
margin-left: 5%;
}
<section class="about__extras">
<figure class="about__extras-figure">
<img src="http://via.placeholder.com/350x1150" alt="" class="about__extras-img">
</figure>
<div class="about__extras-info">
<div class="about__extras-asseenon">
<h2 class="secondary-heading">Beauty and Lifestyle Expert As Seen On:</h2>
<div class="about__asseenon-images">
<img src="http://via.placeholder.com/250x250" alt="nbc" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="cnn" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="Seventeen" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="FOX" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="style networks" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="girls life" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="Rolling-Out-Logo" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="Hope" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="elev8" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="hello beautyful" class="about__asseenon-logos">
<img src="http://via.placeholder.com/250x250" alt="wdbr" class="about__asseenon-logos">
</div>
</div>
</div>
</section>