Как я могу поместить div один под другим? - PullRequest
0 голосов
/ 26 февраля 2019

Это то, что я хочу сделать:

Сверху нужно зафиксировать панель навигации, чтобы она прокручивалась при прокрутке,

, затем я хочу, чтобы первый div был прямо подраздел навигацииИ этот div будет занимать 90% экрана (10% для панели навигации) и будет содержать только изображение.

Под ним находится div, в который я буду вставлять основной контент / текст.Если вы знаете, что я имею в виду, это займет 100% экрана, если вы понимаете, что я имею в виду?

Наконец, небольшая строка нижнего колонтитула в div тоже.

Глядя на мой код, вы увидите, чтоэто очень просто, я хочу сохранить это так .. Мне просто нужно, чтобы div оставался один под другим ..

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  padding: 0;
  margin: 0;
  border: 0;
  background-color: grey;
  background-attachment: fixed;
  background-size: 100% auto;
}

ul#horizontal-list {
  list-style: none;
}

ul#horizontal-list li {
  display: inline;
}

ul {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

li {
  float: center;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px;
  text-decoration: none;
}

li a:hover {
  background-color: red;
}

.navbar {
  position: relative;
  /*height: 10%;*/
  width: 100%;
  background-color: black;
  color: white;
  text-align: center;
}

.navbar ul {
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
  margin-top: 0px;
}

.header {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: url("img/background.jpg");
  background-color: grey;
}

.content {
  position: absolute;
  height: 100%;
  width: 100%;
  background-color: white;
}

.footer {
  height: 50px;
  width: 100%;
  background-color: yellow;
}
<!DOCTYPE html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="stylesheet.css">
  <title>John's Work</title>
  <meta name="description" content="My Personal Portfolio">
</head>

<body>


  <div class="navbar">

    <ul>
      <li><a href="index.html">HOME</a></li>
      <li><a href="about.html">ABOUT</a></li>
      <li><a href="contact.html">CONTACT</a></li>
    </ul>

  </div>


  <div class="header">

  </div>

  <div class="content">
    lorem ipsum text
  </div>

  <div class="footer">
    Copyright by
  </div>




</body>

</html>

Ответы [ 3 ]

0 голосов
/ 26 февраля 2019

удалены все свойства position:absolute всех элементов div.Надеюсь, это поможет

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}
body {
  padding: 0;
  margin: 0;
  border: 0;
  background-color: grey;
  background-attachment: fixed;
  background-size: 100% auto;
}
ul#horizontal-list {
  list-style: none;
}
ul#horizontal-list li {
  display: inline;
}
ul {
  margin: 0;
  padding: 0;
  overflow: hidden;
}
li {
  float: center;
}
li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px;
  text-decoration: none;
}
li a:hover {
  background-color: red;
}
.navbar {
  position: fixed;
    top: 0;
    height: 50px;
    width: 100%;
    background-color: black;
    color: white;
    text-align: center;
    left: 0;
    right: 0;
    z-index: 1;
}
.navbar ul {
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
  margin-top: 0px;
}
.header {
  width: 100%;
  height: 100%;
  background-image: url("img/background.jpg");
  background-color: grey;
}
.content {
  height: 100%;
    width: 100%;
    background-color: red;
}
.footer {
  height: 50px;
  width: 100%;
  background-color: yellow;
}
<!DOCTYPE html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="stylesheet.css">
  <title>John's Work</title>
  <meta name="description" content="My Personal Portfolio">
</head>
<body>
  <div class="navbar">
    <ul>
      <li><a href="index.html">HOME</a></li>
      <li><a href="about.html">ABOUT</a></li>
      <li><a href="contact.html">CONTACT</a></li>
    </ul>
  </div>
  <div class="header"></div>
  <div class="content">lorem ipsum text</div>
  <div class="footer">Copyright by</div>
</body>
</html>
0 голосов
/ 26 февраля 2019

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  padding: 0;
  margin: 0;
  border: 0;
  background-color: grey;
  background-attachment: fixed;
  background-size: 100% auto;
}

ul#horizontal-list {
  list-style: none;
}

ul#horizontal-list li {
  display: inline;
}

ul {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

li {
  float: center;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px;
  text-decoration: none;
}

li a:hover {
  background-color: red;
}
.holder{
    height: 100%;
    width: 100%;
}
.navbar {
    position: fixed;
    top: 0;
    height: 10%;
    width: 100%;
    background-color: black;
    color: white;
    text-align: center;
    left: 0;
    right: 0;
    z-index: 1;
}

.navbar ul {
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
  margin-top: 0px;
}

.header {
  width: 100%;
  height: 90%;
  background-image: url("img/background.jpg");
  background-color: grey;

}

.content {
    height: 100%;
    width: 100%;
    background-color: red;
}

.footer {
  height: 50px;
  width: 100%;
  background-color: orange;
}
<!DOCTYPE html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="stylesheet.css">
  <title>John's Work</title>
  <meta name="description" content="My Personal Portfolio">

</head>

<body>

<div class="holder">
  <div class="navbar">

    <ul>
      <li><a href="index.html">HOME</a></li>
      <li><a href="about.html">ABOUT</a></li>
      <li><a href="contact.html">CONTACT</a></li>
    </ul>

  </div>


  <div class="header">

  </div>
</div>
  <div class="content">
    lorem ipsum text
  </div>

  <div class="footer">
    Copyright by
  </div>




</body>

</html>
0 голосов
/ 26 февраля 2019

Удовлетворяет ли это вас (на самом деле я не понимаю, что вы хотите, но предположите что-то вроде этого)

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  padding: 0;
  margin: 0;
  border: 0;
  background-color: grey;
  background-attachment: fixed;
  background-size: 100% auto;
}

ul#horizontal-list {
  list-style: none;
}

ul#horizontal-list li {
  display: inline;
}

ul {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

li {
  float: center;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px;
  text-decoration: none;
}

li a:hover {
  background-color: red;
}

.navbar {
    position: fixed;
    height: 50px;
    top: 0px;
    width: 100%;
    background-color: black;
    color: white;
    text-align: center;
    z-index: 1;
}

.navbar ul {
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
  margin-top: 0px;
}

.header {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: url("img/background.jpg");
  background-color: grey;
}

.content {
  position: absolute;
      margin-top: 50px;
  height: 100%;
  width: 100%;
  background-color: white;
}

.footer {
  height: 50px;
  width: 100%;
  background-color: yellow;
}
<div class="navbar">

    <ul>
      <li><a href="index.html">HOME</a></li>
      <li><a href="about.html">ABOUT</a></li>
      <li><a href="contact.html">CONTACT</a></li>
    </ul>

  </div>


  <div class="header">

  </div>

  <div class="content">
    lorem ipsum text
  </div>

  <div class="footer">
    Copyright by
  </div>
...