First commit
This commit is contained in:
commit
7a4e6b17e3
4 changed files with 420 additions and 0 deletions
BIN
devtools.png
Normal file
BIN
devtools.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
140
index.html
Normal file
140
index.html
Normal file
|
@ -0,0 +1,140 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CSS Element Offsets</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="hint"></div>
|
||||
<div class="example-wrapper">
|
||||
<div class="margin offsets-vert">
|
||||
<span class="description">margin</span>
|
||||
<span data-for="margin-top">10</span>
|
||||
<div class="offsets-horiz">
|
||||
<span data-for="margin-left">10</span>
|
||||
<div class="border offsets-vert">
|
||||
<span class="description">border</span>
|
||||
<span data-for="border-top">2</span>
|
||||
<div class="offsets-horiz">
|
||||
<span data-for="border-left">2</span>
|
||||
<div class="padding offsets-vert">
|
||||
<span class="description">padding</span>
|
||||
<span data-for="padding-top">5</span>
|
||||
<div class="offsets-horiz">
|
||||
<span data-for="padding-left">5</span>
|
||||
<div class="element">
|
||||
<div class="content">
|
||||
<span data-for="width">130</span>
|
||||
x
|
||||
<span data-for="height">50</span>
|
||||
</div>
|
||||
</div>
|
||||
<span data-for="padding-right">5</span>
|
||||
</div>
|
||||
<span data-for="padding-bottom">5</span>
|
||||
</div>
|
||||
<span data-for="border-right">2</span>
|
||||
</div>
|
||||
<span data-for="border-bottom">2</span>
|
||||
</div>
|
||||
<span data-for="margin-right">10</span>
|
||||
</div>
|
||||
<span data-for="margin-bottom">10</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls-wrapper">
|
||||
<div class="switches">
|
||||
<div class="controls-column">
|
||||
<div class="control">
|
||||
<input type="checkbox" id="dark-mode">
|
||||
<label for="dark-mode">
|
||||
<span>Dark mode</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="control">
|
||||
<input type="checkbox" id="show-element">
|
||||
<label for="show-element">
|
||||
<span>Show element</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="control">
|
||||
<input type="checkbox" id="show-css">
|
||||
<label for="show-css">
|
||||
<span>Show CSS code</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<textarea class="css-code"></textarea>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<div class="controls-column">
|
||||
<div class="control">
|
||||
<label for="margin-top">margin-top</label>
|
||||
<input type="range" min="0" max="50" step="1" value="10" id="margin-top">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="margin-left">margin-left</label>
|
||||
<input type="range" min="0" max="50" step="1" value="10" id="margin-left">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="margin-right">margin-right</label>
|
||||
<input type="range" min="0" max="50" step="1" value="10" id="margin-right">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="margin-bottom">margin-bottom</label>
|
||||
<input type="range" min="0" max="50" step="1" value="10" id="margin-bottom">
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls-column">
|
||||
<div class="control">
|
||||
<label for="border-top">border-top</label>
|
||||
<input type="range" min="0" max="50" step="1" value="2" id="border-top">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="border-left">border-left</label>
|
||||
<input type="range" min="0" max="50" step="1" value="2" id="border-left">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="border-right">border-right</label>
|
||||
<input type="range" min="0" max="50" step="1" value="2" id="border-right">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="border-bottom">border-bottom</label>
|
||||
<input type="range" min="0" max="50" step="1" value="2" id="border-bottom">
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls-column">
|
||||
<div class="control">
|
||||
<label for="padding-top">padding-top</label>
|
||||
<input type="range" min="0" max="50" step="1" value="5" id="padding-top">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="padding-left">padding-left</label>
|
||||
<input type="range" min="0" max="50" step="1" value="5" id="padding-left">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="padding-right">padding-right</label>
|
||||
<input type="range" min="0" max="50" step="1" value="5" id="padding-right">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="padding-bottom">padding-bottom</label>
|
||||
<input type="range" min="0" max="50" step="1" value="5" id="padding-bottom">
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls-column">
|
||||
<div class="control">
|
||||
<label for="width">width</label>
|
||||
<input type="range" min="0" max="500" step="1" value="130" id="width">
|
||||
</div>
|
||||
<div class="control">
|
||||
<label for="height">height</label>
|
||||
<input type="range" min="0" max="500" step="1" value="50" id="height">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
72
script.js
Normal file
72
script.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
var body = document.body;
|
||||
var wrapper = document.querySelector('.example-wrapper');
|
||||
var elem = document.querySelector('.element');
|
||||
var content = document.querySelector('.content');
|
||||
var hint = document.querySelector('.hint');
|
||||
var textarea = document.querySelector('.css-code');
|
||||
|
||||
const props = ['margin','border','padding'];
|
||||
const sides = ['top','right','bottom','left'];
|
||||
|
||||
var inputs = document.querySelectorAll('input[type=range]');
|
||||
inputs.forEach(elem => elem.addEventListener('input', valueChanged));
|
||||
|
||||
document.querySelector('input#dark-mode').addEventListener(
|
||||
'input', (ev) => checkbox(ev, body, 'dark')
|
||||
);
|
||||
|
||||
document.querySelector('input#show-element').addEventListener(
|
||||
'input', (ev) => checkbox(ev, wrapper, 'hidden')
|
||||
);
|
||||
|
||||
document.querySelector('input#show-css').addEventListener(
|
||||
'input', (ev) => checkbox(
|
||||
ev, textarea, 'show',
|
||||
printCss
|
||||
)
|
||||
);
|
||||
|
||||
if (window.matchMedia &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
||||
{
|
||||
checkbox({target: {checked: true}}, body, 'dark');
|
||||
}
|
||||
|
||||
function valueChanged(event) {
|
||||
let el = event.target;
|
||||
let id = el.id;
|
||||
let span = `span[data-for=${id}]`;
|
||||
document.querySelector(span).innerText = el.value;
|
||||
|
||||
let val = el.value + 'px';
|
||||
body.style.setProperty(`--${id}`, val);
|
||||
}
|
||||
|
||||
function printCss() {
|
||||
let css = document.defaultView.getComputedStyle(body);
|
||||
let styles = [];
|
||||
for (let prop of props) {
|
||||
let txt = prop + ':';
|
||||
for (let side of sides) {
|
||||
let variable = `--${prop}-${side}`;
|
||||
console.log(variable);
|
||||
let val = css.getPropertyValue(variable);
|
||||
txt += (' ' + val.trim());
|
||||
}
|
||||
txt += ';'
|
||||
styles.push(txt);
|
||||
}
|
||||
let width = css.getPropertyValue(`--width`);
|
||||
let height = css.getPropertyValue(`--height`);
|
||||
styles.push(`width: ${width.trim()};`);
|
||||
styles.push(`height: ${height.trim()};`);
|
||||
textarea.value = styles.join('\n');
|
||||
elem.getComputedStyles();
|
||||
}
|
||||
|
||||
function checkbox(ev, el, cls, cb) {
|
||||
cb = cb || function(){};
|
||||
ev.target.checked ?
|
||||
el.classList.add(cls) & cb() :
|
||||
el.classList.remove(cls);
|
||||
}
|
208
style.css
Normal file
208
style.css
Normal file
|
@ -0,0 +1,208 @@
|
|||
body {
|
||||
--bg: #fff;
|
||||
--fg: #000;
|
||||
--margin-color: #ad8052;
|
||||
--border-color: #e3c381;
|
||||
--padding-color: #b7c47f;
|
||||
--element-color: #87b2bc;
|
||||
}
|
||||
body.dark {
|
||||
--bg: #2b2a33;
|
||||
--fg: #eee;
|
||||
--margin-color: #926538;
|
||||
--border-color: #b39355;
|
||||
--padding-color: #7b8653;
|
||||
--element-color: #709aa3;
|
||||
}
|
||||
|
||||
:root {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-family: sans-serif;
|
||||
|
||||
--accent-color: #4a93d1;
|
||||
|
||||
--width: 130px;
|
||||
--height: 50px;
|
||||
|
||||
--margin-top: 10px;
|
||||
--margin-left: 10px;
|
||||
--margin-right: 10px;
|
||||
--margin-bottom: 10px;
|
||||
|
||||
--border-top: 2px;
|
||||
--border-left: 2px;
|
||||
--border-right: 2px;
|
||||
--border-bottom: 2px;
|
||||
|
||||
--padding-top: 5px;
|
||||
--padding-left: 5px;
|
||||
--padding-right: 5px;
|
||||
--padding-bottom: 5px;
|
||||
|
||||
background-color: var(--bg);
|
||||
color: var(--fg);
|
||||
transition:
|
||||
color 0.4s ease 0s,
|
||||
background-color 0.4s ease 0s;
|
||||
}
|
||||
|
||||
.example-wrapper {
|
||||
margin: 5px;
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.margin { background: var(--margin-color); }
|
||||
.border { background: var(--border-color); }
|
||||
.padding { background: var(--padding-color); }
|
||||
.element { background: var(--element-color); }
|
||||
|
||||
.description {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 5px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.offsets-vert {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.offsets-vert > span {
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
.offsets-horiz {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
.offsets-horiz > span {
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
.example.wrapper:not(.hidden) .margin,
|
||||
.example-wrapper:not(.hidden) .padding { border: 1px dashed var(--fg); }
|
||||
.example-wrapper:not(.hidden) .border,
|
||||
.example-wrapper:not(.hidden) .element { border: 1px solid var(--fg); }
|
||||
|
||||
.example-wrapper.hidden .offsets-vert > span,
|
||||
.example-wrapper.hidden .offsets-horiz > span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.example-wrapper.hidden .padding {
|
||||
background: var(--margin-color);
|
||||
}
|
||||
|
||||
.example-wrapper.hidden .element {
|
||||
margin-top: var(--margin-top);
|
||||
margin-left: var(--margin-left);
|
||||
margin-right: var(--margin-right);
|
||||
margin-bottom: var(--margin-bottom);
|
||||
|
||||
border-color: var(--border-color);
|
||||
border-style: solid;
|
||||
border-top-width: var(--border-top);
|
||||
border-left-width: var(--border-left);
|
||||
border-right-width: var(--border-right);
|
||||
border-bottom-width: var(--border-bottom);
|
||||
|
||||
padding-top: var(--padding-top);
|
||||
padding-left: var(--padding-left);
|
||||
padding-right: var(--padding-right);
|
||||
padding-bottom: var(--padding-bottom);
|
||||
}
|
||||
|
||||
.element {
|
||||
width: var(--width);
|
||||
height: var(--height);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.controls-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.controls-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.control {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr;
|
||||
}
|
||||
|
||||
.switches {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
input[type=range] {
|
||||
width: 10rem;
|
||||
}
|
||||
|
||||
input[type=checkbox] {
|
||||
display: none;
|
||||
}
|
||||
input[type=checkbox] ~ label {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
cursor: pointer;
|
||||
}
|
||||
input[type=checkbox] ~ label > span {
|
||||
margin-left: 5px;
|
||||
}
|
||||
input[type=checkbox] ~ label::before {
|
||||
content: '';
|
||||
width: 2rem;
|
||||
height: 1rem;
|
||||
border-radius: 5px;
|
||||
background: -moz-linear-gradient(90deg, #777 50%, #bbb 51%);
|
||||
background: -webkit-linear-gradient(90deg, #777 50%, #bbb 51%);
|
||||
background: linear-gradient(90deg, #777 50%, #bbb 51%);
|
||||
}
|
||||
input[type=checkbox]:checked ~ label::before {
|
||||
content: '';
|
||||
width: 2rem;
|
||||
height: 1rem;
|
||||
border-radius: 5px;
|
||||
background: -moz-linear-gradient(270deg, var(--accent-color) 50%, #bbb 51%);
|
||||
background: -webkit-linear-gradient(270deg, var(--accent-color) 50%, #bbb 51%);
|
||||
background: linear-gradient(270deg, var(--accent-color) 50%, #bbb 51%);
|
||||
}
|
||||
|
||||
textarea {
|
||||
display: none;
|
||||
}
|
||||
textarea.show {
|
||||
display: block;
|
||||
}
|
Loading…
Add table
Reference in a new issue