6

I did like so when a href's extension is .pdf; .doc; .ppt; .xls then it'll add corresponding file picture in front of it. Then I tried making a link go smaller when I hover over it but I doesn't do anything! Am I doing something wrong or what?

enter image description here

Code:

ul{
  list-style-type: none;
}
ul a{
  text-decoration:none;
  padding-left: 20px;
  background-repeat: no-repeat;
}
ul a:hover{
  text-decoration:underline;
  color:#666;
  -moz-transform: scale(0.9);
  -webkit-transform: scale(0.9);
  -ms-transform: scale(0.9);
  transform: scale(0.9);
}
a[href$=".pdf"]{
  background-image:url(https://i.sstatic.net/zJlYq.gif);
}
a[href$=".doc"]{
  background-image:url(https://i.sstatic.net/z2lbW.gif);
}
a[href$=".ppt"]{
  background-image:url(https://i.sstatic.net/Tk5Vv.gif);
}
a[href$=".xls"]{
  background-image:url(https://i.sstatic.net/sOr7E.gif);
}
<ul>
  <li><a href="/one.pdf">pdf</a></li>
  <li><a href="/two.doc">doc</a></li>
  <li><a href="/three.ppt">ppt</a></li>
  <li><a href="/four.xls">xls</a></li>
</ul>

1

3 Answers 3

12

You should use display: inline-block for <a> tag (or display: block), because <a> has display: inline by default, but transformable element can't be with display: inline:

Transformable element — an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or ...

Inline-block — this value causes an element to generate an inline-level block container. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an atomic inline-level box.

ul {
    list-style-type: none;
}

ul a {
    text-decoration: none;
    padding-left: 20px;
    background-repeat: no-repeat;
    display: inline-block;
}

ul a:hover {
    text-decoration: underline;
    color: #666;
    -webkit-transform: scale(0.9);
    -moz-transform: scale(0.9);
    -ms-transform: scale(0.9);
    transform: scale(0.9);
}

a[href $= '.pdf'] {
    background-image: url(https://i.sstatic.net/zJlYq.gif);
}

a[href $= '.doc'] {
    background-image: url(https://i.sstatic.net/z2lbW.gif);
}

a[href $= '.ppt'] {
    background-image: url(https://i.sstatic.net/Tk5Vv.gif);
}

a[href $= '.xls'] {
    background-image: url(https://i.sstatic.net/sOr7E.gif);
}
<ul>
    <li><a href="/one.pdf">pdf</a></li>
    <li><a href="/two.doc">doc</a></li>
    <li><a href="/three.ppt">ppt</a></li>
    <li><a href="/four.xls">xls</a></li>
</ul>

Sign up to request clarification or add additional context in comments.

1 Comment

Accepted, sorry i'm new to this Stack Overflow.
4

transform is not applicable to inline elements such as <a>. You could display the link as inline-block or block to get transform to work!

transformable element A transformable element is an element in one of these categories:

  • an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose display property computes to table-row, table-row-group, table-header-group, table-footer-group, table-cell, or table-caption [CSS21]

  • an element in the SVG namespace and not governed by the CSS box model which has the attributes transform, ‘patternTransform‘ or gradientTransform [SVG11].

http://www.w3.org/TR/css3-transforms/#transformable-element
http://www.w3.org/TR/css3-transforms/#transform-property

This code is working:

ul{
  list-style-type: none;
}
ul a{
  display:inline-block;
  text-decoration:none;
  padding-left: 20px;
  background-repeat: no-repeat;
}
ul a:hover{
  display:inline-block;
  text-decoration:underline;
  color:#666;
  -moz-transform: scale(0.9);
  -webkit-transform: scale(0.9);
  -ms-transform: scale(0.9);
  transform: scale(0.9);
}
a[href$=".pdf"]{
  background-image:url(http://placehold.it/20x20);
}
a[href$=".doc"]{
  background-image:url(http://placehold.it/20x20);
}
a[href$=".ppt"]{
  background-image:url(http://placehold.it/20x20);
}
a[href$=".xls"]{
  background-image:url(http://placehold.it/20x20);
}
<ul>
  <li><a href="/one.pdf">pdf</a></li>
  <li><a href="/two.doc">doc</a></li>
  <li><a href="/three.ppt">ppt</a></li>
  <li><a href="/four.xls">xls</a></li>
</ul>

Comments

1

Put display: inline-block on the link elements. You can't seem to transform inline elements. Also - your syntax should be perfectly valid, though you likely have too many prefixes. Only IE9 should need the MS prefix, I'd doubt any others would be needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.