Hàm url() là một hàm dựng sẵn dùng để chèn một file. Tham số của hàm này là URL tuyệt đối, URL tương đối hoặc data URI. Hàm url()
có thể dùng cho background-image
, border-image
, list-style-image
... content
, cursor
, border-image-source
, src
trong @font-face
, và @counter-style/symbol
.
Cú pháp:
url( <string> <url-modifier>* )
Tham số: Hàm này chấp nhận một tham số duy nhất là url. Nó giữ URL ở định dạng string.
Ví dụ về URL:
<css_property>: url("https://www.geeksforgeeks.org/image.png///")
<css_property>: url('https://www.geeksforgeeks.org/image.png///')
<css_property>: url(https://www.geeksforgeeks.org/image.png///)
Ví dụ: Ví dụ dưới đây minh họa hàm url()
trong CSS.
<!DOCTYPE html>
<html>
<head>
<title>CSS url() function</title>
<style>
body {
background-image: url(
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png");
text-align: center;
}
h1 {
color: white;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>CSS url() function</h2>
</body>
</html>
Kết quả:
Trình duyệt được hỗ trợ: Các trình duyệt hỗ trợ hàm url()
được liệt kê dưới đây:
- Google Chrome 1
- Edge 12
- Internet Explorer 3
- Firefox 1
- Safari 1
- Opera 3.5