How to use downloaded image or font(zip file) in CSS - 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.

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
You will get the following window
Click on OK
You will get sansationlight folder
Create a folder next to the index.html file and name it Fonts
Copy the folder sansationlight that you unzip to the Fonts folder
Copy
Paste in Fonts folder
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:
The result:
Here is the font before adding the style code:
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
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:
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:
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
Add the image you want to use to the images folder
Use the <img> tag to add an image
<img src="images/image.jpg" style="width: 50%; height: 50%">
The result:
Useful Links:
HTML Tutorial
CSS Tutorial
HTML, CSS and more
HTML5 video Tutorial
CSS3 video Tutorial
The image I used

Ok, sounds like you're trying to add images to a website. Your images need to be hosted somewhere to be used on a website.
When you use a URL of one that is already on the Internet, that image is hosted by someone else.
If you've downloaded it, you'll need to add it to your web project, which means you'll be hosting it yourself. It will then use a URL to reference the image and display it, but that URL will be on your own domain.
Depending on the software you're using to build this, sometimes you can drag and drop the image into your web page, and the software will do the rest.

Images on your website
Like Andrew says, in order to use images in your website, the images should be on any place on the web.
You can use Amazon S3 for storing your website images.
https://aws.amazon.com/s3/.
Once you get the image online url, you can use it on your html just pasting it on the src attribute of an img tag.
<img src="url/of/the/image">
Custom Fonts on your website
Now, if you want to use a custom-font to your website, you should paste your font files into your website folder and create a css3 rule like below:
#font-face {
font-family: myfont;
src: url(route/to/your/font/my_font.woff);
}
Then, if you want to use the font, for example on all you h2 tags:
h2 {
font-family: myfont;
}
Hope it will help you.

Related

Can´t access my public folder from css file in React App

I'm receiving the following error everytime I try to access a file in my public folders.
./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
Error: Can't resolve '/assets/fonts/PlantinMTProRg.woff' in 'C:\Users\User\Desktop\NewPage\webpage\src'
As you can see, I'm trying to call a font from my index.css, which is inside my src folder.
I call it as it follows:
#font-face {
font-family: 'PlantinMTPro';
src: local('plantin_mt_pro'), url(/assets/fonts/PlantinMTProRg.woff) format('truetype');
}
But no luck so far. Having the same issue for images.
Any ideas?
Thanks in advance!
In your index.html you must link your index.css from the public directory
<link rel="stylesheet" href="%DIR%/NewPage/webpage/src/index.css">
From there, you need to figure out the right url to reach your font family, which you said was in your src file.
#font-face {
font-family: 'PlantinMTPro';
src: local('plantin_mt_pro'), url(/assets/fonts/PlantinMTProRg.woff) format('woff');
}
Also, I notice you used format of truetype. Only use that if you're importing a .ttf file. Use format('woff') in this scenario.
You may need to add some changes here if you're trying to support multiple browsers

Typicon local directory location

i downloaded a source code for a navigation in web, and in the source code there is this "Typicon"
in the HTML he include this
<link rel="stylesheet" type="text/css" href="css/component.css" />
.
Home
in the component CSS here is this.
#font-face {
font-family: 'typicons';
src:url('../fonts/typicons/typicons.eot');
src:url('../fonts/typicons/typicons.eot?#iefix') format('embedded-opentype'),
url('../fonts/typicons/typicons.ttf') format('truetype'),
url('../fonts/typicons/typicons.woff') format('woff'),
url('../fonts/typicons/typicons.svg#typicons') format('svg');
.
.icon-home::before { content: "\e601" }
I want to change the logo of certain class but I cant seem to find the directory for all the icons in the folder in which I can choose from.
What you need is not the directory where the icons are located. They're on the font files. What you need is the HEX code of the icons you want to use in your classes.
One way (free, by the way) is to upload the .ttf file to either Flaticon or FontSquirrel, so that you can create a CSS file with all the hex codes.
Note that this can also be used to create Webfonts from any FREE font and that the CSS file adds CSS classes for each glyph/icon (so that you can use the CSS class instead of remembering/fetching the icons' codes).

IcoMoon App icon fonts are shown as 

Everything is fine but when I use ../ it doesn't work. To call the CSS I use: <link rel="stylesheet" href="../../IcoMoon-App/style.css" /> and it do appears but as . I get the error at MainFolder/Albumes/Clarity_Deluxe_Edition/index.html, but when use the icons at MainFolder/index.html they're displayed well (note that the css location to this one is <link rel="stylesheet" href="IcoMoon-App/style.css" />). This is how my directory is structured:
MainFolder
├index.html
├css
│└index_style.css
├IcoMoon-App
│├IcoMoon-App.eot
│├IcoMoon-App.svg
│├IcoMoon-App.ttf
│├IcoMoon-App.woff
│└style.css
└Albumes
└Clarity_Deluxe_Edition
├index.html
└css
└index_style.css
Yes, because of I changed the location, I also changed the #font-face:
#font-face {
font-family: 'IcoMoon-App';
src:url('IcoMoon-App.eot?xzz47n');
src:url('IcoMoon-App.eot?#iefixxzz47n') format('embedded-opentype'),
url('IcoMoon-App.woff?xzz47n') format('woff'),
url('IcoMoon-App.ttf?xzz47n') format('truetype'),
url('IcoMoon-App.svg?xzz47n#IcoMoon-App') format('svg');
font-weight: normal;
font-style: normal;
}
Am I using wrong the "back folder" (../, don't know the exact name)? Or I did a mistake when changing the location?
One solution to this is using a different way of defining your paths.
In your CSS file, change the path to your IcoMoon font files to:
src:url('/IcoMoon-App/IcoMoon-App.eot?xzz47n');
The / at the very start of the URL makes the browser start from the domain-level of your website and then add the URL exactly as it appears in the example I gave. This will build an "absolute" URL to your IcoMoon font files, regardless of how deep in your folder structure you are.
A drawback to this approach is that the fonts may not appear when you're browsing your site locally (e.g. at http://localhost/~alej27/yoursite) because that would make the browser search for the font files at http://localhost/IcoMoon-App/IcoMoon-App.eot?xzz47n. There are ways around that (hosts file modifying and setting up a virtual domain) but that's outside the scope of this question :)

Downloading a Google font and setting up an offline site that uses it

I have a template and it has a reference to a Google font like this:
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600,300' rel='stylesheet' type='text/css'>
How can I download it and set it up to use in my pages which are running offline all the time?
Check out google webfonts helper
It lets you download every web font of Google and suggests css code for the implementation.
This tool also allows you to simply download all formats at once without the hassle.
Ever wanted to know where Google hosts their webfonts? This service might be handy if you want to download all .eot, .woff, .woff2, .svg, .ttf files of a font variant directly from google (normally your User-Agent would determine the best format).
Also take a look at their Github page.
Just go to Google Fonts - http://www.google.com/fonts/ , add the font you like to your collection, and press the download button. And then just use the #fontface to connect this font to your web page.
Btw, if you open the link you are using, you'll see an example of using #fontface
http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600,300
For an example
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 300;
src: local('Open Sans Light'), local('OpenSans-Light'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/DXI1ORHCpsQm3Vp6mXoaTaRDOzjiPcYnFooOUGCOsRk.woff) format('woff');
}
Just change the url address to the local link on the font file, you've downloaded.
You can do it even easier.
Just download the file, you've linked:
http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600,300
Name it opensans.css or so.
Then just change the links in url() to your path to font files.
And then replace your example string with:
<link href='opensans.css' rel='stylesheet' type='text/css'>
Found a step-by-step way to achieve this (for 1 font):
(as of Sep-9 2013)
Choose your font at http://www.google.com/fonts
Add the desired one to your collection using "Add to collection" blue button
Click the "See all styles" button near "Remove from collection" button and make sure that you have selected other styles you may also need such as 'bold'...
Click the 'Use' tab button on bottom right of the page
Click the download button on top with a down arrow image
Click on "zip file" on the the popup message that appears
Click "Close" button on the popup
Slowly scroll the page until you see the 3 tabs "Standrd|#import|Javascript"
Click "#import" tab
Select and copy the url between 'url(' and ')'
Copy it on address bar in a new tab and go there
Do "File > Save page as..." and name it "desiredfontname.css" (replace accordingly)
Decompress the fonts .zip file you downloaded (.ttf should be extracted)
Go to "http://ttf2woff.com/" and convert any .ttf extracted from zip to .woff
Edit desiredfontname.css and replace any url within it [between 'url(' and ')'] with the corresponding converted .woff file you got on ttf2woff.com; path you write should be according to your server doc_root
Save the file and move it at its final place and write the corresponding <link/> CSS tag to import these in your HTML page
From now, refer to this font by its font-family name in your styles
That's it. Cause I had the same problem and the solution on top did not work for me.
The other answers are not wrong, but I found this to be the fastest way.
Download the zip file from Google fonts and unzip it.
Upload the font files 3 at a time to http://www.fontsquirrel.com/tools/webfont-generator
Download the results.
Results contain all font formats: woff, svg, ttf, eot.
AND as an added bonus they generate the css file for you too!
If you'd like to explicitly declare your package dependencies or automate the download, you can add a npm package to pull in google fonts and serve locally.
Fontsource
Fontsource allows you to:
Self-host Open Source fonts in neatly bundled NPM packages.
You can search npm for scope:fontsource <typefacename> to browse the available fonts like #fontsource/roboto or #fontsource/open-sans and install like this:
$ npm install #fontsource/roboto --save
$ npm install #fontsource/open-sans --save
Font Downloaders
For a more generic use case, there are several npm packages that will deliver fonts in two steps, first by installing the library, and then by pointing it to the font name and options you'd like to include.
Google Fonts Webpack Plugin
Google Fonts Offline
Google Fonts
Get Google Fonts
Further Reading:
How to host material icons offline?
Using offline Material icons and Roboto font in Electron app
Archived: Typefaces
3 steps:
Download your custom font on Goole Fonts and down load .css file
ex: Download http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600,300
and save as example.css
Open file you download (example.css). Now you must download all font-face file and save them on fonts directory.
Edit example.css: replace all font-face file to your .css download
Ex:
#font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 400;
src: local('Open Sans Italic'), local('OpenSans-Italic'), url(http://fonts.gstatic.com/s/opensans/v14/xjAJXh38I15wypJXxuGMBvZraR2Tg8w2lzm7kLNL0-w.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
Look at src: -> url. Download http://fonts.gstatic.com/s/opensans/v14/xjAJXh38I15wypJXxuGMBvZraR2Tg8w2lzm7kLNL0-w.woff2 and save to fonts directory. After that change url to all your downloaded file. Now it will be look like
#font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 400;
src: local('Open Sans Italic'), local('OpenSans-Italic'), url(fonts/xjAJXh38I15wypJXxuGMBvZraR2Tg8w2lzm7kLNL0-w.woff2) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
** Download all fonts contain .css file
Hope it will help u
When using Google Fonts, your workflow is divided in 3 steps : "Select", "Customize", "Embed". If you look closely, at the right end of the "Use" page, there is a little arrow which allows you to download the font currently in your collection.
After that, and once the font is installed on your system, you just have to use it like any other regular font using the font-family CSS directive.
Essentially you are including the font into your project.
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: normal;
src: url('path/to/OpenSans.eot');
src: local('Open Sans'), local('OpenSans'), url('path/to/OpenSans.ttf') format('truetype');
1)Go at google fonts
2)select your font and it's a style
3)then you will get a link tag, side of link click on import
copy its link present inside the URL(' here ') and paste it on the browser search bar.
And then you will get something like this
and then download it and save it where your project files are there!
7)and then include it in your HTML link tag or import it in your CSS file
(https://i.stack.imgur.com/NvJ60.jpg)
(https://i.stack.imgur.com/XwK0l.jpg)
8)and then use ton family mentioned in google fonts
I followed duydb's answer to produce the python code below that automates this process.
import requests
with open("example.css", "r") as f:
text = f.read()
urls = re.findall(r'(https?://[^\)]+)', text)
for url in urls:
filename = url.split("/")[-1]
r = requests.get(url)
with open("./fonts/" + filename, "wb") as f:
f.write(r.content)
text = text.replace(url, "/fonts/" + filename)
with open("example.css", "w") as f:
f.write(text)
Hope this helps with some of the copy-paste death.
You need to download the font and reference it locally.
Download the CSS from the link you posted, then download all of the WOFF files and (if needed) convert them to TTF.
Then change the CSS from the link you posted to include the fonts locally.
From
url(http://themes.googleusercontent.com/static/fonts/opensans/v6/
DXI1ORHCpsQm3Vp6mXoaTXhCUOGz7vYGh680lGh-uXM.woff)
To
url(/path/to/font/font.woff)
Voila! There might be some more you need to do but the above is the basics. This article explains a little better.
just download the font and extract it in a folder. then link that font.
the below code worked for me properly.
body {
color: #000;
font-family:'Open Sans';
src:url(../../font/Open_Sans/OpenSans-Light.ttf);
}

Background and Fontface not showing on aspx page

I have a master template in aspx from which I create other aspx pages from and in the master template I have referenced a css style sheet. For some reason the background image that i've set on the body and the fontface that i've applied is not working anymore. It simply does not show up on any of the aspx pages created from the master template.
I can not for the life of me figure out why it's not showing. In fact, in Visual Studio the background DOES show.
Here is an image of my project directory so you can see how they are all positioned.
http://i.imgur.com/xHFOXil.png
So I have my stylesheet referenced for all the aspx pages in the base Cafe directory AND the Aspx files in the Secure folder by the simple
<link href="Styles/Coffee.css" rel="stylesheet" media="screen" />
<link href="../Styles/Coffee.css" rel="stylesheet" media="screen" />
So the style sheet has been referenced correctly as some objects do change as they are suppose to.
Here is the code in the css file : http://slexy.org/view/s2OAgP08oS
Also this is thie output of the page in both Visual Studio and the output in the browser :
http://i.imgur.com/Hsh6sLD.jpg
This was working before just fine, the labels and all text on my aspx page was displaying with the fontface etc. Background was fine in both IE and FF. Don't get what's happened now.
Okay folks, rookie mistake on my part. It was the fact that I wasn't referencing to the fontface files or the image correctly. Because I had /Fontface and /Images it was going into CSS STYLES FODLER/Images.. When in fact it was in the Images folder of the directory above.
So doing this fixes it.
#font-face {
font-family: 'MolotRegular';
src: url('../Fontface/Molot-webfont.eot');
src: url('../Fontface/Molot-webfont.eot?#iefix') format('embedded-opentype'),
url('../Fontface/Molot-webfont.woff') format('woff'),
url('../Fontface/Molot-webfont.ttf') format('truetype'),
url('../Fontface/Molot-webfont.svg#MolotRegular') format('svg');
font-weight: normal;
font-style: normal;
}
body
{
font-family: 'MolotRegular', Arial, Helvettica;
background-image: url("../Images/background.jpg");
margin-top: 0px;
}
TL:DR : Do not trust the output in Visual Studio. It's a LIE!

Resources