Skip to content

Commit bc074f4

Browse files
committed
some box alignment examples
1 parent a309a44 commit bc074f4

File tree

4 files changed

+590
-0
lines changed

4 files changed

+590
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Flexbox Alignment: alignment with auto margins</title>
7+
8+
<style>
9+
body {
10+
font: 1.2em Helvetica, Arial, sans-serif;
11+
margin: 20px;
12+
padding: 0;
13+
}
14+
15+
textarea {
16+
font-family: monospace;
17+
display: block;
18+
margin-bottom: 10px;
19+
background-color: #F4F7F8;
20+
border: none;
21+
border-left: 6px solid #558ABB;
22+
color: #4D4E53;
23+
width: 90%;
24+
max-width: 700px;
25+
padding: 10px 10px 0px;
26+
font-size: 90%;
27+
}
28+
29+
textarea:nth-of-type(1) {
30+
height: 110px
31+
}
32+
33+
textarea:nth-of-type(2) {
34+
height: 140px
35+
}
36+
37+
.playable-buttons {
38+
text-align: right;
39+
width: 90%;
40+
max-width: 700px;
41+
padding: 5px 10px 5px 26px;
42+
font-size: 100%;
43+
}
44+
45+
section {
46+
width: 90%;
47+
max-width: 700px;
48+
border: 1px solid #4D4E53;
49+
border-radius: 2px;
50+
padding: 10px 14px 10px 10px;
51+
margin-bottom: 10px;
52+
}
53+
54+
section input {
55+
display: block;
56+
margin: 5px;
57+
}
58+
59+
.box {
60+
width: 500px;
61+
border: 2px dotted rgb(96, 139, 168);
62+
}
63+
64+
.box>* {
65+
padding: 20px;
66+
border: 2px solid rgb(96, 139, 168);
67+
border-radius: 5px;
68+
background-color: rgba(96, 139, 168, .2);
69+
}
70+
</style>
71+
<style class="editable">
72+
.box {
73+
display: flex;
74+
}
75+
.push {
76+
margin-left: auto;
77+
}
78+
</style>
79+
</head>
80+
81+
<body>
82+
<section>
83+
<div class="box">
84+
<div>One</div>
85+
<div>Two</div>
86+
<div>Three</div>
87+
<div class="push">Four</div>
88+
<div>Five</div>
89+
</div>
90+
91+
</section>
92+
<textarea class="playable-css">
93+
.box {
94+
display: flex;
95+
}
96+
.push {
97+
margin-left: auto;
98+
}
99+
</textarea>
100+
<textarea id="code" class="playable-html">
101+
<div class="box">
102+
<div>One</div>
103+
<div>Two</div>
104+
<div>Three</div>
105+
<div class="push">Four</div>
106+
<div>Five</div>
107+
</div>
108+
</textarea>
109+
<div class="playable-buttons">
110+
<input id="reset" type="button" value="Reset">
111+
</div>
112+
</body>
113+
<script>
114+
var section = document.querySelector('section');
115+
var editable = document.querySelector('.editable');
116+
var textareaHTML = document.querySelector('.playable-html');
117+
var textareaCSS = document.querySelector('.playable-css');
118+
var reset = document.getElementById('reset');
119+
var htmlCode = textareaHTML.value;
120+
var cssCode = textareaCSS.value;
121+
122+
function fillCode() {
123+
editable.innerHTML = textareaCSS.value;
124+
section.innerHTML = textareaHTML.value;
125+
}
126+
127+
reset.addEventListener('click', function () {
128+
textareaHTML.value = htmlCode;
129+
textareaCSS.value = cssCode;
130+
fillCode();
131+
});
132+
133+
textareaHTML.addEventListener('input', fillCode);
134+
textareaCSS.addEventListener('input', fillCode);
135+
window.addEventListener('load', fillCode);
136+
</script>
137+
138+
</html>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Flexbox Alignment: simple example</title>
7+
8+
<style>
9+
body {
10+
font: 1.2em Helvetica, Arial, sans-serif;
11+
margin: 20px;
12+
padding: 0;
13+
}
14+
15+
textarea {
16+
font-family: monospace;
17+
display: block;
18+
margin-bottom: 10px;
19+
background-color: #F4F7F8;
20+
border: none;
21+
border-left: 6px solid #558ABB;
22+
color: #4D4E53;
23+
width: 90%;
24+
max-width: 700px;
25+
padding: 10px 10px 0px;
26+
font-size: 90%;
27+
}
28+
29+
textarea:nth-of-type(1) {
30+
height: 170px
31+
}
32+
33+
textarea:nth-of-type(2) {
34+
height: 160px
35+
}
36+
37+
.playable-buttons {
38+
text-align: right;
39+
width: 90%;
40+
max-width: 700px;
41+
padding: 5px 10px 5px 26px;
42+
font-size: 100%;
43+
}
44+
45+
section {
46+
width: 90%;
47+
max-width: 700px;
48+
border: 1px solid #4D4E53;
49+
border-radius: 2px;
50+
padding: 10px 14px 10px 10px;
51+
margin-bottom: 10px;
52+
}
53+
54+
section input {
55+
display: block;
56+
margin: 5px;
57+
}
58+
59+
.box {
60+
width: 500px;
61+
border: 2px dotted rgb(96, 139, 168);
62+
}
63+
64+
.box>* {
65+
padding: 20px;
66+
border: 2px solid rgb(96, 139, 168);
67+
border-radius: 5px;
68+
background-color: rgba(96, 139, 168, .2);
69+
}
70+
</style>
71+
<style class="editable">
72+
.box {
73+
display: flex;
74+
align-items: flex-start;
75+
justify-content: space-between;
76+
}
77+
78+
.box :first-child {
79+
align-self: center;
80+
}
81+
</style>
82+
</head>
83+
84+
<body>
85+
<section>
86+
<div class="box">
87+
<div>One</div>
88+
<div>Two</div>
89+
<div>Three
90+
<br>has
91+
<br>extra
92+
<br>text
93+
</div>
94+
</div>
95+
96+
</section>
97+
<textarea class="playable-css">
98+
.box {
99+
display: flex;
100+
align-items: flex-start;
101+
justify-content: space-between;
102+
}
103+
104+
.box :first-child {
105+
align-self: center;
106+
}
107+
</textarea>
108+
<textarea id="code" class="playable-html">
109+
<div class="box">
110+
<div>One</div>
111+
<div>Two</div>
112+
<div>Three
113+
<br>has
114+
<br>extra
115+
<br>text
116+
</div>
117+
</div>
118+
</textarea>
119+
<div class="playable-buttons">
120+
<input id="reset" type="button" value="Reset">
121+
</div>
122+
</body>
123+
<script>
124+
var section = document.querySelector('section');
125+
var editable = document.querySelector('.editable');
126+
var textareaHTML = document.querySelector('.playable-html');
127+
var textareaCSS = document.querySelector('.playable-css');
128+
var reset = document.getElementById('reset');
129+
var htmlCode = textareaHTML.value;
130+
var cssCode = textareaCSS.value;
131+
132+
function fillCode() {
133+
editable.innerHTML = textareaCSS.value;
134+
section.innerHTML = textareaHTML.value;
135+
}
136+
137+
reset.addEventListener('click', function () {
138+
textareaHTML.value = htmlCode;
139+
textareaCSS.value = cssCode;
140+
fillCode();
141+
});
142+
143+
textareaHTML.addEventListener('input', fillCode);
144+
textareaCSS.addEventListener('input', fillCode);
145+
window.addEventListener('load', fillCode);
146+
</script>
147+
148+
</html>

0 commit comments

Comments
 (0)