Ширина элемента Flex не изменяется в IE - PullRequest
0 голосов
/ 10 января 2019

Я пытаюсь создать множество «плиток», и у меня возникают проблемы в Internet Explorer - большинство / все другие браузеры выглядят нормально. Проблема в том, что я хочу, чтобы количество плиток составляло только 4 на строку на рабочем столе и 2 на строку на мобильных устройствах, но в IE другие плитки просто сжимаются в той же строке, а не переходят на следующую строку.

Кажется, что ширина гибких элементов не работает, и должна составлять 23,5% (на рабочем столе) и 48,5% на мобильных устройствах. Может кто-нибудь объяснить, что здесь происходит? Похоже, IE не любит современный код!

/* Flex Tests */
.sad-flex {
    display: flex;
    flex-flow: row wrap;
}
.flex-item {
    width: 23.5%;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.flex-item:not(:nth-of-type(4n+1)) { margin-left: 2% }
.flex-item:nth-of-type(n+5) { margin-top: 2% }
.flex-item-image-link { width: 100% }
.flex-item img {
    width: 100%;
    background-size: cover;
    background-position: center;
}
.flex-item, .flex-text-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1em;
    text-align: center;
    font-family: arial; /* perhaps remove */
    justify-content: flex-start;
}
.flex-text-content { padding: 10px }
.flex-item .flex-text.header {
    margin-bottom: 0;
    font-weight: 700;
    width: 100%;
}
.flex-item .flex-text.header a { color: #000 }
.flex-item .flex-text.price {
    padding-top: 20px;
    font-size: 1.4em;
    color: grey;
}
.flex-item .flex-text.description {
    font-size: 1em;
    padding-top: 20px;
    max-height: 6em; /* limits to 3 lines of text */
    overflow: hidden;
}
.flex-item .flex-btn {
    border: none;
    outline: 0;
    padding: 12px;
    color: #fff;
    background-color: #000;
    cursor: pointer;
    width: 100%;
    font-size: 1.3em;
    margin: auto auto 0 auto;
}
.flex-item .flex-btn:hover { opacity: 0.7 }
.flex-item ul { text-align: left }
@media (max-width: 767px) {
    .flex-item:not(:nth-of-type(4n+1)) { margin-left: 3% }
    .flex-item { width: 48.5% }
    .flex-item:not(:nth-of-type(even)) { margin-left: 0 }
    .flex-item:nth-of-type(n+3) { margin-top: 3% }
}
/* IE FIXES */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .sad-flex {
        -ms-flex-direction: row;
        -ms-flex-wrap: wrap;
    }
    .flex-item {
        -ms-flex: 1;
    }
    .flex-item * { width: 100% }
}
<div class="sad-flex">

    <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
    

<div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>

</div>

1 Ответ

0 голосов
/ 10 января 2019

IE не поддерживает сокращение flex: flex-grow flex-shrink flex-basis.

Вам нужно изменить его на flex-grow.

Например, это

flex: 1 2 30px;

следует заменить на этот

flex-grow: 1;
flex-shrink: 2;
flex-basis: 30px;

В вашем случае

.flex-item {
    flex-grow: 1;
}

/* Flex Tests */
.sad-flex {
    display: flex;
    flex-flow: row wrap;
}
.flex-item {
    width: 23.5%;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.flex-item:not(:nth-of-type(4n+1)) { margin-left: 2% }
.flex-item:nth-of-type(n+5) { margin-top: 2% }
.flex-item-image-link { width: 100% }
.flex-item img {
    width: 100%;
    background-size: cover;
    background-position: center;
}
.flex-item, .flex-text-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1em;
    text-align: center;
    font-family: arial; /* perhaps remove */
    justify-content: flex-start;
}
.flex-text-content { padding: 10px }
.flex-item .flex-text.header {
    margin-bottom: 0;
    font-weight: 700;
    width: 100%;
}
.flex-item .flex-text.header a { color: #000 }
.flex-item .flex-text.price {
    padding-top: 20px;
    font-size: 1.4em;
    color: grey;
}
.flex-item .flex-text.description {
    font-size: 1em;
    padding-top: 20px;
    max-height: 6em; /* limits to 3 lines of text */
    overflow: hidden;
}
.flex-item .flex-btn {
    border: none;
    outline: 0;
    padding: 12px;
    color: #fff;
    background-color: #000;
    cursor: pointer;
    width: 100%;
    font-size: 1.3em;
    margin: auto auto 0 auto;
}
.flex-item .flex-btn:hover { opacity: 0.7 }
.flex-item ul { text-align: left }
@media (max-width: 767px) {
    .flex-item:not(:nth-of-type(4n+1)) { margin-left: 3% }
    .flex-item { width: 48.5% }
    .flex-item:not(:nth-of-type(even)) { margin-left: 0 }
    .flex-item:nth-of-type(n+3) { margin-top: 3% }
}
/* IE FIXES */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .sad-flex {
        -ms-flex-direction: row;
        -ms-flex-wrap: wrap;
    }
    .flex-item {
        flex-grow: 1;
    }
    .flex-item * { width: 100% }
}
<div class="sad-flex">

    <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
    

<div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>
  
  <div class="flex-item">
    <a class="flex-item-image-link" href="/shop/i/turtle/"><img style='background-image: url("https://images.pexels.com/photos/133394/pexels-photo-133394.jpeg");' src="https://cml.sad.ukrd.com/tp/3x2/"></a>
    <div class="flex-text-content">
        <h2 class="flex-text header"><a href="#">textko</a></h2>
        <span class="flex-text price">$12.34</span>
        <span class="flex-text description">text here text here text here text here text here text heret ext here .</span>
    </div>
    <button class="flex-btn" onclick="#'">button</button>
</div>

</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...