1
0
mirror of https://github.com/NigelOToole/pixel-borders.git synced 2025-09-01 01:51:55 +02:00
This commit is contained in:
Nigel O'Toole
2019-04-05 11:04:02 +01:00
commit 5ca68d4f18
15 changed files with 9530 additions and 0 deletions

48
src/index.html Normal file
View File

@@ -0,0 +1,48 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pixel borders - Creates pixelated borders on html elements</title>
<link rel="stylesheet" href="styles/site.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Cutive+Mono|Lato:300,400">
<link rel="stylesheet" href="styles/pixel-borders.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Press+Start+2P">
</head>
<body>
<div class="fullwidth fullwidth--lg">
<div class="container">
<h2>Basic examples</h2>
<div class="pixel-borders pixel-borders--1">Pixel border 1</div>
<div class="pixel-borders pixel-borders--1 pixel-borders--1-inset">Pixel inset 1</div>
<br>
<div class="pixel-borders pixel-borders--2">Pixel border 2</div>
<div class="pixel-borders pixel-borders--2-inset">Pixel inset 2</div>
<br><br>
<h2>Colour coded examples</h2>
<button class="pixel-borders pixel-box--light">Pixel light</button>
<button class="pixel-borders pixel-box--primary">Pixel primary</button>
<button class="pixel-borders pixel-box--success">Pixel success</button>
<button class="pixel-borders pixel-box--warning">Pixel warning</button>
<button class="pixel-borders pixel-box--error">Pixel error</button>
<br><br>
<h2>Customisation examples</h2>
<button class="pixel-borders pixel-box--light-custom">Custom inset</button>
<button class="pixel-borders pixel-box--primary-custom">No inset</button>
<button class="pixel-borders pixel-box--success-custom">Highlight</button>
<button class="pixel-borders pixel-box--warning-custom">Inset & Highlight</button>
<button class="pixel-borders pixel-box--error-custom">Custom border</button>
</div>
</div>
</body>
</html>

349
src/styles/_normalize.scss Normal file
View File

@@ -0,0 +1,349 @@
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}

View File

@@ -0,0 +1,233 @@
// Generate SVG image for pixelated corners
@function pixel-borders-image($corner-size, $color) {
$svg: '';
$svg-path: '';
$svg-size: $corner-size * 6;
$color: str-replace('' + $color, '#', '%23');
@if $corner-size == 1 {
$svg-path: 'M0 2h2v2H0zM2 0h2v2H2zM4 2h2v2H4zM2 4h2v2H2z';
} @else {
$svg-path: 'M2 2h2v2H2zM4 0h2v2H4zM10 4h2v2h-2zM0 4h2v2H0zM6 0h2v2H6zM8 2h2v2H8zM8 8h2v2H8zM6 10h2v2H6zM0 6h2v2H0zM10 6h2v2h-2zM4 10h2v2H4zM2 8h2v2H2z';
}
$svg: 'data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'#{$svg-size}\' height=\'#{$svg-size}\'><path d=\'#{$svg-path}\' fill=\'#{$color}\' /></svg>';
@return $svg;
}
// String replace function - replace `$search` with `$replace` in `$string`
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
// Pixel border
@mixin pixel-borders($corner-size: 1, $border-size: 4px, $border-color: #000, $border-inset-color: false) {
@supports (border-image-source: none) {
border-radius: ($border-size * ($corner-size + 2)) + ($corner-size * 2);
}
border-style: solid;
border-width: $border-size;
border-color: $border-color;
border-image-slice: $corner-size * 2;
border-image-width: $corner-size;
border-image-outset: 0;
border-image-source: url(pixel-borders-image($corner-size, $border-color));
@if $border-inset-color {
@include pixel-inset-border($border-size, $border-inset-color);
}
}
// Pixel inset border
@mixin pixel-inset-border($border-inset-size: 4px, $border-inset-color: #ddd, $border-inset-sides: 'bottom-right', $border-inset-color-br: false, $border-inset-color-tl: false) {
$box-shadow: '';
@if not($border-inset-color-br) {
$border-inset-color-br: $border-inset-color;
}
@if not($border-inset-color-tl) {
$border-inset-color-tl: $border-inset-color;
}
position: relative;
&::after {
content: '';
position: absolute;
z-index: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
@if $border-inset-sides == 'bottom-right' or $border-inset-sides == false {
$box-shadow: inset -#{$border-inset-size} -#{$border-inset-size} $border-inset-color-br;
}
@if $border-inset-sides == 'top-left' {
$box-shadow: inset $border-inset-size $border-inset-size $border-inset-color-tl;
}
@if $border-inset-sides == 'all' {
$box-shadow: inset -#{$border-inset-size} -#{$border-inset-size} $border-inset-color-br, inset $border-inset-size $border-inset-size $border-inset-color-tl;
}
box-shadow: $box-shadow;
}
}
// ($corner-size: 1, $border-size: 4px, $border-color: #000, $border-inset-color: false)
// ($border-inset-size: 4px, $border-inset-color: #ddd, $border-inset-sides: 'bottom-right', $border-inset-color-br: false, $border-inset-color-tl: false)
// Pixel box - Colours for border and inset are calulated using $background-color unless $border-color is passed
@mixin pixel-box($corner-size, $border-size, $background-color, $border-color: false, $border-inset: true, $border-inset-size: false, $border-inset-color: false, $border-inset-sides: false, $border-inset-color-br: false, $border-inset-color-tl: false) {
$background-color-hover: darken($background-color, 5);
// $border-inset-color: '';
@if not($border-color) {
$border-color: darken($background-color, 20);
}
@include pixel-borders($corner-size: $corner-size, $border-size: $border-size, $border-color: $border-color);
@if $border-inset-sides == 'all' and not($border-inset-color) {
$border-inset-color-br: darken($background-color, 10);
$border-inset-color-tl: lighten($background-color, 15);
}
@if not($border-inset-color) {
$border-inset-color: darken($background-color, 10);
}
@if $border-inset-sides == 'top-left' {
$border-inset-color: lighten($background-color, 15);
}
@if $border-inset {
@include pixel-inset-border($border-inset-size: $border-size, $border-inset-color: $border-inset-color, $border-inset-sides: $border-inset-sides, $border-inset-color-br: $border-inset-color-br, $border-inset-color-tl: $border-inset-color-tl);
}
background-color: $background-color;
&:hover, &:focus {
background-color: $background-color-hover;
}
}
// Demo styles
.pixel-borders {
position: relative;
display: inline-block;
margin: 0 15px 15px 0;
padding: 15px 20px;
background-color: #fff;
font-family: "Press Start 2P", Arial Black, Arial Bold, Arial, sans-serif;
}
// Simple examples with default styling
.pixel-borders--1 {
@include pixel-borders();
}
.pixel-borders--1-inset {
@include pixel-borders($border-inset-color: #ddd);
}
.pixel-borders--2 {
@include pixel-borders($corner-size: 2);
}
.pixel-borders--2-inset {
@include pixel-borders($corner-size: 2);
&::after {
@include pixel-borders($corner-size: 1, $border-color: #ddd);
content: '';
position: absolute;
z-index: 0;
bottom: 0;
right: 0;
border-image-width: 0 1 1 0;
width: calc(100% - 4px);
height: calc(100% - 4px);
}
}
// Examples using the pixel box mixin to colour code the elements
.pixel-box--light {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #fff);
}
.pixel-box--primary {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #209cee);
}
.pixel-box--success {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #92cc41);
}
.pixel-box--warning {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #f7d51d);
}
.pixel-box--error {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #e76e55);
}
// Custom examples to show flexibility of the mixins
.pixel-box--light-custom {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #fff, $border-inset-color: #999, $border-inset-sides: 'all');
}
.pixel-box--primary-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #209cee, $border-inset: false);
}
.pixel-box--success-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #92cc41, $border-inset-sides: 'top-left');
}
.pixel-box--warning-custom {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #f7d51d, $border-inset-sides: 'all');
}
.pixel-box--error-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #e76e55, $border-color: #000);
}

203
src/styles/site.scss Normal file
View File

@@ -0,0 +1,203 @@
// ----- Demo site styles -----
@import "normalize";
// ----- Base styles -----
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
font-family: "Lato", -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
font-size: 1rem;
font-weight: 300;
line-height: 1.5;
color: #333;
background-color: #fff;
}
a {
color: #1976D2;
text-decoration: none;
transition: color 0.3s;
&:hover, &:focus {
color: #2196F3;
}
}
// Type
h1, h2, h3, h4, h5, h6 {
font-weight: 300;
small {
font-size: 60%;
}
}
h1, h2 {
margin: 0 0 20px 0;
}
h3, h4, h5, h6 {
margin: 0 0 15px 0;
}
h1 { font-size: 38px; }
h2 { font-size: 34px; }
h3 { font-size: 26px; }
h4 { font-size: 20px; }
h5 { font-size: 16px; }
h6 { font-size: 14px; }
p {
margin: 0 0 15px 0;
}
strong {
font-weight: 400;
}
// ----- Layout -----
.container {
width: 100%;
max-width: 1140px;
margin-right: auto;
margin-left: auto;
padding-left: 15px;
padding-right: 15px;
}
// ----- Header and footer -----
.header {
position: fixed;
top: 0;
z-index: 100;
width: 100%;
padding: 15px 0;
color: #fff;
background-color: #1976D2;
box-shadow: 0 0 6px 6px rgba(0,0,0,0.1);
}
.logo-text {
margin: 0;
@media (max-width: 767px) {
font-size: 25px;
}
@media (min-width: 768px) {
display: inline-block;
}
}
.header--links {
.btn {
margin: 0;
margin-top: 7px;
&:last-child {
margin-left: 7px;
}
}
@media (min-width: 768px) {
float: right;
}
}
.footer {
padding-top: 15px;
padding-bottom: 15px;
font-size: 12px;
text-align: center;
}
// ----- Demo -----
.demo {
margin-top: 40px;
margin-bottom: 40px;
}
.demo--intro {
margin-top: 20px;
border-bottom: 1px solid #ddd;
p:last-child {
padding-bottom: 20px;
}
}
.btn {
display: inline-block;
text-align: center;
vertical-align: middle;
cursor: pointer;
border: 1px solid #bbb;
padding: 4px 12px 6px 12px;
font-size: 18px;
background-color: #fff;
border-radius: 4px;
transition: background-color .3s, color .3s;
&:hover, &:active {
background-color: #f3f3f3;
}
}
.btn-white {
color: #fff;
border-color: #fff;
background-color: transparent;
}
.install .btn {
margin-right: 15px;
margin-bottom: 15px;
}
pre {
display: block;
padding: 10px 15px;
margin: 0 0 20px 0;
overflow: auto;
font-family: 'Cutive Mono', monospace;
font-size: 14px;
word-break: break-all;
word-wrap: break-word;
background-color: #f3f3f3;
border: 1px solid #bbb;
border-radius: 4px;
}
// ----- Breakpoint examples -----
// Breakpoints up
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { }
// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { }