電子書籍の厳選無料作品が豊富!

HP初心者です。
書籍通りに作ってみてのですが文字は変更されるのですが、
作った大中小の画像?までクリックするとズレてしまいます。
文字だけが変更されるのを希望してます。

↓見てやって下さい
http://www.d-judge.jp/d-judge/test.html

ソースは
HTML↓
<div id="header">
<div class="font_size">
<ul>
<li><img src="images/txt_size.gif" alt="文字サイズ" width="68" height="14" /></li>
<li><a href="javascript:void(0);" onclick="javascript:changeFsize('l')" class="textL"><span>大</span></a></li>
<li><a href="javascript:void(0);" onclick="javascript:changeFsize('m')" class="textM"><span>中</span></a></li>
<li><a href="javascript:void(0);" onclick="javascript:changeFsize('s')" class="textS"><span>小</span></a></li>
</ul>
</div>
<p>ああああああ
テストです。</p>
</div>

css↓
/* 文字サイズ
----------------------------*/
#header .font_size {
margin: 2.5em 0px 0px;
position: absolute;
left: 86px;
top: -2px;
width: 250px;
text-align: right;
height: 24px;
}
#header .font_size li {
padding: 0px 0px 0px 1em;
float: left;
list-style: none;
}
#header .font_size li img {
margin-top: 5px 0;
}
#header .font_size ul li a {
height: 24px;
width: 24px;
display: block;
}
#header .font_size ul li a span {
display: none;
}
#header .font_size ul li .textL:link,
#header .font_size ul li .textL:visited,
#header .font_size ul li .textL:active {
background-image: url(images/text_L.gif);
background-repeat: no-repeat;
background-position: left top;
}
#header .font_size ul li .textL:hover {
background-image: url(images/text_L_o.gif);
background-repeat: no-repeat;
background-position: left top;
}
#header .font_size ul li .textM:link,
#header .font_size ul li .textM:visited,
#header .font_size ul li .textM:active {
background-image: url(images/text_M.gif);
background-repeat: no-repeat;
background-position: left top;
}
#header .font_size ul li .textM:hover {
background-image: url(images/text_M_o.gif);
background-repeat: no-repeat;
background-position: left top;
}
#header .font_size ul li .textS:link,
#header .font_size ul li .textS:visited,
#header .font_size ul li .textS:active {
background-image: url(images/text_S.gif);
background-repeat: no-repeat;
background-position: left top;
}
#header .font_size ul li .textS:hover {
background-image: url(images/text_S_o.gif);
background-repeat: no-repeat;
background-position: left top;
}

javascript↓
/*フォントサイズ変更*/
function changeFsize(fontsize) {
var change = document.getElementsByTagName("body")[0];
switch(fontsize) {
case "s": var percent = "62.5%"; break;
case "m": var percent = "75%"; break;
case "l": var percent = "85%"; break;
}
change.style.fontSize = percent;
}

です。
どなたかお分かりになる方宜しくお願いしますm(_ _ )m

A 回答 (2件)

header .font_size {


margin: 2.5em 0px 0px;←ここと
(省略)
}
#header .font_size li {
padding: 0px 0px 0px 1em;←ここに
(省略)
}

"em"という相対的単位で余白が設定されているので、この部分はフォント・サイズの変更に依存してしまいますから、その変化に伴って画像の位置がずれて表示されるのは当然の結果となります。この部分の値を"0"にするか"px"による絶対値で指定すればそれらの余白自体は変更されなくなりますが、現在の設定だとサンプル部分である”<p>ああああああテストです。</p>”の方が上に表示される様になっているので、その部分の大きさが変化する事でこちらの表示部分にも影響が出ます(重なるなど)。
なので、どちらかと言えばボタン部分を上にしてそちらの領域は固定値で確保(画像だけなのでそれで支障ないでしょう)した上で、サンプル部分は下に表示される様に配置した方がいいのでは、と思います。

それからこれは質問内容とは関係ないのですが、気になった点が1つ。
コンテンツを表示した最初の状態で【大】ボタンを押すと逆に文字サイズが初期状態より小さくなってしまう様ですが…?
    • good
    • 0
この回答へのお礼

有り難うございます!!
em→pxに変更したら出来ました!!
さすがです!!全然気がつきませんでした・・・
サンプルの【大】が初期より大きくなってしまうのはbodyのサイズを決めていませんでした^^;
ですので初期の状態より【大】で決めたサイズの方が小さかったみたいです。。。
細部までお気遣い有り難うございました!
大変助かりましたーーーー(涙)

お礼日時:2008/07/26 12:20

よくわかりませんが、こういうことでしょうか?



<img src="images/txt_size.gif" alt="文字サイズ" width="68" height="14" style="position:absolute; top:130px; left:140px; " />

topとleftの値は適宜調整してください。
文字サイズを大きくしたり小さくしたりすると、時として文字と画像が重なるかも知れませんが、
文字サイズをどんなに変更しても、少なくとも、表示位置は変わらなくなります。
    • good
    • 0
この回答へのお礼

taloo様
早速の回答有難うございます!
よく分らないですよね・・・
talooさんの言うとおりやってみたのですが変化ありませんでした。。。

お礼日時:2008/07/25 12:23

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!