CSS background image for fluid layouts
I am trying to apply a background-image to a li element.
<ul>
<li class="maintablink"> </li>
</ul>
My CSS for the same is
li.maintablink{background:url(../images/tab_content.png) no-repeat left top;}
Even adding some width:200px;height:200px above does not work.
I am using HTML5 doctype
I have 2 questions related to this;
The background image is slightly bigger and does not display fully inside the li. i.e. it indirectly depends on the content inside my li element. I do not want to give any content inside li (except
) How do I fix this issue ?I am using fluid layout (everything in %, no px value)...So how do I give the width/height for this background-image...It should scale with the browser size (I know for page images, we use
i开发者_运维问答mg{max-width:100%}
)...But how do I make background-images scalable ?
It sounds like you're looking for the CSS background-size
property.
For a background that is scalable according to the size of the container:
background-size: auto;
For a background that is a fixed size, regardless of the size of the container or the actual background image:
background-size: 150px 200px;
You can also use percentages, or the keywords contain
or cover
.
See http://www.css3.info/preview/background-size/ for more info.
Please note that background-size
does have quite good browser support now, but some older browsers (in particular IE8 and earlier, but also Firefox 3.x) do not support it.
If you need to support these browsers fully, you will need to work out a fall-back solution (probably using additional markup and/or Modernizr to determine whether the feature is available).
Apply a background-image to a li element
li is not a block element so you must be change
display:inline-block
before you set width and height.
There is an option to set background-size in CSS you can follow this link,. If you don't want to show your content from li element just put the text-indent:-9999px
to you li css.
Check out this demo for testing background-size
精彩评论