Управление блоком post-stats 18/18

На 100% сделать то получилось, но вот в правильности я не уверен.


html, body {
margin: 0;
padding: 0;
}

body {
width: 280px;
min-height: 250px;
padding-top: 50px;
padding-left: 10px;
padding-right: 10px;
font-size: 12px;
font-family: “Arial”, sans-serif;
line-height: 1.2;
color: #7f8c8d;
background: #ecf0f1;
}

.post-stats .icon {
width: 15px;
height: 15px;
}

/*
Все размеры, отступы, координаты, размеры шрифтов (не заданные в body) кратны 5 или 10.
Ардеса картинок:
/assets/course14/quotes.png
/assets/course14/post-challenge.png
Картинка “кавычки” выровнена по центру
*/

.post {
position: relative;
}

.post-title {
margin-left: 75px;
margin-bottom: 5px;
font-size: 20px;
color: #2980b9;
}

.post-date {
position: absolute;
top: 0px;
left: 0px;
width: 55px;
height: 55px;
line-height: 55px;
text-align: center;
vertical-align: middle;
background-color: #ffffff;
border-bottom: 5px solid #bdc3c7;
font-size: 15px;
font-weight: bold;
}

.post-type {
position: absolute;
top: 70px;
left: 0px;
width: 55px;
height: 55px;
background: #7f8c8d url("/assets/course14/quotes.png") no-repeat 50% 50%;
border-bottom: 5px solid #bdc3c7;
}

.post-author {
margin-left: 75px;

}

.post a {
color: #2980b9;
text-decoration: none;
}

.post-stats {
position: relative;
display: inline-block;
margin-top: 5px;
margin-left: 75px;
margin-right: -65px;
}

.post-stats .icon {
position: absolute;
background-image: url("/assets/course14/post-challenge.png");
background-repeat: no-repeat;
}

.post-stats .icon-tags {
background-position: 0 0;
}

.post-stats .icon-comments {
background-position: -20px 0;
}

.post-stats a:nth-child(2) {
margin-left: 20px;
}

.post-text {
margin-top: 20px;
margin-left: 75px;
padding: 10px 15px;
background: #ffffff;
border-bottom: 5px solid #bdc3c7;
}


Вся проблема заключается в том что правильно ли было использовать отрицательный отступ в селекторе post-stats? Меня не покидает чувство, что есть более простое решение.

При относительном позиционировании также доступны координаты top, left, bottom, right.
Можно воспользоваться.
.post-stats {
position: relative;
display: inline-block;
margin-top: 5px;
left: 75px;
margin-right: 10px;
}

2 лайка

Оу, а это то мне в голову и не пришло. Спасибо за помощь

1 лайк

В .post-date команда vertical-align бесполезна, т.к. сам текст выравнивался line-height. Можете попробовать убрать вертикальное выравнивание, разницы не будет :slight_smile:

Чтобы каждый раз не задавать отступ от левого края, чтобы вписать иконки, можно было прописать padding: 75 px в “прародителе”,post.

В общем, у нас с Вами есть отличая, а вот результат и у меня 100%. Сравните, если будет желание, я из Вашего кода кое-что также подчерпнул :wink:

CSS

html, body {
    margin: 0;
    padding: 0;
}
body {
    width: 280px;
    min-height: 250px;
    padding-top: 50px;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 12px;
    font-family: "Arial", sans-serif;
    line-height: 1.2;
    color: #7f8c8d;
    background: #ecf0f1;
}
.post-stats .icon {
    width: 15px;
    height: 15px;
}
/*
Все размеры, отступы, координаты, размеры шрифтов (не заданные в body) кратны 5 или 10.
Ардеса картинок:
/assets/course14/quotes.png
/assets/course14/post-challenge.png
Картинка "кавычки" выровнена по центру
*/
.post {
    position: relative;
    padding: 0;
    margin: 0;
    padding-left: 75px;
    width: 210px;
    min-height: 250px;
}
.post-title {
    color: #2980b9;
    font-size: 20px;
    margin-bottom: 5px;
}
.post-date {
    position: absolute;
    top: 0px;
    left: 0px;
    display: inline-block;
    font-weight: bold;
    font-size: 15px;
    width: 55px;
    height: 55px;
    line-height: 55px;
    text-align: center;   
    border-bottom: 5px solid #bdc3c7;
    background-color: #ffffff;
}
.post-type {
    position: absolute;
    top: 70px;
    left: 0px;
    display: inline-block;
    font-weight: bold;
    background: #7f8c8d url("/assets/course14/quotes.png") no-repeat 50% 50%;
    font-size: 15px;
    width: 55px;
    height: 55px;
    border-bottom: 5px solid #bdc3c7;
}
.post-author {
    margin-bottom: 5px;
}
.post-author > a {
    text-decoration: none;
    color: #2980b9;
}
.post-stats {
    position: relative;
    display: inline-block;
    margin-right: 10px;
    margin-left: 20px;
}
.post-stats .icon {
    background-image: url("/assets/course14/post-challenge.png");
}
.post-stats > a {
    text-decoration: none;
    color: #2980b9;
}
.icon-tags {
    position: absolute;
    right: 123px;
    background-position: 0 0;    
}
.icon-comments {
    position: absolute;
    right: 11px;
    background-position: -100px 0px;    
}
.post-text {
    width: 175px;
    padding: 10px 15px;
    margin-top: 20px;
    border-bottom: 5px solid #bdc3c7;
    background-color: #ffffff;
}
1 лайк

В условиях написанно: > Все размеры, отступы, координаты, размеры шрифтов (не заданные в body) кратны 5 или 10.

В вашем решение:
.icon-tags {
position: absolute;
right: 123px;
.icon-comments {
position: absolute;
right: 11px;

Я на 99% сделал.

     <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Испытание: анонс поста</title>
    </head>
    <body>
        <div class="post">
            <div class="post-title">Интенсив: программа</div>
            <div class="post-date">13.09</div>
            <div class="post-type"></div>
            <div class="post-author">
                Автор: <a href="#">HTML Academy</a>
            </div>
            <div class="post-stats">
                <div class="icon icon-tags"></div>
                <a href="#">интенсив</a>,
                <a href="#">программа</a>
            </div>
            <div class="post-stats">
                <div class="icon icon-comments"></div>
                <a href="#">5</a>
            </div>
            <div class="post-text">Работа над интенсивом идёт полным ходом. Мы нашли крутых людей в команду и решили еще кучу задач. Но сегодня я подробнее расскажу</br> о работе над программой интенсива.</div>
        </div>
    </body>
</html>

CSS

html, body {
margin: 0;
padding: 0;
}

body {
width: 280px;
min-height: 250px;
padding-top: 50px;
padding-left: 10px;
padding-right: 10px;
font-size: 12px;
font-family: “Arial”, sans-serif;
line-height: 1.2;
color: #7f8c8d;
background: #ecf0f1;
}

.post-stats .icon {
width: 15px;
height: 15px;
}
.post {
position:relative;
margin:0px;
/margin-left:0px;/
padding-left:75px;
padding-right:0px}
.post-date {
position:absolute;
width:55px;
height:55px;
background-color:#ffffff;
text-align:center;
line-height:55px;
top:0px;
left:0px;
border-bottom:5px solid #bdc3c7;
font-size:15px;
font-weight:bold;
}
.post-title {
font-size:20px;
color:#2980b9;
margin-bottom:5px;
}
.post-type {
position:absolute;
width:55px;
height:55px;
background-color:#7f8c8d;
background-image: url("/assets/course14/quotes.png");
background-repeat: no-repeat;
background-position:center;
top:70px;
left:0px;
border-bottom:5px solid #bdc3c7;
}
.post-author {
margin-bottom:5px;
}
.post-stats {
display:inline-block;
vertical-align:middle;
margin-bottom:20px;
margin-right:10px;
padding-left:20px;
}
.icon-tags {
background-image: url("/assets/course14/post-challenge.png");
background-repeat: no-repeat;
background-position:0px 0px;
}
.icon-comments {
background-image: url("/assets/course14/post-challenge.png");
background-repeat: no-repeat;
background-position:-20px 0px;
}
.icon {
position:absolute; }

.post-stats .icon-tags {
left:75px;}
.post-stats .icon-comments {
left:225px;}

.post-text {
background-color:#ffffff;
padding:10px;
padding-left:15px;
border-bottom:5px solid #bdc3c7;}

.post a{
color:#2980b9;
text-decoration:none;
}

1 лайк

Так будет еще лучше:
.post-stats {
position: relative;
display:inline-block;
vertical-align:middle;
margin-bottom:20px;
margin-right:10px;
padding-left:20px;
}
.post-stats .icon-tags {
left: 0;
}
.post-stats .icon-comments {
left: 0;
}

2 лайка

Thanks!!!
100%

У меня тоже с абсолютами не кратно 5 получается.
И хоть у меня на 100%, но что-то сдается мне, что коряво написан код :frowning:

.post {
    margin: 0;
    padding: 0;
}
.post-title {
    font-size: 20px;
    margin-left: 75px;
    color: #2980b9;
}
.post-date {
    position: absolute;
    top: 50px;
    left: 10px;
    background: #ffffff;
    border-bottom: 5px solid #bdc3c7;
    text-align: center;
    font-weight: bold;
    font-size: 15px;
    width: 55px;
    padding: 20px 0px;
    line-height: 1;
    
}
.post-type{
    position: absolute;
    top: 120px;
    left: 10px;
    width: 55px;
    height: 55px;
    border-bottom: 5px solid #bdc3c7;
    background: #7f8c8d url("/assets/course14/quotes.png") no-repeat 50% 50%;
}
.post-author {
    margin-left: 75px;
    margin-top: 5px;
    margin-bottom: 0px;
}
.post-author a{
    text-decoration: none;
    color: #2980b9;
    
}
.post-stats {
    margin-left: 95px;
    display: inline-block;
    margin-top: 5px;
}
.post-stats a{
    text-decoration: none;
    color: #2980b9;
}
.post :nth-child(6) {
    margin-left: 30px;
}
.icon {
    background: url("/assets/course14/post-challenge.png") no-repeat;
}
.icon-tags {
    position: absolute;
    top: 98px;
    left: 85px;
}
.icon-comments {
    background-position: -20px 0px;
    position: absolute;
    top: 98px;
    left: 237px;
}

.post-text {
    background: #ffffff;
    margin: 20px 0px 25px 75px;
    border-bottom: 5px solid #bdc3c7;
    padding: 10px 15px;
    font-size: 12px;
}

Можно так подправить:
.post {
margin: 0;
padding: 0;
position: relative;
}
.post-title {
font-size: 20px;
/margin-left: 75px;/
position: relative;
left: 75px;
color: #2980b9;
}
.post-date {
position: absolute;
top: 0;
left: 0;
background: #ffffff;
border-bottom: 5px solid #bdc3c7;
text-align: center;
font-weight: bold;
font-size: 15px;
width: 55px;
padding: 20px 0px;
line-height: 1;

}
.post-type{
position: absolute;
top: 70px;
left: 0;
width: 55px;
height: 55px;
border-bottom: 5px solid #bdc3c7;
background: #7f8c8d url("/assets/course14/quotes.png") no-repeat 50% 50%;
}
.post-author {
/margin-left: 75px;
margin-top: 5px;
margin-bottom: 0px;
/
left: 75px;
top: 5px;
position: relative;
}
.post-author a{
text-decoration: none;
color: #2980b9;

}
.post-stats {
/margin-left: 95px;/
position: relative;
left: 75px;
top: 5px;
padding-left: 20px;
margin-right: 10px;
margin-bottom: 20px;
display: inline-block;
margin-top: 5px;
}
.post-stats a{
text-decoration: none;
color: #2980b9;
}
/.post :nth-child(6) {
margin-left: 30px;
}
/
.icon {
background: url("/assets/course14/post-challenge.png") no-repeat;
position: absolute;
}
.icon-tags {
top: 0;
left: 0;
}
.icon-comments {
background-position: -20px 0px;
top: 0;
left: 0;
}

.post-text {
background: #ffffff;
/margin: 20px 0px 25px 75px;/
border-bottom: 5px solid #bdc3c7;
padding: 10px 15px;
font-size: 12px;
position: relative;
left: 75px;
top: 5px;
width: 175px;
}
Если есть вопросы, то задавайте.

1 лайк