Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCameron Scully
2,919 PointsWhy does #top use "#" instead of an underscore or "_" ?
Why does #top use "#" instead of an underscore or "_" ? Also, at the end of the course will there be a comprehensive list of html commands or terms that we may be able to tap into, or is there a website or .pdf that already lists these?
3 Answers
Jon Myzzle
6,279 PointsHello Cameron!
MDN is a great tool to use for referencing the many commands and syntax within both HTML and CSS alone! I'd recommend taking the time to familiarize yourself with it. I personally find myself using it almost everyday, if not, everyday!
Referring back to your first question, im assuming you are talking about the selector for an ID /class. Where using the "#" is for an ID and a "." is for a class. To my understanding... that's just kind of the way HTML and CSS are set up! For example, when using a "#Top" in a link that goes back to the top of the page you are telling the code, "Hey link, I want you to sort through the code and find the ID named Top and take me there!"
The same can be applied when using CSS to style code. See the following:
#main-nav {
border: dotted blue 2px;
}
.main-pg {
border: solid red 4px;
}
These are saying, "Hey selector, I want you to find the ID /CSS named main-nav /main-pg and then apply the following styles to them!
I hope that makes sense and helped to answer your question, i can explain a little more if you are still confused!
Cheers and happy coding!!
Steven Parker
231,271 PointsAn href attribute can contain a URL or a URL fragment that the hyperlink points to.
A URL fragment is a name preceded by a hash mark (#), which specifies an internal target location (an ID of an HTML element) within the current document. Note: You can also use the special value href="#top" or the empty fragment href="#" to link to the top of the current page.
Personally, I prefer the empty fragment "#" to avoid confusion with any internal target locations. But the "#" symbol in either case maintains consistency with the URL fragment designation.
Steven Parker
231,271 PointsThe fragment "#top" is a special case that works without defining a reference. But if you do define a reference by that name, it overrides the default behavior. That's why I recommend avoiding it and using "#" instead.
Cameron Scully
2,919 PointsCameron Scully
2,919 PointsThank you for both of your answers, they really do help clear up things.
BUT
What I am talking about is what defines the difference between this (#):
<a href="#top">example hyperlink text</a>
and this
<a href="_blank">example hyperlink text</a>
from what it sounds like, the difference is that "#" has to do with something internal in the code, whereas "_" has to do with something external??
Also how does the code define a "top"? I couldn't find anywhere in the code where it lists a point to reference called "top". My guess would be that it is simply how html is formatted and is one of its golden set rules...
Jon Myzzle
6,279 PointsJon Myzzle
6,279 PointsThis all comes down to the <a> tag I believe. W3schools describes it as the following but I can TRY and sum it up a little clearer. I would suggest taking a quick peek at it though!
"#top" is an HTML value of the "href" attribute. Its just another URL name. It would be no different than typing out a website name or typing the name of an addition page of your website like index.html or information.html.
"_blank" is an HTML value of the "target" attribute, it doesn't specify a location to go to but rather where to open that location at. As in a new window, a new tab, etc. In other words, these are predefined in the HTML code itself, whereas a URL can be any website, file, location on the current page using an ID.
Cameron Scully
2,919 PointsCameron Scully
2,919 Pointsperfect so the examples I had were actually false. haha! That helped to solve my question perfectly! Thanks a million to you guys!