Нижний колонтитул плавает в середине на странице - PullRequest
1 голос
/ 31 мая 2019

Есть ли способ установить нижний колонтитул внизу страницы? Нижний колонтитул должен иметь ширину 100%, а также .wrapper 960px.

Я уже пробовал:

  1. position: relative; - вставляется между .content тегами
  2. position: absolute; - придерживается .nav
  3. position: fixed; - может быть решение, но оно мне не нужно постоянно, просто внизу последней страницы.
  4. чтобы переместить .footer за пределы .wrapper и установить .wrapper:not(footer); - нижний колонтитул приклеен к нижней части, но ширина не изменилась.

Любое предложение, как можно установить его внизу?

@charset "UTF-8";
@import url('https://fonts.googleapis.com/css?family=Montserrat|Nunito+Sans|Roboto&display=swap');
* {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  word-wrap: break-word;
}

html,
body,
header,
main {
  height: 100%;
}

body {
  width: 100%;
  font-family: Roboto, Verdana, sans-serif;
  font-size: 1em;
  background-image: url(../images/extra_clean_paper.png);
  background-repeat: repeat;
}

header {
  text-align: center;
  background-color: yellow;
}

#hero-header {
  position: relative;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

#hero-btn {
  width: 50px;
  height: 50px;
  position: absolute;
  bottom: 4em;
  left: 50%;
  -webkit-transform: translateX(-50%);
  -ms-transform: translateX(-50%);
  transform: translateX(-50%);
}

.hero-btn a {
  position: relative;
  display: inline-block;
  color: black;
  text-decoration: none;
  -webkit-transition: opacity .3s;
  -o-transition: opacity .3s;
  transition: opacity .3s;
}

.hero-btn a:hover {
  opacity: 0.5;
}

header a {
  padding-top: 70px;
}

header a span {
  position: absolute;
  top: 0;
  left: 50%;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  border-left: 1px solid black;
  border-bottom: 1px solid black;
  -webkit-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  transform: rotate(-45deg);
  -webkit-animation: sdb07 2s infinite;
  animation: sdb07 2s infinite;
  opacity: 0;
}

header a span:nth-of-type(1) {
  -webkit-animation-delay: 0s;
  animation-delay: 0s;
}

header a span:nth-of-type(2) {
  top: 16px;
  -webkit-animation-delay: .15s;
  animation-delay: .15s;
}

header a span:nth-of-type(3) {
  top: 32px;
  -webkit-animation-delay: .3s;
  animation-delay: .3s;
}

@-webkit-keyframes sdb07 {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes sdb07 {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

#resp-nav {
  text-align: center;
  display: none;
  background-color: grey;
}

#resp-nav i {
  font-size: 2em;
  color: white;
}

#nav {
  text-align: center;
  background-color: dimgray;
  z-index: 2;
}

main:not(#footer) {
  max-width: 960px;
  margin: 0 auto;
}

.container {
  background-color: #eeeeee;
  border: 1px solid red;
  border-radius: 5px;
  clear: both;
  overflow: hidden;
  margin-top: 1em;
  min-height: 100%;
  padding: 3.125em 0.625em;
  -webkit-box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3);
  box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3);
}

.aboutme img {
  width: 100%;
  height: auto;
}

.aboutme .col-40 {
  margin-top: 1em;
  padding-left: 1em;
  padding-right: 1em;
  width: 39%;
}

.aboutme .col-60 {
  margin-top: 1em;
  padding-left: 1em;
  padding-right: 1em;
  width: 59%;
}

.left {
  float: left;
}

.right {
  float: right;
}

.table {
  display: table;
  border-collapse: collapse;
  table-layout: fixed;
}

.hobbies .table-row {
  display: table-row;
  border-bottom: 0.1em solid darkgrey;
}

.hobbies .table-row:last-child {
  border: 0;
}

.hobbies .table-cell {
  display: table-cell;
  padding-left: 1em;
  padding-right: 1em;
  vertical-align: middle;
  text-align: center;
  width: 50%;
}

.portfolio .col-50 {
  margin-top: 1em;
  padding-left: 1em;
  padding-right: 1em;
  width: 49%;
}

.projects .flex-row {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.projects .col-33 {
  position: relative;
  width: 100%;
  max-width: 33%;
  -ms-flex: 0 0 33%;
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 33%;
  flex: 0 0 33%;
}

.projects .services-box {
  background: #f9f9f9;
  padding: 10px;
  margin: 20px 5px 0 5px;
}

footer {
  background: red;
  height: 50px;
  width: 100%;
  position: relative;
  bottom: 0;
  left: 0;
  margin-top: 10px;
}
<header id="link-hero-page">
  <div id="hero-header">
  </div>
</header>
<nav>
  <ul id="nav">
  </ul>
</nav>
<main>
  <section id="link-main" class="aboutme container">
    <div class="col-40 left">
    </div>
    <article class="col-60 right">
    </article>
  </section>
  <section id="link-hobbies" class="hobbies container">
    <div class="table">
      <div class="table-row">
        <article class="table-cell">
        </article>
      </div>
      <div class="table-row">
        <div class="table-cell">
        </div>
        <article class="table-cell">
        </article>
      </div>
      <div class="table-row">
        <article class="table-cell">
        </article>
      </div>
    </div>
  </section>
  <section id="link-portfolio" class="portfolio container">
    <article class="col-50 left">
    </article>
    <article class="col-50 right">
    </article>
  </section>
  <section id="link-projects" class="projects container">
    <div class="flex-row">
      <div class="col-33">
        <article class="services-box">
        </article>
      </div>
      <div class="col-33">
        <article class="services-box">
        </article>
      </div>
      <div class="col-33">
        <article class="services-box">
        </article>
      </div>
    </div>
  </section>
  <section id="link-contacts" class="contacts container">

  </section>
</main>
<!--FOOTER-->
<footer>
  <address>
				<p style="text-align: center;">LOREM LOREM LOREM LOREM LOREM</p>
			</address>
</footer>

https://jsfiddle.net/1adkjLw0/

Ответы [ 2 ]

0 голосов
/ 31 мая 2019

Просто переместите нижний колонтитул за пределы оболочки.

       * {
		  margin: 0;
		  padding: 0;
		}

		html,
		body {
		  height: 100%;
		}

		body {
		  width: 100%;
		}

		.nav {
		  background: green;
		  height: 50px;
		}

		.wrapper {
		  max-width: 500px;
		  margin: 0 auto;
		}

		.content {
		  background: yellow;
		  margin-top: 10px;
		  height: 100px;
		}

		.footer {
		  background: red;
		  height: 50px;
		  width: 100%;
		  position: relative;
		  bottom: 0;
		  left: 0;
		  margin-top: 10px;
		}
<div class="nav"></div>
<div class="wrapper">
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>  
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>
</div>
<div class="footer"></div>
0 голосов
/ 31 мая 2019

Один из вариантов - превратить ваш контейнер в вертикальный флексбокс и установить margin-top: auto в нижнем колонтитуле, который подтолкнет его к нижней части гибкого контейнера.Вам также нужно установить height: 100% для контейнера, чтобы он заполнил всю страницу

* {
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  width: 100%;
}

.nav {
  background: green;
  height: 50px;
}

.wrapper {
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.content {
  background: yellow;
  margin-top: 10px;
  height: 100px;
}

.footer {
  background: red;
  height: 50px;
  width: 100%;
  position: relative;
  margin-top: auto;
  bottom: 0;
  left: 0;
}
<body>

<div class="nav"></div>

<div class="wrapper">

  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>  
  <div class="content"></div>
  <div class="content"></div>
  <div class="content"></div>

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

</div>

</body>
...