Components
In m-components.css, m.css provides a set of basic components for further improving the layout and display of authored content.
Colors
Similarly to Bootstrap, m.css has a set of predefined colors that affect how a certain component looks. This works on majority of components shown on this page. The colors are:
.m-default
is a default style that doesn’t grab attention.m-primary
is meant to be used to highlight the primary element on a page.m-success
is good to highlight happy things.m-warning
catches attention, but doesn’t hurt.m-danger
brings really bad news.m-info
is for side notes.m-dim
is shy and doesn’t want you to be bothered by the information it brings
Blocks
Blocks, defined by .m-block
, wrap the content in a light frame and add a
bolder colored bar on the left. Use in combination with one of the color styles
above. Block caption should go into <h3>
(or <h4>
,
<h5>
, <h6>
) and is colored in respect to the color style as
well. Text and links inside the text always have the default color, except for
.m-block.m-dim
. It’s also possible to have a block without the border,
just add .m-flat
class to it.
It’s recommended to use the <aside>
element to highlight the semantics,
but the CSS class can be used on any block element.
Badges
Badges are blocks together with an avatar, containing for example info about
the author of given article. Simply add .m-badge
to your colored block
element and put an <img>
element with the avatar as the first child.
Only <h3>
is supported for a badge. For standalone rounded avatars, see
Images below.
Notes, frame
Unlike blocks, notes are meant to wrap smaller bits of information. Use the
.m-note
CSS class together with desired color class. A note is also
slightly rounded and has everything colored, the background, the caption, text
and also links. The <h3>
(<h4>
, <h5>
, <h6>
)
caption tag is optional.
Besides notes, there is a frame element defined by .m-frame
, which just
wraps your content in a slightly rounded border. No color classes apply to a
frame.
Like with blocks, tt’s recommended to use the <aside>
element for
semantic purposes, but the CSS classes can be used on any block element.
Text
Use .m-text
CSS class together with desired color class to color a
paragraph or inline text.
Apply .m-tiny
, .m-small
or .m-big
CSS class together with
.m-text
to make the text appear smaller or larger.
Labels
Use .m-label
together with a color class to style a label. Combine with
.m-flat
to create a less noticeable label. The label size adapts to size
of surrounding text.
Tables
Use .m-table
to apply styling to a table. The table is centered by
default; rows are separated by lines, with <thead>
and <tfoot>
being separated by a thicker line. The <th>
element is rendered in
bold, all <th>
and <td>
are aligned to left while table
<caption>
is centered. Example table:
<table class="m-table"> <caption>Table caption</caption> <thead> <tr> <th>#</th> <th>Heading</th> <th>Second<br/>heading</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Cell</td> <td>Second cell</td> </tr> </tbody> <tbody> <tr> <th scope="row">2</th> <td>2nd row cell</td> <td>2nd row 2nd cell</td> </tr> </tbody> <tfoot> <tr> <th>Σ</th> <td>Footer</td> <td>Second<br/>footer</td> </tr> </tfoot> </table>
# | Heading | Second heading |
---|---|---|
1 | Cell | Second cell |
2 | 2nd row cell | 2nd row 2nd cell |
Σ | Footer | Second footer |
Use the .m-fullwidth
CSS class on the <table>
element to make
the table span the full width instead of being centered. Rows are highlighted
on hover, if you want to disable that, put .m-flat
on the
<table>
element. You can also put .m-thin
onto <th>
elements to remove the bold styling. Similarly to other components, you can
color particular <tr>
or <td>
elements using the color classes
from above:
Default row | Lorem | ipsum | dolor | sit | amet | Link |
Primary row | Lorem | ipsum | dolor | sit | amet | Link |
Success row | Lorem | ipsum | dolor | sit | amet | Link |
Warning row | Lorem | ipsum | dolor | sit | amet | Link |
Danger row | Lorem | ipsum | dolor | sit | amet | Link |
Info row | Lorem | ipsum | dolor | sit | amet | Link |
Dim row | Lorem | ipsum | dolor | sit | amet | Link |
Mark the table with .m-big
to inflate it with more spacing, for example
when designing a high-level product category overview.
Similarly to lists, if using
<p>
elements inside <td>
, they are neither indented nor
justified.
Images
Putting .m-image
class onto an <img>
, <svg>
or
<video>
tag makes the image or video centered, slightly rounded and
sets its max width to 100%. Adding .m-fullwidth
on the image element
works as expected. For accessibility reasons it’s a good practice to include
the alt
attribute.
To make the image clickable, wrap the <a>
tag in an additional
<div>
and put the .m-image
class on the <div>
element
instead of on the image. This will ensure that only the image is clickable and
not the surrounding area:
For avatars, similarly to the Badges above, applying a .m-badge
class
together with .m-image
will make the image round. Works for both plain
<img>
and clickable images wrapped in <div class="m-image">
.
The .m-badge
isn’t recognized for <svg>
or <video>
however.
Figures
Use the HTML5 <figure>
tag together with .m-figure
to style it.
As with plain image, it’s by default centered, slightly rounded and has a
border around the caption and description. The caption is expected to be in the
<figcaption>
element. Inside it, there can optionally be a longer
description wrapped in a div.m-figure-description
element. The
.m-fullwidth
class works here too and you can also wrap the
<img>
/ <svg>
/ <video>
element in an <a>
tag
to make it clickable.
Figure always expects at least the caption to be present. If you want just an
image, use the plain image tag. If you have a lot of figures on the page and
the border is distracting, apply the .m-flat
class to hide it.
Optionally you can color the figure border and caption (with the description
staying unaffected) by adding one of the CSS color classes to the
<figure>
element.
Image grid
Inspired by image grids on Medium,
its purpose is to present photos in a beautiful way. Wrap one or more
<figure>
elements in a <div class="m-imagegrid">
element and
delimit each row with a wrapper <div>
. Each <figure>
element
needs to contain an <img>
and a <figcaption>
with image caption
that appears on hover; these two elements can be optionally wrapped in an
<a>
to make the image clickable. If you don’t want a caption, use an
empty <div>
instead of <figcaption>
. If you want the grid to
inflate to full container width,
add a .m-container-inflate
CSS class to it.
Example usage (stupidly showing the two images all over again — sorry):
<div class="m-imagegrid m-container-inflate"> <div> <figure style="width: 69.127%"> <a href="ship.jpg"> <img src="ship.jpg" /> <figcaption>F9.0, 1/250 s, ISO 100</figcaption> </a> </figure> <figure style="width: 30.873%"> <a href="flowers.jpg"> <img src="flowers.jpg" /> <figcaption>F2.8, 1/1600 s, ISO 100</figcaption> </a> </figure> </div> <div> <figure style="width: 30.873%"> <a href="flowers.jpg"> <img src="flowers.jpg" /> <figcaption>F2.8, 1/1600 s, ISO 100</figcaption> </a> </figure> <figure style="width: 69.127%"> <a href="ship.jpg"> <img src="ship.jpg" /> <figcaption>F9.0, 1/250 s, ISO 100</figcaption> </a> </figure> </div> </div>
The core idea behind the image grid is scaling particular images to occupy the same height on given row. First, a sum of image aspect ratios is calculated for the whole row:
Then, percentage width of each image is calculated as:
Code
m.css recognizes code highlighting compatible with Pygments and provides additional styling for it. There’s a set of builtin pygments-*.css styles that match the m.css themes.
For example, code highlighted using:
echo -e "int main() {\n return 0;\n}" | pygmentize -f html -l c++ -O nowrap
Will spit out a bunch of <span>
elements like below. To create a code
block, wrap the output in <pre class="m-code">
(note that whitespace
matters inside this tag). The block doesn’t wrap lines on narrow screens to not
hurt readability, a horizontal scrollbar is shown instead if the content is
too wide.
<pre class="m-code"><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span></pre>
int main() { return 0; }
Pygments allow to highlight arbitrary lines, which affect the rendering in this way:
int main() { std::cout << "Hello world!" << std::endl; return 0; }
Sometimes you want to focus on code that has been changed / added and mute the
rest. Add an additional .m-inverted
CSS class to the
<pre class="m-code">
to achieve this effect:
#include <iostream> int main() { std::cout << "Hello world!" << std::endl; return 0; }
To have code highlighting inline, wrap the output in <code class="m-code">
instead of <pre>
:
<p>The <code class="m-code"><span class="n">main</span><span class="p">()</span></code> function doesn't need to have a <code class="m-code"><span class="k">return</span></code> statement.</p>
The main()
function doesn't need to have a return
statement.
Color swatches in code snippets
For code dealing with colors it might be useful to show the actual color that’s
being represented by a hexadecimal literal, for example. In the below snippet,
<span class="m-code-color" style="background-color: #3bd267;"></span>
is added next to the literal, showing a colored square:
<pre class="m-code"><span class="p">.</span><span class="nc">success</span> <span class="p">{</span> <span class="k">color</span><span class="p">:</span> <span class="mh">#3bd267<span class="m-code-color" style="background-color: #3bd267;"></span></span><span class="p">;</span> <span class="p">}</span></pre>
.success { color: #3bd267; }
Colored terminal output
Besides code, it’s also possible to “highlight” ANSI-colored terminal output. For that, m.css provides a custom Pygments lexer that’s together with pygments-console.css able to detect and highlight the basic 4-bit color codes (8 foreground colors in either normal or bright version) and a tiny subset of the 24-bit color scheme as well. Download the ansilexer.py file or use it directly from your Git clone of m.css. Example usage:
ls -C --color=always | pygmentize -l plugins/ansilexer.py:AnsiLexer -x -f html -O nowrap
Wrap the HTML output in either <pre class="m-console">
for a block
listing or <code class="m-console">
for inline listing. The output
might then look similarly to this:
<pre class="m-console">CONTRIBUTING.rst CREDITS.rst <span class="g g-AnsiBrightBlue">doc</span> <span class="g g-AnsiBrightBlue">plugins</span> README.rst COPYING <span class="g g-AnsiBrightBlue">css</span> <span class="g g-AnsiBrightBlue">documentation</span> <span class="g g-AnsiBrightBlue">pelican-theme</span> <span class="g g-AnsiBrightBlue">site</span></pre>
CONTRIBUTING.rst CREDITS.rst doc plugins README.rst COPYING css documentation pelican-theme site
It’s sometimes desirable to have console output wrapped to the available
container width (like terminals do). Add .m-console-wrap
to the
<pre>
to achieve that effect.
Code figure
It often happens that you want to present code with corresponding result
together. The code figure looks similar to image figures and
consists of a <figure>
(or <div>
) element with the
.m-code-figure
class containing a <pre>
block and whatever else
you want to put in as the result. The <pre>
element has to be the very
first child of the <figure>
for the markup to work correctly. Similarly
to image figure, you can apply the .m-flat
CSS class to remove the
border, the <figcaption>
element is styled as well.
Example (note that this page uses code figure for all code examples, so it’s a bit of a figure inception shown here):
<figure class="m-code-figure"> <pre>Some code snippet</pre> And a resulting output. </figure>
Some code snippetAnd a resulting output.
It’s also possible to have matching border for a console output. Just use
.m-console-figure
instead of .m-code-figure
on the outer element.
For reduced clutter when combining a code figure with console output (and vice
versa), mark the second <pre>
with .m-nopad
:
<figure class="m-code-figure"> <pre class="m-code">Some code snippet</pre> <pre class="m-console m-nopad">And a resulting output.</pre> </figure>
Some code snippet
And a resulting output.
Math
The latex2svg.py
utility from tuxu/latex2svg can be used to generate
SVG representation of your LaTeX math formulas. Assuming you have some LaTeX
distribution and dvisvgm installed, the usage is:
echo "\$\$ a^2 = b^2 + c^2 \$\$" | python plugins/latex2svg.py > formula.svg
The formula.svg
file will then contain the rendered formula, which with
some minor patching (removing the XML preamble etc.) can be pasted directly
into your HTML code. The <svg>
element containing math can be wrapped
in <div class="m-math">
to make it centered. Similarly to code
blocks, the math block shows a horizontal scrollbar if the content is too wide
on narrow screens. CSS color classes can be applied to the
<div>
. It’s a good practice to include the <title>
element for accessibility reasons.
<div class="m-math m-success"> <svg> <title>a^2 = b^2 + c^2</title> <g>...</g> </svg> </div>
For inline math, add the .m-math
class to the <svg>
tag
directly. Note that you’ll probably need to manually specify
vertical-align
style to make the formula align well with surrounding
text. You can use CSS color classes here as well. When using the latex2svg.py
utility, wrap the formula in $
instead of $$
to produce inline math;
the depth
value returned on stderr can be taken as a base for the
vertical-align
property.
<p>There is <a href="https://tauday.com/">a movement</a> for replacing circle constant <svg class="m-math" style="vertical-align: 0.0pt">...</svg> with the <svg class="m-math m-warning" style="vertical-align: 0.0pt">...</svg> character.
There is a movement for replacing circle constant with the character.
The CSS color classes work also on <g>
and <rect>
elements
inside <svg>
for highlighting parts of formulas.
Math figure
Similarly to code figure, math can be also put in a <figure>
with
assigned caption and description. It behaves the same as image figures, the
figure width being defined by the math equation size. Create a
<figure class="m-figure">
element and put <svg class="m-math">
as a first child. The remaining content of the figure can be
<figcaption>
with optional div.m-figure-description
same as with
image figures. Add the .m-flat
class to the
<figure>
to remove the outer border and equation background,
CSS color classes on the <figure>
affect the figure, on the
<svg>
affect the equation.
<figure class="m-figure"> <svg class="m-math"> <title>a^2 = b^2 + c^2</title> <g>...</g> </svg> <figcaption> Theorem <div class="m-figure-description">A Pythagorean one.</div> </figcaption> </figure>
Plots
Wrap a <svg>
element in a <div class="m-plot">
to make it
centered and occupying full width. Mark plot axes background with
.m-background
, bars can be styled using .m-bar
and a
corresponding CSS color class. Mark ticks and various other lines
with .m-line
, error bars with .m-error
. Use
<text class="m-label">
for tick and axes labels and
<text class="m-title">
for graph title.
<div class="m-plot"><svg> <path d="M 68.22875 70.705312 ..." class="m-background"/> <path d="M 68.22875 29.116811 ..." class="m-bar m-warning"/> <path d="M 68.22875 51.121309 ..." class="m-bar m-primary"/> ... <defs><path d="..." id="mba4ce04b6c" class="m-line"/></defs> <use x="68.22875" xlink:href="#mba4ce04b6c" y="37.91861"/> <text class="m-label" style="text-anchor:end;" ...>Cheetah</text> ... <path d="M 428.616723 37.91861 ..." class="m-error"/> ... <text class="m-title" style="text-anchor:middle;" ...>Fastest animals</text> </svg></div>
Graphs
Wrap a <svg>
element in a <div class="m-graph">
to make it
centered and occupying full width at most. Wrap edge <path>
,
<polygon>
and <text>
elements in <g class="m-edge">
to
style them as edges, wrap node <polygon>
, <ellipse>
and
<text>
elements in <g class="m-node">
to style them as nodes.
You can use CSS color classes on either the wrapper <div>
or on the <g>
to color the whole graph or its parts. Use .m-flat
on a .m-node
to make it just an outline instead of filled.
<div class="m-graph m-info"><svg> <g class="m-node"> <ellipse cx="27.5772" cy="-27.5772" rx="27.6545" ry="27.6545"/> <text text-anchor="middle" x="27.5772" y="-23.7772">yes</text> </g> <g class="m-node m-flat"> <ellipse cx="134.9031" cy="-27.5772" rx="25" ry="25"/> <text text-anchor="middle" x="134.9031" y="-23.7772">no</text> </g> <g class="m-edge"> <path d="M55.2163,-27.5772C68.8104,-27.5772 85.3444,-27.5772 99.8205,-27.5772"/> <polygon points="99.9261,-31.0773 109.9261,-27.5772 99.9261,-24.0773 99.9261,-31.0773"/> <text text-anchor="middle" x="82.6543" y="-32.7772">no</text> </g> <g class="m-edge m-dim"> <path d="M125.3459,-50.4471C124.3033,-61.0564 127.489,-70.3259 134.9031,-70.3259 139.7685,-70.3259 142.813,-66.3338 144.0365,-60.5909"/> <polygon points="147.5398,-60.5845 144.4603,-50.4471 140.5459,-60.2923 147.5398,-60.5845"/> <text text-anchor="middle" x="134.9031" y="-75.5259">no</text> </g> </svg></div>
Graph figure
Similarly to math figure, graphs also can be <figure>
s. The
behavior is almost identical, create a <figure class="m-figure m-graph">
element and put the <svg>
as a first child and a <figcaption>
right after.
<figure class="m-figure"> <svg class="m-graph m-warning"> ... </svg> <figcaption> Impenetrable logic <div class="m-figure-description">No.</div> </figcaption> </figure>
Padding and floating
Similarly to typography elements;
blocks, notes, frames, tables, images, figures, image grids, code and math
blocks and code figures have 1rem
padding on the bottom, except when
they are the last element, to avoid excessive spacing. The list special casing
and ability to disable the padding using .m-nopadb
applies here as well.
Components that appear directly in a column that’s m-container-inflatable
or directly inside any nested <section>
are outdented to preserve a
straight line of text alignment on the sides. You can spot that on this page
— look how notes and figures have their background outside. This also makes
narrow layouts better readable, as the component visuals don’t cut into
precious screen width.
All components support the floating classes from the grid system, however having floating elements inside the components is not supported. Floating elements also preserve the inflatable behavior described above.
Responsive utilities
If you have some element that will certainly overflow on smaller screen sizes
(such as wide table or image that can’t be scaled), wrap it in a
.m-scroll
. This will put a horizontal scrollbar under in case the
element overflows.
There’s also .m-fullwidth
that will make your element always occupy 100%
of the parent element width. Useful for tables or images.