pseudo-class


Using :before to create icon including link


How can I use content with :before to create an icon that also acts as a link to a page?
For example, I currently have:
.basketBtn a:before
{
content:url('/images/mobile/basketIcon.png');
position:absolute;
left:9px;
top:9px;
}
Now need to make the image basketIcon clickable, but this does not work:
.basketBtn a:before {
content:url('/images/mobile/basketIcon.png');
position:absolute;
left:9px;
top:9px;
}
As defined by the spec, content only generates textual content and doesn't process HTML. This makes sense, as you wouldn't want CSS to generate HTML, would you?
Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).
Use CSS for what it is made for, presentation.
However, in your specific case I don't see too much of a problem, as the ::before pseudo-element creates an element that is the first child of the parent element. This means that, if you assign the correct href to your parent anchor, also your ::before element should be perfectly clickable, whether it is absolutely positioned or not.
Working demo

Related Links

Why does sometimes the pseudo class is a:active and sometimes a.active?
Using :before to create icon including link

Categories

HOME
shell
algorithm
embedded
prism
time-complexity
telegram
jmx
pclxl
owl-carousel
javacc
aws-cli
cq5
cakephp-3.4
vsm
missing-data
odoo-8
pattern-matching
mod-security
windows-ce
project-intu
magnetic-cards
flatpak
screen-readers
dreamweaver
jmp
kendo-mobile
jquery-ias
libigl
backpack-for-laravel
parcelable
roslyn
php-mysqlidb
mongoid6
syntax-highlighting
utorrent
android-gridview
keras-layer
least-squares
xajax
lint
sql-server-ce
playframework-2.1
css-position
magento-1.9.3
stringtokenizer
portforwarding
chronicle-map
apache-directory
gitlist
geotiff
mongotemplate
corruption
pair-programming
filehandle
seq
type-theory
rmongo
redistributable
winusb
parfor
pacemaker
segment-io
windows-azure-queues
model-associations
vorpal.js
xdoclet
google-query-language
stream-processing
aurora
ikiwiki
uiactionsheet
fuzzywuzzy
fink
spring-retry
android-launcher
bufferedinputstream
shopizer
openbabel
cryptographichashfunction
variadic-templates
showdialog
cosine-similarity
execve
punycode
tweenlite
build-script
template-deduction
paste
maven-scm
xmltodict
bin
light
inputmismatchexception
dtmf
octal
traceability
chart-director
asplinkbutton
idn
xcode3.2
boost-signals
u2netdk
winmain
event-receiver
xui
cuteeditor
drupal-fivestar
binomial-heap
complex-event-processing
cldc
todos
blind
image-capture

Resources

Encrypt Message