I'm trying to create a logo using pure HTML and CSS. The design is very intuitive, being a [13x13] matrix containing some colored items.
CSS is very simple and minor. However, the HTML code has many repeated parts and needs to be DRY (Don't Repeat Yourself).
body { width: 100vmin; margin: auto } logo { display: grid; grid-template-columns: repeat(13, 1fr); } s { } w { background-color: #d6d6d6; aspect-ratio: 1 } l { background-color: #d6d6d6; aspect-ratio: 1 } f { background-color: #d6d6d6; aspect-ratio: 1 }
I've tried usinginstead ofwithout success.
Is there any way to reduce this code?
Note:The color should remain unchanged.
If javascript is available, you can concatenate the cell type into a string object and use it to dynamically build the flag. Sample code is as follows.
let logo = document.getElementById("logo"); logo.dataset["cells"].split('').forEach(a => logo.append(document.createElement(a)));body { width: 100vmin; margin: auto } logo { display: grid; grid-template-columns: repeat(13, 1fr); } w { background-color: #d6d6d6; aspect-ratio: 1 } l { background-color: #d6d6d6; aspect-ratio: 1 } f { background-color: #d6d6d6; aspect-ratio: 1 }Based on the need for HTML/CSS and @Temani Afif's comment, here is an SVG solution:
.w * { stroke:red;stroke-width:1;;fill:none;stroke-linejoin="miter"; } .l * { stroke:green;stroke-width:1;;fill:none;stroke-linejoin="miter"; } .f * { stroke:blue;stroke-width:1;;fill:none;stroke-linejoin="miter"; }