Skip to content

Commit

Permalink
style: Refactor CSS to improve readability and maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitacontreras committed Jun 28, 2024
1 parent f990a06 commit 6db43fa
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 131 deletions.
78 changes: 78 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
* {
margin: 0;
padding: 0;
background-color: #1f1f1f;
}
body{
overflow:hidden;
}
.container {
background-color: #fff;
border: 1px solid #ababab;
height: 500px;
width: 500px;
margin: 0;
padding: 0 20px;
box-sizing: border-box;
display: flex;
align-items: flex-start;
justify-content: center;
overflow: hidden;
margin: 20px 0;
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-app-region: no-drag;
cursor: default;
}

.text {
background-color: #fff;
text-align: justify;
text-justify: inter-word;
font-size: 60px;
filter: blur(2px);
font-family: Arial;
font-stretch: ultra-condensed;
margin: 20px;
}
h1 {
color: #ece8e8;
text-align: justify;
text-justify: inter-word;
font-size: 60px;
font-family: Arial;
font-stretch: ultra-condensed;
margin: 0;
}
h3{
color:#696969;
font-size:12px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding-bottom: 20px;
}
input {
color: #ece8e8;
background-color: #2e2e2e;
border: 0;
outline: none;
height: 30px;
width: 500px;
}
.center {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.social-networks {
display: flex;
justify-content: center;
margin-top: 20px;
}
.social-networks i {
font-size: 40px;
color: #ece8e8;
margin: 0 10px;
cursor: pointer;
}
133 changes: 2 additions & 131 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,86 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
background-color: #1f1f1f;
}
body{
overflow:hidden;
}
.container {
background-color: #fff;
border: 1px solid #ababab;
height: 500px;
width: 500px;
margin: 0;
padding: 0 20px;
box-sizing: border-box;
display: flex;
align-items: flex-start;
justify-content: center;
overflow: hidden;
margin: 20px 0;
-webkit-user-select: none;
-webkit-user-drag: none;
-webkit-app-region: no-drag;
cursor: default;
}

.text {
background-color: #fff;
text-align: justify;
text-justify: inter-word;
font-size: 60px;
filter: blur(2px);
font-family: Arial;
font-stretch: ultra-condensed;
margin: 20px;
}
h1 {
color: #ece8e8;
text-align: justify;
text-justify: inter-word;
font-size: 60px;
font-family: Arial;
font-stretch: ultra-condensed;
margin: 0;
}
h3{
color:#696969;
font-size:12px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding-bottom: 20px;
}
input {
color: #ece8e8;
background-color: #2e2e2e;
border: 0;
outline: none;
height: 30px;
width: 500px;
}
.center {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.social-networks {
display: flex;
justify-content: center;
margin-top: 20px;
}
.social-networks i {
font-size: 40px;
color: #ece8e8;
margin: 0 10px;
cursor: pointer;
}
</style>
<link rel="stylesheet" href="css/style.css">
<meta charset="UTF-8" />
<meta name="description" content="Generate your brat-like image from the newest Charlie XCX album" />
<meta name="keywords" content="brat, brat generator, brat charlie xcx, charlix xcx," />
Expand All @@ -106,56 +27,6 @@ <h3>(screenshot to save the image)</h3>
</div>
</div>

<script>
function adjustTextSize() {
const container = document.getElementById("container");
const text = document.getElementById("text");

text.style.fontSize = "50px";
text.style.lineHeight = "normal";

const textClone = text.cloneNode(true);
textClone.style.visibility = "hidden";
textClone.style.position = "absolute";
textClone.style.lineHeight = "normal";
textClone.style.width = container.clientWidth + "px";
container.appendChild(textClone);

let fontSize = parseInt(window.getComputedStyle(text).fontSize, 10);
const containerHeight = container.clientHeight;
const containerWidth = container.clientWidth;
let textHeight, textWidth;

do {
textHeight = textClone.scrollHeight;
textWidth = textClone.scrollWidth;

if (textHeight > containerHeight || textWidth > containerWidth) {
fontSize -= 1;
textClone.style.fontSize = fontSize + "px";
} else {
break;
}
} while (fontSize > 0);

text.style.fontSize = fontSize + "px";
textClone.style.fontSize = fontSize + "px";
textHeight = textClone.scrollHeight;
const newLineHeight = containerHeight / (textHeight / fontSize);
text.style.lineHeight = (newLineHeight > fontSize ? newLineHeight : fontSize) + "px";
container.removeChild(textClone);
}

function updateText() {
const textInput = document.getElementById("textInput");
const text = document.getElementById("text");

text.textContent = textInput.value;
adjustTextSize();
}

window.onload = adjustTextSize;
window.onresize = adjustTextSize;
</script>
<script src="js/text.js"></script>
</body>
</html>
49 changes: 49 additions & 0 deletions js/text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function adjustTextSize() {
const container = document.getElementById("container");
const text = document.getElementById("text");

text.style.fontSize = "50px";
text.style.lineHeight = "normal";

const textClone = text.cloneNode(true);
textClone.style.visibility = "hidden";
textClone.style.position = "absolute";
textClone.style.lineHeight = "normal";
textClone.style.width = container.clientWidth + "px";
container.appendChild(textClone);

let fontSize = parseInt(window.getComputedStyle(text).fontSize, 10);
const containerHeight = container.clientHeight;
const containerWidth = container.clientWidth;
let textHeight, textWidth;

do {
textHeight = textClone.scrollHeight;
textWidth = textClone.scrollWidth;

if (textHeight > containerHeight || textWidth > containerWidth) {
fontSize -= 1;
textClone.style.fontSize = fontSize + "px";
} else {
break;
}
} while (fontSize > 0);

text.style.fontSize = fontSize + "px";
textClone.style.fontSize = fontSize + "px";
textHeight = textClone.scrollHeight;
const newLineHeight = containerHeight / (textHeight / fontSize);
text.style.lineHeight = (newLineHeight > fontSize ? newLineHeight : fontSize) + "px";
container.removeChild(textClone);
}

function updateText() {
const textInput = document.getElementById("textInput");
const text = document.getElementById("text");

text.textContent = textInput.value;
adjustTextSize();
}

window.onload = adjustTextSize;
window.onresize = adjustTextSize;

0 comments on commit 6db43fa

Please sign in to comment.