<div class="list">
<div class="article">
<div class="article__img-container">
<div class="article__img" style="background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2015738/news__img_2.jpg) no-repeat center center; background-size: cover;">
</div>
</div>
<div class="article__title">Заголовок новости</div>
<div class="article__content">Далеко-далеко за, словесными горами в стране гласных и согласных живут рыбные тексты.</div>
<div class="article__info">
<a href="#" class="btn btn_type_8"><span class="btn__content">Читать
подробнее</span></a>
<div class="article__date">
01/01/2019
</div>
</div>
</div>
<!-- END article -->
<div class="article">
<div class="article__img-container">
<div class="article__img" style="background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2015738/news__img_2.jpg) no-repeat center center; background-size: cover;">
</div>
</div>
<div class="article__title">Заголовок новости</div>
<div class="article__content">Далеко-далеко за, словесными горами в стране гласных и согласных живут рыбные тексты.</div>
<div class="article__info">
<a href="#" class="btn btn_type_8"><span class="btn__content">Читать
подробнее</span></a>
<div class="article__date">
01/01/2019
</div>
</div>
</div>
<!-- END article -->
<div class="article">
<div class="article__img-container">
<div class="article__img" style="background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2015738/news__img_2.jpg) no-repeat center center; background-size: cover;">
</div>
</div>
<div class="article__title">Заголовок новости</div>
<div class="article__content">Далеко-далеко за, словесными горами в стране гласных и согласных живут рыбные тексты.</div>
<div class="article__info">
<a href="#" class="btn btn_type_8"><span class="btn__content">Читать
подробнее</span></a>
<div class="article__date">
01/01/2019
</div>
</div>
</div>
<!-- END article -->
<div class="article">
<div class="article__img-container">
<div class="article__img" style="background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2015738/news__img_2.jpg) no-repeat center center; background-size: cover;">
</div>
</div>
<div class="article__title">Заголовок новости</div>
<div class="article__content">Далеко-далеко за, словесными горами в стране гласных и согласных живут рыбные тексты.</div>
<div class="article__info">
<a href="#" class="btn btn_type_8"><span class="btn__content">Читать
подробнее</span></a>
<div class="article__date">
01/01/2019
</div>
</div>
</div>
<!-- END article -->
</div>
/* article */
.article {
display: flex;
flex-direction: column;
width: calc(50% - 20px);
margin: 10px;
transition: .3s all;
height: 320px;
}
.article_first {
width: calc(55% - 20px);
}
.article_first + .article {
width: calc(45% - 20px);
}
.article_second {
width: calc(45% - 20px);
}
.article_second + .article {
width: calc(55% - 20px);
}
.article__img-container {
height: 120px;
position: relative;
overflow: hidden;
transition: .3s all;
}
.article_first .article__img-container,
.article_second + .article .article__img-container {
height: 160px;
}
.article__img {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(../images/news__img_2.jpg) no-repeat center center;
background-size: cover;
transition: 0.3s all;
}
.article__title {
color: #8c570a;
font-weight: 700;
font-size: 22px;
padding: 20px 0;
}
.article__content {
color: #85878d;
font-size: 16px;
line-height: 20px;
height: 95px;
overflow: hidden;
}
.article__info {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 15px;
}
.article__date {
color: #737373;
font-family: "Candara";
font-size: 15px;
}
.list {
max-width: 600px;
width: 100%;
display: flex;
justify-content: center;
align-items: flex-start;
flex-wrap: wrap;
margin: 0 auto;
}
document.querySelectorAll('.article').forEach((element, index, array) => {
element.addEventListener('mouseover', event => {
document.querySelectorAll('.article_first').forEach((element) => {
element.classList.remove('article_first');
});
document.querySelectorAll('.article_second').forEach((element) => {
element.classList.remove('article_second');
});
if(index%2 == 0 ) {
element.classList.add('article_first');
} else {
element.previousElementSibling.classList.add('article_second');
}
});
});
document.querySelector('.list').addEventListener('mouseout', event => {
document.querySelectorAll('.article').forEach((element) => {
element.classList.remove('article_first');
});
document.querySelectorAll('.article').forEach((element) => {
element.classList.remove('article_second');
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.