Created
January 2, 2024 09:26
-
-
Save horstjens/d84f6714ad0eaa4d5f5081eae72525d5 to your computer and use it in GitHub Desktop.
htmltabelle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start = """<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
table { | |
font-family: arial, sans-serif; | |
border-collapse: collapse; | |
width: 100%; | |
} | |
td, th { | |
text-align: left; | |
padding: 8px; | |
} | |
th {border: 5px solid #777777;} | |
td {border: 1px solid #777777;} | |
tr:nth-child(even) { | |
background-color: #eeeeee; | |
} | |
</style> | |
</head> | |
<body>""" | |
def rgb2hex(r,g,b): | |
return "#{:02x}{:02x}{:02x}".format(r,g,b) | |
with open("keineAhnung.html","w") as n: | |
n.write(start) | |
n.write("<h1>Anas riesige 20x20 Tabelle</h1>\n") | |
# 1. zeile der tabelle | |
n.write("<table><tr><th></th>") | |
for x in range(1,21): | |
# (210 - 50) = 160 / 20 = 8 | |
farbe = 210 - 8 * x | |
hexcode = rgb2hex(farbe,farbe,farbe) | |
n.write(f'<th style="background-color: {hexcode};">{x}</th>') | |
n.write("</tr>") | |
# ----------------------------------------- | |
for i in range(1, 21): | |
rot = 255 | |
grün = 0 | |
blau = 0 | |
n.write("<tr>") | |
hexcode = rgb2hex(rot, grün, blau) | |
n.write(f'<th style="background-color: {hexcode};">1</th>') | |
# ----- | |
for x in range(1,21): | |
r = max(0, rot-x*6) | |
g = max(0, grün-x*12) | |
b = max(0, blau-x*12) | |
hexcode = rgb2hex(r,g,b) | |
n.write(f'<td style="background-color: ' | |
f'{hexcode};">{x}</td>') | |
n.write("</tr>") | |
# --------- | |
n.write("</table>") | |
n.write("</body></html>") | |
print("website ist fertig") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment