Как спозиционировать див?

Как спозиционировать div portfolio относительно body, чтобы в последствии див work1 позиционировать относительно него? Сейчас work1 позиционируется относительно body и имеем необходимое мне положение, но, вероятно, так делать не правильно.

<!DOCTYPE html>
<html lang="rug">
<head>
	<meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
	<link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="shortcut icon" type="image/x-icon" href="images/">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700&display=swap" rel="stylesheet">
	<title>WELOVEDESIGN</title>
</head>
<body>
<div class="nav">
    <div class="logo"></div>
    <div class="razdelitel"></div>
    <div class="social">
        <a class="be" href="#"></a>
        <a class="insta" href="#"></a>
        <a class="vk" href="#"></a>
    </div>
    <div class="contacts">
    <div class="mail">
    <div class="mailicon"></div>
  <a>PRIMER@GMAIL.COM</a>
    </div>
<div class="telegram">
    <div class="telegramicon"></div>
    <a href="https://teleg.run/maximgolovlev">@PRIMER</a>
</div>
<div class="portfolio">
        
    <div class="work1"><img src="../htmlcss/images/work1.png"></div>
        
        </div>
    </div>
</div>
    </body>
</html>


body {
    font-size: 10px;
    font-family: 'Open Sans', sans-serif;
	background: #000000;

}
.nav {
    width: 1720px;
    display: flex;
    margin: 80px auto 0 auto;
    flex-flow: row nowrap;
}

.logo {
    width: 287px;
    height: 28px;
    background-image: url(../images/logo.png);
    background-repeat: no-repeat;
}

.razdelitel {
    margin-left:35px;
    width: 1px;
    height: 28px;
    background-color: #5b5b5b;
}

.be {
    display: inline-block;
    margin-top: 6px;
    margin-left: 35px;
    width: 21px;
    height: 16px;
    background-image: url(../images/be.png);
    background-repeat: no-repeat;
    
}

.be:hover {
    display: inline-block;
    transition: 1s;
    margin-top: 6px;
    margin-left: 35px;
    width: 21px;
    height: 16px;
    background-image: url(../images/behover.png);
    background-repeat: no-repeat;
    
}

.insta {
    display: inline-block;
    margin-top: 6px;
    margin-left: 15px;
    width: 16px;
    height: 16px;
    background-image: url(../images/insta.png);
    background-repeat: no-repeat;
    
}

.insta:hover {
    display: inline-block;
    transition: 1s;
    margin-top: 6px;
    margin-left: 15px;
    width: 16px;
    height: 16px;
    background-image: url(../images/instahover.png);
    background-repeat: no-repeat;
    
}

.vk {
    display: inline-block;
    margin-top: 6px;
    margin-left: 15px;
    width: 21px;
    height: 16px;
    background-image: url(../images/vk.png);
    background-repeat: no-repeat;
    
}

.vk:hover {
    display: inline-block;
    transition: 1s;
    margin-top: 6px;
    margin-left: 15px;
    width: 21px;
    height: 16px;
    background-image: url(../images/vkhover.png);
    background-repeat: no-repeat;
    
}

.contacts {
    display: flex;
    position: relative;
    padding-left: 21px;
    line-height: 16px;
}

.mailicon {
    display: inline-block;
    width: 21px;
    height: 16px;
    margin-left: 965px;
    background-image: url(../images/mail.png);
    background-repeat: no-repeat;
    position: absolute;
    top: 0px;
    left: 0px;
}

.mailicon:hover {
    display: inline-block;
    width: 21px;
    height: 16px;
    margin-left:px;
    background-image: url(../images/mailhover.png);
    background-repeat: no-repeat;
}

.telegramicon {
    display: inline-block;
    width: 21px;
    height: 16px;
    margin-left: 1150px;
    background-image: url(../images/telegram.png);
    background-repeat: no-repeat;
    position: absolute;
    top: 0px;
    left: 0px;    
}

.telegramicon:hover {
    display: inline-block;
    width: 21px;
    height: 16px;
    margin-left:;
    background-image: url(../images/telegramhover.png);
    background-repeat: no-repeat;
}

.mail {
    display: inline-block;
    margin-top: 6px;
    margin-left: 985px;
    width: 20px;
    height: 16px;

}
 
.mail:hover {
    display: inline-block;
    transition: 1s;
    margin-top: 6px;
    margin-left: 985px;
    width: 20px;
    height: 16px;
}
 


.telegram {
    display: inline-block;
    margin-top: 6px;
    margin-left: 150px;
    width: 20px;
    height: 16px;

}

 
.telegram:hover {
    display: inline-block;
    transition: 1s;
    margin-top: 6px;
    margin-left: 150px;
    width: 20px;

}


.mail a {
    display: inline-block;
    margin-left: 1000px;
    font-weight: 700;
    text-decoration: none;
    color: #5b5b5b;
    position: absolute;
    top: 0px;
    left: 0px;  
}

.mail a:hover {
    display: inline-block;
    color: #ff322e;
    transition: 0.5s;
}

.mail:hover .mailicon {
    background-image: url(../images/mailhover.png);
    background-repeat: no-repeat;
    transition: 0.5s;

}



.telegram a {
    display: inline-block;
    margin-left: 1180px;
    font-weight: 700;
    text-decoration: none;
    color: #5b5b5b;
    position: absolute;
    top: 0px;
    left: 0px;    
}

.telegram a:hover {
    display: inline-block;
    color: #ff322e;
    transition: 0.5s;

}


.telegram:hover .telegramicon {
    background-image: url(../images/telegramhover.png);
    background-repeat: no-repeat;
    transition: 0.5s;

}

.portfolio {


}

.work1 {
    position: absolute;
    left: 0px;
    top: 222px;
}
  • Вопрос задан
  • 46 просмотров
Решения вопроса 1
Ankhena
@Ankhena Куратор тега CSS
Нежно люблю верстку
Абсолюты позиционируются относительно ближайшего родителя с position отличным от static. Если его нет, то относительно body.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы