Category: HTML

HTML: how to vertically center an object with CSS?

xml tag

There are several ways to vertically center an object with CSS:

Flexbox

<div class="container">
  <div class="center-item">
    <!-- content goes here -->
  </div>
</div>
.container {
  display: flex;
  align-items: center;
  height: 100%;
}

This method uses the CSS flexbox layout to center the child element vertically within the parent container. The align-items property set to center aligns the child element along the cross axis.

Grid Layout

<div class="container">
  <div class="center-item">
    <!-- content goes here -->
  </div>
</div>
.container {
  display: grid;
  place-items: center;
  height: 100%;
}

This method uses the CSS grid layout to center the child element vertically and horizontally within the parent container. The place-items property set to center aligns the child element both vertically and horizontally.

Table Cell

<div class="container">
  <div class="center-item">
    <!-- content goes here -->
  </div>
</div>
.container {
  display: table-cell;
  vertical-align: middle;
  height: 100%;
}

This method uses the CSS table layout to center the child element vertically within the parent container. The display: table-cell and vertical-align: middle properties treat the parent container as a table cell and vertically center the child element within it.

Transforms

<div class="container">
  <div class="center-item">
    <!-- content goes here -->
  </div>
</div>
.container {
  position: relative;
  height: 100%;
}
.center-item {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

This method uses CSS transforms to center the child element vertically within the parent container. The top: 50% property positions the child element vertically halfway down the parent container, and the transform: translateY(-50%) property moves the child element upwards by half its own height, effectively centering it vertically within the parent container.

Foto von Jackson Sophat auf Unsplash.

 

UX improvements: `enterkeyhint` to define action label for the keyboard of mobile devices

Usability

The enterkeyhint is a html attribute described in the HTML standard, which can be used to improve the context of action buttons of keyboards on mobile device.

The enterkeyhint content attribute is an enumerated attribute that specifies what action label (or icon) to present for the enter key on virtual keyboards. This allows authors to customize the presentation of the enter key in order to make it more helpful for users.

It allows the following fixed values: enter, done, go, next, previous, search and send. Let’s have a look at those values and the resulting keyboard style on iOS:

<input>

The default behavior without any value.

<input enterkeyhint=”enter”>

The user agent should present a cue for the operation ‘enter’, typically inserting a new line.

<input enterkeyhint=”done”>

The user agent should present a cue for the operation ‘done’, typically meaning there is nothing more to input and the input method editor (IME) will be closed.

<input enterkeyhint=”go”>

The user agent should present a cue for the operation ‘go’, typically meaning to take the user to the target of the text they typed.

<input enterkeyhint=”next”>

The user agent should present a cue for the operation ‘next’, typically taking the user to the next field that will accept text.

<input enterkeyhint=”previous”>

The user agent should present a cue for the operation ‘previous’, typically taking the user to the previous field that will accept text.

<input enterkeyhint=”search”>

The user agent should present a cue for the operation ‘search’, typically taking the user to the results of searching for the text they have typed.

<input enterkeyhint=”send”>

The user agent should present a cue for the operation ‘send’, typically delivering the text to its target.

Photo by Melisa Hildt on Unsplash

 

HTML5 Boilerplate – das Grundgerüst für HTML5

HTML5 Boilerplate bietet ein kompaktes Grundgerüst zum Gestalten von Webseiten oder wie auch ich es nicht besser ausdrücken kann:

HTML5 Boilerplate ist ein professionelles HTML/CSS/JS-Template als Basis für eine schnelle, robuste und zukunftssichere Website.
Nach mehr als zwei Jahren Entwicklung, bekommt ihr das beste der besten Techniken zusammengefasst: Cross-Browser-Normalisierung, Performance-Optimierungen und sogar optionale Features wie Cross-Domain AJAX und Flash. Eine starter .htaccess-Konfigurationsdatei kommt mit praktischen Caching-Regeln, bereitet deine Seite für HTML5-Video vor und erlaubt dir einfache @font-face-Nutzung und gzip-Auslieferung deiner Ressourcen.
Boilerplate ist weder ein Framework, noch schreibt es dir eine Entwicklungsphilosophie vor. Es ist eine Sammlung von Tipps und Tricks, die dir helfen sollen, dein Projekt schnellstmöglich und flexibel auf die Beine zu stellen.

… ohne dabei eine Menge Zeit in die Anpassung einer Webseite an die verschiedensten Browser zu vergeuten. Weitere Informationen gibt es auf http://html5boilerplate.com/.

HTML5-Enabling-Script für IE

Nutzt man HTML5 für die Gestaltung einer Webseite, dann werden Besucher, welche den Internet Explorer mit einer Version < 9 verwenden, schnell mit falschen Seitendarstellungen überhäuft. Grund hierfür sind neue HTML5-Tags, die von den älteren Browserversionen nicht unterstützt werden. Beispiele sind: <header>, <footer>, <nav>, usw. Diese sind in HTML4 noch nicht definiert und werden somit auch nicht (oder fehlerhaft) angezeigt.

Auf remysharp.com wird eine Möglichkeit beschrieben, die mittels JavaScript auch diese Tags bei älteren Browserversionen “definiert” oder besser gesagt anlernt. Der IE scheint ja bekanntlich in allen Versionen immer noch etwas Hilfe zu brauchen 😉

Web-Development: eine Sammlung an hilfreichen Tutorials und Webseiten

Auch beim Gestalten von Webseiten gibt es immer wieder Dinge, welche schon einmal irgendwo in den tiefen des Internet beschrieben wurden. Damit das Rad also nicht neu erfunden werden muss, hier eine Liste mit hilfereichen Tutorials, wenn es um Web-Development geht. Neben allgemeinen Themen zum Webdesign soll es hierbei auch um die Verwendung der aktuellen Standards von HTML5 und CSS3 gehen.

“form” Attribut in HTML5

In HTML4 oder XHTML war es bisher so, dass Formularelemente (input/textarea) sich innerhalb eines <form>-Tags befinden mussten, damit diese beim Absenden eines Formulars auch berücksichtigt wurden. Die Daten eines Formularelements außerhalb eines <form>-Tags ließen sich so nur mit umständlichen JavaScript beim Absenden eines Formular mit übergeben.

Nicht mehr unterstütze bzw. veraltete Tags in HTML5

Im folgenden sind HTML-Tags aufgelistet, welche laut Doctype-Definition in HTML5 nicht mehr unterstützt werden. Dazu gehören auch Tags wie beispielsweise <font> oder <center>. Wer allerdings schon ausgiebig mit CSS arbeitet, der sollte diese Tags sowieso bereits nicht mehr verwendet haben. Es gibt aber auch andere Tags, welche unter umständen noch verwendet wurden. Aber keine Angst, die meisten der nicht mehr unterstützten Tags lassen sich durch CSS in Verbindung mit den gültigen Tags “nachbilden”.

CSS: Blockelement in HTML5 zentrieren

Zum Zentrieren eines Blockelementes (<div>) konnte man in HTML4 noch das Attribut align verwenden:

<div align="center">
  <div>
    ...

Damit wird der zweite div-Block bei Angabe einer festen Breite innerhalb des ersten Blocks zentriert.

Mit HTML5 ist allerdings das align-Attribut für div-Elemente nicht mehr zulässig, d.h. das Zentrieren muss in HTML5 über CSS realisiert werden.