• 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"

Object Storage Arubacloud
0 głosów
4,341 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ź 174 wizyt
pytanie zadane 11 marca 2023 w JavaScript przez TOWaD Mądrala (6,000 p.)
0 głosów
1 odpowiedź 584 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ź 770 wizyt
pytanie zadane 25 stycznia 2019 w JavaScript przez MrxCI Dyskutant (8,260 p.)

92,576 zapytań

141,426 odpowiedzi

319,652 komentarzy

61,961 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.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...