Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize the content property's image

Tags:

css

I have an unordered list of links and each link has a unique id.
I'm using that id with the :before selector to place
the associated website's favicon before the link (using the content property).
One of these icons is twice the size of the others.
Is there any way to change the size of this icon using CSS?
If the answer is no, is there any way to do this other than editing the image?

Visual reference:

enter image description here

Here is what I tried (and it doesn't seem to work):

#geog:before {     content: url("icons/geogebra.ico") " ";     height: 50%;     width: 50%; } 
like image 466
Honest Abe Avatar asked Aug 22 '12 23:08

Honest Abe


People also ask

How do I change the content size of an image in CSS?

We can resize the image by specifying the width and height of an image. A common solution is to use the max-width: 100%; and height: auto; so that large images do not exceed the width of their container. The max-width and max-height properties of CSS works better, but they are not supported in many browsers.

How do you resize content in CSS?

The resize property defines if (and how) an element is resizable by the user. Note: The resize property does not apply to inline elements or to block elements where overflow="visible". So, make sure that overflow is set to "scroll", "auto", or "hidden".

Which CSS properties are used to resize images?

The max-width property in CSS is used to create resize image property. The resize property will not work if width and height of image defined in the HTML. Width can also be used instead of max-width if desired. The key is to use height:auto to override any height=”…” attribute already present on the image.


2 Answers

I've run into the same problem before. Try this:

#geog:before {     display: inline-block;     width: 16px;     height: 16px;     margin-right: 5px;     content: "";     background: url("icons/geogebra.ico") no-repeat 0 0;     background-size: 100%; } 

I'm sure you'll have to tweak those values, but that worked for me. Of course, this won't work if you can't set it as a background image for some reason. Best of luck to you!

like image 165
David Vasquez Avatar answered Sep 23 '22 20:09

David Vasquez


I believe you are looking for the zoom property. Check this jsfiddle

Also you can add spacing with margin-right between the icon and the content of the element.

like image 41
Plamen Avatar answered Sep 24 '22 20:09

Plamen