CSS Tips & Tricks
CSS Tips & Tricks
#captioned_image p {
text-align: center;
font-style: italic;
font-size: smaller;
text-indent: 0;
padding: 0;
}
There is one problem here, and that is that the image may be too wide. In this case, the image is 180 px wide and
the div is 28% of the surrounding text. So if you make the window narrower, it may be that the image overflows
the div (try it!).
Another way is to scale the image itself. Add the following rule:
#captioned_image img {
width: 100%;
}
Display the caption on top
#captioned_image p {
display: table-cell;
width: 100%;
}
#captioned_image p + p {
display: table-caption;
caption-side: top;
}
Image Replacement
You have the following HTML:
<div>
<span>Welcome</span>
</div>
And you want to show an image instead of showing the text "Welcome", let's say an image of the text
"Welcome" written in a fancy font face. For example:
The declaration block display:none; inside the span rule makes anything placed inside span disappear.
and I want to specify different images for different headers using image replacement technique. I
have the part of the image replacement CSS as following:
h1.imgReplace {
height:<YOU SPECIFY THE HEIGHT>;
background-repeat:no-repeat;}
h1.imgReplace span {
display:none;}
I have images home_icon.gif, demo_icon.gif, and tour_icon.gif. I want to replace the text "Home"
with home_icon.gif, and so on so forth. I need to both change my XHTML code little bit (may be
add id or class attributes to <h1> tag) and write rest of my CSS. Please help me write rest of CSS
for implementing the image replacement, and the necessary modification to current XHTML code
to implement the image replacement effect.
Think about it, why do we need image replacement. Give a few example of possible usage for
image replacement.
The following method uses the CSS text-indent property to shift contained text outside the visible element
window.
#ID_OF_ELEMENT {
text-indent: -9999px;
overflow: hidden;
}
Replace the ID_OF_ELEMENT with the id of the element you want to apply this image replacement techniuqe
for.
In the following example the first letter "N" of the word "Nature" is replaced by an image of "N" in a nice font
face and bigger font-size.
The technique we use here is the same we used for the image replacement. See the following example code:
#dropcap_n {
display:block;
float:left;
width: 62px;
height:56px;
margin-right:5px;
background-image:url("cssimages/dropcap_n.gif");
background-repeat:no-repeat;
}
#dropcap_n span {display:none;}