Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use downloaded image or font(zip file) in CSS

A beginner question: I know how to use online image--copy paste in url but don't know how it works if downloaded. I downloaded the font as a zip file but I don't know what to put in the url, the same question for image. Thanks.

enter image description here

like image 528
Emma Zhu Avatar asked Sep 11 '25 16:09

Emma Zhu


1 Answers

As you a beginner I will explain everything to you step by step.

In the beginning you must unzip the compressed file sansationlight.zip

Right click on sansationlight.zip then click on Extract files

enter image description here

You will get the following window

enter image description here

Click on OK

You will get sansationlight folder

enter image description here

Create a folder next to the index.html file and name it Fonts

enter image description here

enter image description here

Copy the folder sansationlight that you unzip to the Fonts folder

Copy

enter image description here

Paste in Fonts folder

enter image description here

Add the following style code to the style tag in the index.html file:

@font-face {
    font-family: 'SansationLight';
    src: url('Fonts/SansationLight/SansationLight.eot');
    src: url('Fonts/SansationLight/SansationLight.eot?#iefix') format('embedded-opentype'),
         url('Fonts/SansationLight/SansationLight.woff') format('woff'),
         url('Fonts/SansationLight/SansationLight.ttf') format('truetype'),
         url('Fonts/SansationLight/SansationLight.svg#SansationLight') format('svg');
    font-weight: normal;
    font-style: normal;

}

div{
    font-family: 'SansationLight';
}

Here you will see how the code will appear on the your HTML page:

enter image description here

The result:

enter image description here

Here is the font before adding the style code:

enter image description here

If you want to use an external style file, follow these steps:

After copying the sansationlight folder to Fonts folder, create another folder next to the Fonts folder, name it stylesheets

enter image description here

Inside the stylesheets folder, create the style.css file and open it.

Copy the following code into the style.css file:

@font-face {
    font-family: 'SansationLight';
    src: url('../Fonts/SansationLight/SansationLight.eot');
    src: url('../Fonts/SansationLight/SansationLight.eot?#iefix') format('embedded-opentype'),
         url('../Fonts/SansationLight/SansationLight.woff') format('woff'),
         url('../Fonts/SansationLight/SansationLight.ttf') format('truetype'),
         url('../Fonts/SansationLight/SansationLight.svg#SansationLight') format('svg');
    font-weight: normal;
    font-style: normal;

}

.mydiv{


font-family: 'SansationLight';
}

Note, I've added ../ for one step back out of the stylesheets folder

Here you see how the code will appear on the your style.css file:

enter image description here

To link the style.css file with index.html, use the link tag in index.html:

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

This is how the code will appear in the index.html file:

enter image description here

Note In the first way I made the font style for all divs div{ }

In the second way, the class was used .mydiv

For adding images:

Create a folder next to the index.html file and name it images

enter image description here

Add the image you want to use to the images folder

enter image description here

Use the <img> tag to add an image

<img src="images/image.jpg" style="width: 50%; height: 50%">

enter image description here

The result:

enter image description here

Useful Links:

HTML Tutorial

CSS Tutorial

HTML, CSS and more

HTML5 video Tutorial

CSS3 video Tutorial

The image I used

like image 60
Husam Ebish Avatar answered Sep 14 '25 07:09

Husam Ebish