Hello there,
First off, I’m a beginner with golang and with webdev generally.
I’m attempting to program a easy web site and I’m not in a position to get the css config proper.
.
├── static
│ └── css
│ └── check.css
├── check.go
└── tmpl
└── check.html
check.go:
bundle foremost
import (
"log"
"web/http"
"textual content/template"
)
func foremost() {
web site := func(w http.ResponseWriter, r *http.Request) {
templ := template.Should(template.ParseFiles("tmpl/check.html"))
templ.Execute(w, nil)
}
http.Deal with("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/check/", web site)
log.Println("Listening on :8081 ...")
err := http.ListenAndServe(":8081", nil)
if err != nil {
log.Deadly(err)
}
}
check.html:
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta identify="viewport" content material="width=device-width, initial-scale=1.0" />
<meta http-equiv="“X-UA-Appropriate”" content material="“ie" ="edge”" />
<title>Llynx Demo @ IGMR</title>
<hyperlink
href="https://cdn.jsdelivr.web/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="nameless"
/>
<!-- <type> -->
<!-- [class*="col"] { -->
<!-- padding: 1rem; -->
<!-- background-color: #33b5e5; -->
<!-- border: 2px strong #fff; -->
<!-- colour: #fff; -->
<!-- text-align: heart; -->
<!-- } -->
<!---->
<!-- [class*="con"] { -->
<!-- padding: 1rem; -->
<!-- background-color: #9e33e5; -->
<!-- border: 2px strong #fff; -->
<!-- colour: #fff; -->
<!-- text-align: heart; -->
<!-- } -->
<!-- </type> -->
<hyperlink rel="stylesheet" kind="textual content/css" href="https://discussion board.golangbridge.org/t/using-net-http-im-unable-to-serve-css/static/css/check.css" />
</head>
<physique>
<div class="container">
<h1>HI</h1>
</div>
</physique>
</html>
And the check.css:
.col {
padding: 1rem;
background-color: #33b5e5;
border: 2px strong #fff;
colour: #fff;
text-align: heart;
}
.con {
padding: 1rem;
background-color: #9e33e5;
border: 2px strong #fff;
colour: #fff;
text-align: heart;
}
3 Thinks I’ve noticed:
- The Chrome Dev device doesn’t present an error that it couldn’t load some css information
- If i am going on http://localhost:8081/static/css/check.css I see the content material of the .css file – thats good, proper?
- Within the check.html: If I write the styling there I can see the div in purple, so the css shouldn’t be the problem?
I’m looking for 3 hours now, I hope any individual may give me some hints:)
Thanks!
Change this line in your .html
file to
href="https://discussion board.golangbridge.org/static/css/check.css"
Right here you’ve gotten an instance how one can “add” all stuff you place throughout the public folder.
Thanks, however sadly this isn’t working both.
I learn by all, the file construction is just not talked about nor a completed repo.
Didn’t made it
I feel one thing is improper together with your html or css code. I copied all the pieces out of your instance. Simply added h1 colour: crimson
to css file, modified this slash and all the pieces labored.