Align content in a fixed footer

Matteo Rizzo

I'm trying to code a simple download page, but I can't get what I want to.

An image is worth a thousand words, so I sketched what I would like to get:
enter image description here

For now, I figured out how to:

  • keep the box fixed to the bottom, while
  • keeping the page scrollable

But I can't understand how to make the title and the button aligned in different sides, and the content of the "footer" aligned vertically...

Here's the actual "code"...

* {
  padding: 0;
  margin: 0;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  position: relative;
  margin: 5px;
}

::-webkit-scrollbar-track {
  box-shadow: #fff;
}

::-webkit-scrollbar-thumb {
  background-color: #222;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

* {
  box-sizing: border-box;
}

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

body {
  background: #fff;
  color: #222;
  font-family: "Gotham SSm A";
  text-align: center;
  display: table;
  margin: auto;
}

p {
  font-size: 18px;
  font-weight: 500;
  text-align: left;
  text-transform: uppercase;
  width: 100%;
  margin: auto;
  left: 0;
}

a {
  transition: 0.2s all;
  text-decoration: none;
}

.button {
  display: inline-block;
  padding: 10px 20px;
  font-family: "Gotham SSm A";
  font-size: 18px;
  font-weight: 500;
  line-height: 1.5;
  text-transform: uppercase;
  background: #fff;
  color: #222;
  border-radius: 2px;
  border: 0;
}

.button:hover,
.button:focus {
  color: #fff;
  background: #F9BF3B;
}

.download {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  padding: 1%;
  min-height: 50px;
  height: 15%;
  width: 100%;
  background: #fafafa;
  box-shadow: 0 0 15px 0 rgba(153, 153, 153, 0.5);
}

.left, .right {
  display: inline-block;
}
<div class="download">
  <div class="left">
    <p>left-aligned text</p>
  </div>

  <div class="right">
    <a href="#" class="button">button</a>
  </div>
</div>

Michael Schwartz

Weave made with Preprocessors: http://kodeweave.sourceforge.net/editor/#6a3f265ea39a9e4c296718eb64e08ecf
Weave: http://kodeweave.sourceforge.net/editor/#b3ebebb74666da608e8d8a19f2a1690d

Always try to keep your code DRY!

Considering your new to this I'm going to point a few things out before I answer your question. (but first checkout Common CSS questions)

There are a few errors in your code, remember that...
The universal selector * is known to be slow (only use it when absolutely necessary, because of this it's best to avoid using it as much as possible). NOTE: By default the html and body tags have a width 100%.

You should always utilize a good CSS reset library into your projects (Normalize is my personal favorite). This saves you most of the headache of styling your elements to work on other browsers.
As for CSS3 you would need something like Prefix-free or Autoprefixer to...

Break free from CSS prefix hell!

With that said.

The first thing I did was focus on centering your footer content.

In this case using margin, translate, position relative & top would be bad practice to center your text vertically. (The only relevant reason to use it would be if the font || font-size was different on the button than the default text, but in this case it's not so DON'T USE IT! (Remember DRY)

To align your text vertically you can use display table, display table-cell and vertical-align middle

In this case it'd be best to use text-align instead of float.

With that said by using display table and positioning the footer at the bottom. see code I was able to alleviate unnecessary uses of clear, margin and padding.

@import url('https://fonts.googleapis.com/css?family=Montserrat');
html, body {
  height: 100%;
}

/* Content Padding */
.content {
  padding: 1em;
}

/* Position and Style Footer */
.download {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 1em;
  background: #fff;
  box-shadow: 0 0 1.056em rgba(0, 0, 0, 0.5);
}
/* Footer Typography */
.download, .button {
  font-family: "Montserrat";
  font-size: 20px;
  font-weight: 500;
  line-height: 1.5;
  text-transform: uppercase;
  text-decoration: none;
}
/* Margin Button to Center */
.button {
  color: #000;
  padding: 10px 22px;
  border-radius: 0.4em;
  transition: all .2s ease;
}
.button:hover {
  color: #fff;
  background: #F9BF3B;
}

/* Vertically Align Content */
.table {
  display: table;
  width: 100%;
  height: 100px;
}
.cell {
  width: 100%;
  display: table-cell;
  vertical-align: middle;
}

/* Variable Classes */
.left {
  text-align: left;
}
.right {
  text-align: right;
}

/* Styles Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  position: relative;
  margin: 5px;
}
::-webkit-scrollbar-track {
  box-shadow: #fff;
}
::-webkit-scrollbar-thumb {
  background-color: #222;
}
::-webkit-scrollbar-corner {
  background: transparent;
}
<link href="https://necolas.github.io/normalize.css/4.1.1/normalize.css" rel="stylesheet"/>
<script src="https://leaverou.github.io/prefixfree/prefixfree.js"></script>

<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa praesentium velit quas esse itaque voluptate eos alias deserunt veniam, molestias exercitationem, maiores sed et vitae, iusto autem cum eaque? Maxime.</p>
  <p>Rerum, tempore, debitis! Ducimus perferendis qui doloribus ab, deleniti error cumque eaque consequatur soluta. Quidem incidunt, commodi qui soluta sed aut suscipit, nisi dolore. Tempora ipsa ut quod ipsum autem!</p>
  <p>Illo nisi eos quam neque adipisci a id autem sed distinctio, recusandae iure rem maiores, facere fugiat, harum sit reprehenderit dignissimos quaerat ut. Necessitatibus iure, suscipit blanditiis ipsum consectetur! Illum!</p>
  <p>Magnam autem dicta architecto necessitatibus accusamus expedita, at, accusantium nobis dolorem repellat vero earum beatae sunt iusto aut veritatis numquam deserunt blanditiis officia nihil! Ad, amet consectetur maiores quia earum?</p>
  <p>Nisi libero voluptatibus modi facere laboriosam ex provident. Quae dolorem tempore rem quia voluptate nisi consequuntur rerum earum fugiat neque, aperiam, iste culpa deserunt eligendi eos aspernatur ex harum ea.</p>
  <p>Adipisci, itaque ullam! Quis culpa tempora sunt dignissimos eaque porro laudantium excepturi, fugit quasi ex dolor repellendus neque magnam repellat fuga aliquid odio, veniam dicta cumque, laborum placeat rem commodi.</p>
  <p>Ad sunt optio nostrum, distinctio repellendus dignissimos, cum aut quos sed excepturi, nulla qui molestias? Ad quia, eligendi! Quam facilis consequatur laboriosam, adipisci et. Debitis ea facere ullam iure repellendus?</p>
  <p>Laborum, distinctio necessitatibus. Odit voluptatem fugit sint voluptates rem distinctio animi nihil beatae, molestiae explicabo tempora vero quam! Quidem autem itaque eos ratione voluptatum veritatis eveniet vitae aperiam aut voluptates?</p>
  <p>Soluta eos tempore, eum ducimus pariatur repellendus quaerat praesentium laudantium? Molestias laborum odio ratione temporibus rem id, excepturi magnam delectus facilis quibusdam quaerat exercitationem veniam vero architecto provident dolore sed.</p>
  <p>Quia, debitis odit obcaecati mollitia sunt enim natus ipsum, beatae corporis laborum id provident velit laudantium eveniet, fugiat. Velit minus ipsum nihil nemo, eos vero, soluta quos ab accusamus obcaecati.</p>
  <p>Nam quis, esse iure aliquid? Rem temporibus nemo aspernatur cupiditate accusamus, explicabo totam laboriosam odit magni quaerat maxime culpa vitae! Repellat velit quos eaque temporibus, tempore neque odio ex deserunt?</p>
  <p>Eveniet, unde quas debitis rem laboriosam cumque praesentium animi veniam temporibus ullam ipsam modi minima iusto repellat, tenetur reiciendis dolorum, officia dolor possimus. Esse quidem vitae perspiciatis velit a fuga.</p>
</div>

<div class="table">
  <div class="download">
    <div class="cell left">
      <p>left-aligned text</p>
    </div>

    <div class="cell right">
      <a class="button" href="javascript:void(0)">button</a>
    </div>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fixed header, fixed footer dynamic content

From Dev

Fixed column, fluid content and bottom fixed footer

From Dev

Footer That Should Be Below All Content, but Not Fixed

From Dev

Fixed Header and Footer not allowing page content to scroll?

From Dev

Sticky footer (not fixed) hiding main content

From Dev

(CSS) My fixed footer overlaps my content

From Dev

How to separate body content with fixed header and footer for multiple pages

From Dev

Vaadin basic layout: fixed header and footer + scrollable content

From Dev

Fixed Header/Footer, Scrollable Content, Space Above/Below

From Dev

Page Layout with Fixed HTML Header and Footer, with Flexible content

From Dev

Vaadin basic layout: fixed header and footer + scrollable content

From Dev

jquery mobile: fixed footer with nav panel not resized, content not centered

From Dev

Add fixed footer inside content that's already bounded by page-level header and footer

From Dev

How to make a fixed width sidebar align with the flexible content using flexbox

From Dev

Vertical align middle footer

From Dev

Align the list in the footer to center

From Dev

Method to align footer?

From Dev

sticky footer and fixed header

From Java

Fixed footer in Bootstrap

From Java

React Native fixed footer

From Dev

footer is fixed on viewpager in android

From Dev

Floating/fixed div in footer

From Dev

Fill FrameLayout with fixed footer

From Dev

Footer not fixed to the bottom of the page

From Dev

Android RecyclerView Fixed Footer

From Dev

Floating/fixed div in footer

From Dev

Creating a fixed footer with Bootstrap

From Dev

Fixed footer in android layout

From Dev

Absolute sidebar or fixed footer

Related Related

HotTag

Archive