Menu

Overview

An introduction to Semantic style coding

Interfacing Carefully

UI definitions in Semantic are given the class name ui. This is to help tell the difference between ui elements and parts of the definition of an element. This means any element with the class name UI has a corresponding UI definition.

For example a menu may have menu items inside of it. These items are contained as part of the menu definition but do not receive the class name ui because they are part of a UI menu collection.

A Simple MenuHTML
<div class="ui menu">
  <a class="item">Home</a>
  <a class="item">Inbox</a>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Changing an Element

Class names in Semantic always use single english words. If a class name is an adjective it is either a type of element or variation of an element. CSS definitions always define adjectives in the context of a noun. In this way class names cannot pollute the namespace.

A Compact Menu VariationHTML
<div class="ui compact menu">
  <a class="item">Home</a>
  <a class="item">Inbox</a>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Combining elements

All UI definitions in semantic are stand-alone, and do not require other components to function. However, components can choose to have optional couplings with other components.

For example you might want to include a badge inside a menu. A label inside of a menu will automatically function as a badge.

Using a UI Label inside a UI MenuHTML
<div class="ui compact menu">
  <a class="item">Home</a>
  <a class="item">
    Inbox
    <div class="ui label">22</div>
  </a>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Semantic APIs

Modules define a public API using verbs and simple phrases. When methods are invoked internally those phrases are matched to internal methods automatically.

HTML
<div class="ui pointing secondary demo menu">
  <a class="active red item" data-tab="first">First</a>
  <a class="blue item" data-tab="second">Second</a>
  <a class="green item" data-tab="third">Third</a>
</div>
<div class="ui active tab segment" data-tab="first">First</div>
<div class="ui tab segment" data-tab="second">Second</div>
<div class="ui tab segment" data-tab="third">Third</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
First
Second
Third

Opening a new tab with a behavior

Modules have simple behaviors for triggering common actions

Run Code
$('.demo.menu .item')
  .tab('change tab', 'second')
;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Opening a new tab with multiple behaviors

Any internal behavior is accessible as well

Run Code
$('.demo.menu .item')
  .tab('deactivate all')
  .tab('activate tab', 'third')
  .tab('activate navigation', 'third')
;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Turning on HTML5 State

Modules can be re-initialized at any time with different settings

Run Code
$('.demo.menu .item')
  .tab({
    history : true,
    path    : '/introduction/getting-started.html'
  })
;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Next: UI Types