Search code examples
htmlstyles

How to perform hover and make link not change colour when clicked in HTML


I am using Python to work with HTML files. I exported my dataframes as HTML files and generated a clickable Table of contents. There is only one problem when I click a link in the table of contents, the colour changes. Is there a way to make it so this doesn't happen?

html = "</head> <body> <h1>Data records</h1> <h2>From February 2019 to January 2020</h2> </body></html>"

for link, names in zip(sorted(df, key=lambda x: int(x.split('-')[0])), data_list):         
     html += '<a href="%s">%s</a><br>' % (link, names)

with open("test.html", "w") as f:
     f.write(html)

Solution

  • have you tried adding a css tag into your html output ? for example :

    html = "<style type='text/css'>a:visited{color:black;}</style></head><body> <h1>Data records</h1> <h2>From February 2019 to January 2020</h2> </body></html>"