• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Różnica między "href", a "src"

Aruba Cloud - Virtual Private Server VPS
0 głosów
4,758 wizyt
pytanie zadane 18 października 2015 w HTML i CSS przez Pampi Początkujący (390 p.)

Wiem, że pytanie pewnie jest banalne i odpowiedź będzie równie wyczerpująca >.<
Jaka jest różnica między "src", a "href"?
Z tego co wiem obu można używać jako ścieżki lokalnej i globalnej. Wizualnie też nie widzę różnicy.
Wiem, że jednego używa się głównie w linkach, a drugiego w zdjęciach.
W internetach jedyną odpowiedź jaką znalazłem jest: "Bo jedno jest do img, a drugie do a".
Nie zadowala mnie taka odpowiedź ;-; wolę coś zrozumieć niż wykuć smiley

2 odpowiedzi

+2 głosów
odpowiedź 19 października 2015 przez Radekoslaw123 Gaduła (3,080 p.)
Hym, sam pewnie źle powiem XD

Ale raczej tak jest że href kieruję do strony internetowej, a src pobiera plik i używa go w odpowiednim znaczniku.

Chyba dobrze powiedziałem :)
+1 głos
odpowiedź 18 października 2015 przez Boshi VIP (100,240 p.)

z SO, serio tak ciezko wrzucić pytanie   po angielsku ?

Yes. There is a differentiation between src and href and they can't be used interchangeably. We use src for replaced elements while href for establishing a relationship between the referencing document and an external resource.

href (Hypertext Reference) attribute specifies the location of a Web resource thus defining a link or relationship between the current element (in case of anchor a) or current document (in case of link) and the destination anchor or resource defined by this attribute. When we write:

<link href="style.css" rel="stylesheet" />

The browser understands that this resource is a stylesheet and the processing parsing of the page is not paused (rendering might be paused since the browser needs the style rules to paint and render the page). It is not similar to dumping the contents of the css file inside the style tag. (Hence is is advisable to use link rather than @import for attaching stylesheets to your html document.)

src (Source) attribute just embeds the resource in the current document at the location of the element's definition. For eg. When the browser finds

<script src="script.js"></script>

The loading and processing of the page is paused until this the browser fetches, compiles and executes the file. It is similar to dumping the contents of the js file inside the script tag. Similar is the case with img tag. It is an empty tag and the content, that should come inside it, is defined by the src attribute. The browser pauses the loading until it fetches and loads the image. [so is the case with iframe]

This is the reason why it is advisable to load all JavaScript files at the bottom (before the </body> tag

 

Podobne pytania

0 głosów
1 odpowiedź 225 wizyt
pytanie zadane 11 marca 2023 w JavaScript przez TOWaD Mądrala (6,340 p.)
0 głosów
1 odpowiedź 991 wizyt
pytanie zadane 18 lipca 2018 w HTML i CSS przez Michał Rupiński Początkujący (270 p.)
0 głosów
1 odpowiedź 1,022 wizyt
pytanie zadane 25 stycznia 2019 w JavaScript przez MrxCI Dyskutant (8,260 p.)

93,291 zapytań

142,289 odpowiedzi

322,332 komentarzy

62,612 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Wprowadzenie do ITsec, tom 1 Wprowadzenie do ITsec, tom 2

Można już zamawiać dwa tomy książek o ITsec pt. "Wprowadzenie do bezpieczeństwa IT" - mamy dla Was kod: pasja (użyjcie go w koszyku), dzięki któremu uzyskamy aż 15% zniżki! Dziękujemy ekipie Sekuraka za fajny rabat dla naszej Społeczności!

...