IE9でのCSSスプライトに関する質問

このQ&Aのポイント
  • IE9でのCSSスプライトについて質問があります。
  • 表示に関する問題が発生しているか調べたところ、display属性の指定が問題なく動作することがわかりました。
  • display属性を指定しない場合、リンクの画像部分に適用されない可能性があります。
回答を見る
  • ベストアンサー

IE9でのCSSスプライト

*****html***** <div id="head"> <ul> <li id="scope1"><a href="index.html">トップ</a></li> </ul> </div> ************* *****css***** div#head ul { position:absolute; top:10px; left:10px; width:600px; height:30px; overflow:hidden; } div#head ul li { list-style-type:none; display:inline; } div#head ul li#scope1 a{ background: url('test.png') 0px 0px; width:100px; height:50px; text-indent:-9999px; display:block; position:absolute; top:0px; left:0px; } div#head ul li#scope1 a:hover { background:url('test.png') 0px -50px; } ************** 上記のような記述で、IE9で表示させたところ、もちろんうまく動作します。 ところが、「display」の部分を2ヶ所両方ともはずしても、なんら問題なく動作しています。 block属性にするのは、<a>で指定したリンクを文字部分だけでなくを画像部分全体に 適用するためだと思っていたのですが、指定しないとまずいものなのでしょうか?

  • CSS
  • 回答数1
  • ありがとう数3

質問者が選んだベストアンサー

  • ベストアンサー
  • ORUKA1951
  • ベストアンサー率45% (5062/11036)
回答No.1

無駄な書き方をするからです。  それぞれのプロパティには、値によって他の性質を持つものがたくさんあります。有名なところではfloat:です。それが指定されると無条件で新たなブロックを作ります。a要素のwidth:、height:を指定すると、それ自体が大きさを持ちます。  スタイルシートを簡潔に書きましょう。 ところで、気になったのですが、id="scope1"って何でしょう。スタイルシートで、さすがにそれに他のセレクタをつける意味と合わせて??でした。  ナビゲーションリストだと思いますが、他のaにもそれぞれidがつくのですか?  その場合は、スタイルシートではなく個別の要素で背景画像のみ追設定したほうがよいのではないかと・・

kiraristar
質問者

お礼

ありがとうございます。解決しました。 idの指定については、一考の余地がありあそうですね。

関連するQ&A

  • cssスプライト positionが効かない

    現在サイトを制作中で、グローバルナビのcssスプライトでつまずいてしまいました。 background-positionがなぜか効きません、、、、。 htmlとcssのチェックをしていただけないでしょうか?? どなたか親切なかた宜しくお願い致します!! <div id="gnav"> <ul> <li class="gnav_1"><a href="#"><img src="images/gnav_home.png" width="164" height="60" alt="ホーム" /></a></li> <li class="gnav_2"><a href="#"><img src="images/gnav_intro.png" width="164" height="60" alt="初めての方へ" /></a></li> <li class="gnav_3"><a href="#"><img src="images/gnav_staff.png" width="164" height="60" alt="スタッフ紹介" /></a></li> <li class="gnav_4"><a href="#"><img src="images/gnav_price.png" width="164" height="60" alt="料金" /></a></li> <li class="gnav_5"><a href="#"><img src="images/gnav_access.png" width="164" height="60" alt="アクセス" /></a></li> <li class="gnav_6"><a href="#"><img src="images/gnav_q&a.png" width="164" height="60" alt="よくあるご質問" /></a></li> </ul> </div><!--gnav--> --------------------------------css------------------------------ #gnav { overflow: hidden; } #gnav ul { margin: 24px 0 0 7px ; } #gnav ul li { float: left; width: 164px; height:60px; background: url(images/gnav_on.png) 0 0 no-repeat; } #gnav ul li a { display:block; } .gnav_2 { background-position: -164px 0; } .gnav_3 { background-position: -328px 0; } .gnav_4 { background-position: -492px 0; } .gnav_5 { background-position: -656px 0; } .gnav_6 { background-position: -820px 0 ; } #gnav ul li a:hover img{ visibility:hidden; }

    • ベストアンサー
    • CSS
  • IE以外のブラウザーで

    はじめまして。 ホームページの作成をDW5.5で行っています。 以下のソース、cssにてアップしたところ、header menuの部分の画像が IEだとちゃんと横並びに表示されるのですが、Firefox、Safariなどでは menuが縦に並んでしまいます。 どのように修正すればいいのか、ご指導いただけませんでしょうか? <<ソース部>> <body> <div id="header"></div> <div id="head_navi"> <ul> <li id="head_bu1"><a href="../index.html"></a></li> <li id="head_bu2"><a href="../about.html"></a></li> <li id="head_bu3"><a href="#"></a></li> <li id="head_bu4"><a href="#"></a></li> <li id="head_bu5"><a href="#"></a></li> <li id="head_bu6"><a href="../policy.html"></a></li> <li id="head_bu7"><a href="#"></a></li> <li id="head_bu8"><a href="#"></a></li> </ul></div> </body> <<css部>> *{ margin:0px; padding:0px; } img{ border:none; } li{ list-style-type:none; } body{ font-size:12px; line-height:1.4em; font-family:"MS Pゴシック", "MS PGothic", "メイリオ", Meiryo, Osaka, "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", sans-serif; background-color: #333333; margin:0px auto; } /* FireFox リンク選択時の点線を消す */ a{ overflow:hidden; outline:none; } /* FireFox flashの境界の点線を消す */ object{ outline:none; } /* ■ヘッダー */ #header{ width:1000px; height:320px; background-color: #000000; } #head_navi{ width:1000px; height: 40px; background-color: #666; } #head_navi ul{ overflow:hidden; float:left; padding-left: 21px; } #head_bu1 a{ display:block; width:112px; height:38px; float: left; background:url(../img/header_1_off.png) no-repeat left top; } #head_bu1 a:hover{ background:url(../img/header_1_on.png) no-repeat left top; } #head_bu2 a{ display:block; width:113px; height:38px; float: left; background:url(../img/header_2_off.png) no-repeat left top; } #head_bu2 a:hover{ background:url(../img/header_2_on.png) no-repeat left top; } #head_bu3 a{ display:block; width:117px; height:38px; float: left; background:url(../img/header_3_off.png) no-repeat left top; } #head_bu3 a:hover{ background:url(../img/header_3_on.png) no-repeat left top; } #head_bu4 a{ display:block; width:122px; height:38px; float: left; background:url(../img/header_4_off.png) no-repeat left top; } #head_bu4 a:hover{ background:url(../img/header_4_on.png) no-repeat left top; } #head_bu5 a{ display:block; width:101px; height:38px; float: left; background:url(../img/header_5_off.png) no-repeat left top; } #head_bu5 a:hover{ background:url(../img/header_5_on.png) no-repeat left top; } #head_bu6 a{ display:block; width:126px; height:38px; float: left; background:url(../img/header_6_off.png) no-repeat left top; } #head_bu6 a:hover{ background:url(../img/header_6_on.png) no-repeat left top; } #head_bu7 a{ display:block; width:134px; height:38px; float: left; background:url(../img/header_7_off.png) no-repeat left top; } #head_bu7 a:hover{ background:url(../img/header_7_on.png) no-repeat left top; } #head_bu8 a{ display:block; width:133px; height:38px; background:url(../img/header_8_off.png) no-repeat left top; } #head_bu8 a:hover{ background:url(../img/header_8_on.png) no-repeat left top; }

  • CSS、IE6-7で要素が消えてしまいます。

    CSS初心者です。 過去の質問や書籍、webでの検索をしつつも解決しませんでしたので、どうかお力添え下さい! お願い致します。 当方ではwebレイアウトの確認をMac OSX Firefox、Opera、Safari でおこなっています。 Windows IE については、オンラインのレンダラーでの確認です。 シンプルな構造のページのはずなのですが、以下の HTML / CSS で リストを横並びにしたナビゲーションバーが IE6、IE7で表示されません。 " absolute position dissappearing bug" ではないのでしょうか? ちなみに、画像置換で背景画像をマウスオーバーで変更するタイプのものです。 ---------------------------------------HTML(body以下) <div id="wrap" > <div class="navwrap"> <div id="nav"> <ul> <li><a href="menu1.html" class="nav-1">メニュー1</a></li> <li><a href="menu2.html" class="nav-2" >メニュー2</a></li> <li><a href="menu3.html" class="nav-3">メニュー3</a></li> </ul> </div> </div> </div> </body></html> ---------------------------------------CSS(上記部分) #wrap { height:100%; width: 100%; background:url(parts/bg.jpg) no-repeat right bottom; margin:0;} .navwrap {   width: 100%;   text-align: center;   position: absolute;   bottom: 30px;   } #nav {   position: static;   width:700px;   height: 50px;   text-align:left;   margin:0px auto;   } html > body #nav, html > body #nav ul li a { /* for Safari */height: 50px;} #nav ul { margin: 0; padding: 0; list-style: none;   } #nav ul li { float:left; width: 140px;   } #nav ul li a { display: block; color: #333; font-size: 75%; text-align: center; letter-spacing: 0.1em; text-decoration: none; text-indent: -9999px;   } #nav ul li a:hover { color: #000; background-position: bottom;   } .nav-1 {background: url(parts/nav-concept.png) top left no-repeat;} .nav-2 {background: url(parts/nav-about.png) top left no-repeat;} .nav-3 {background: url(parts/nav-collection.png) top left no-repeat;} 長くてすみませんが、詳しい方、どうかお願い致します!

    • 締切済み
    • CSS
  • CSSのロールオーバーがIEで崩れます

    CSSのロールオーバーでメニューを制作しています。 背景画像のポジションを変えて、1枚の画像でロールオーバーさせるというよくあるものです。 Mac+Safari、Firefoxではきちんと表示されるのですが、 Win+IE7だと1枚の画像がそのまま表示されてしまい、ロールオーバーになりません。 (IE7しか自宅にないので他のバージョンのIEではどうなるかわかりません。) しかもline-height: 140%;という一行を削除したら1枚べろんと表示されていたところが半分程かくれました。 ロールオーバー自体でなく、他の部分がおかしいのでしょうか? ちなみに元の画像の高さは20pxで、10pxの画像を上下につなげています。 タイトル画像が120x26で、その横に絶対配置で並べています。 ど素人が手打ちで書いた文章なのでお恥ずかしいのですが、 問題の部分のCSSとhtml、全体のCSS、を以下に載せておきますのでどうぞご教授ください。 (メニュー項目の数等一部省略しているところがあります。) よろしくお願い致します。 /*CSSの記述*/ body{ margin: 0px; text-align: center; } table,tr,td,p,ul,li,h1,h2,h3,h4,h5,h6,input,textarea { line-height; 140%; color: #696969; font-family:"MS Pゴシック", Osaka, "ヒラギノ角ゴ Pro W3"; font-size: 10pt; } div#wrapper{ width: 500px; margin: 40px auto; text-align: left; } div#header{ width: 100%; position: relative; margin-bottom: 30px; } ul#menu{ position: absolute; left: 150px; top: 10px; width: 350px; height: 10px; } ul#menu li{ float: left; height: 10px; margin-right: 15px; } ul#menu li a{ margin: 0; padding: 0; height: 10px; display: block; text-indent: -9999px; outline: none; background-repeat: no-repeat; } ul#menu li a:link, ul#menu li a:visited{ background-position: left top; } ul#menu li a:hover, ul#menu li a:active{ background-position: left bottom; } ul#menu li#top a{ background-image: url(../img/top.gif); width: 32px; } ul#menu li#about a{ background-image: url(../img/about.gif); width: 48px; } ul#menu li#pict a{ background-image: url(../img/pict.gif); width: 37px; } /*HTMLの記述*/ <div id="wrapper"> <div id="header"> <h1><IMG SRC = "タイトル画像" ALT = "" border="0"></h1> <ul id="menu"> <li id="top"><a href="top.html">top</a></li> <li id="about"><a href="about.html">about</a></li> <li id="pict"><a href="pict.html">pict</a></li> </ul> </div>  ~略~ </div>

    • ベストアンサー
    • CSS
  • IE7で表示すると画像に隙間があきます。

    WEBサイトを作っているのですがIE7で表示すると 画像と画像の間にスペースが出来てしまいます。 他のブラウザだとスペースが出来ないのですが原因は何なんでしょうか? HTML <div id="sidebar"> <div id="sidebar-bg"> </div> <div id="image-navigation"> <div class="navi"> <ul> <li><a href="#.html" title="○○"><img src="images/○○.png" width="200" height="39" alt="○○" /></a></li> <li><a href="#.html" title="○○"><img src="images/○○.png" width="200" height="35" alt="○○" /></a></li> <li><a href="#.html" title="○○"><img src="images/○○.png" width="200" height="35" alt="○○" /></a></li> <li><a href="#.html" title="○○"><img src="images/○○.png" width="200" height="35" alt="○○" /></a></li> <li><a href="#.html" title="○○"><img src="images/○○.png" width="200" height="35" alt="○○" /></a></li> <li><a href="#.html" title="○○"><img src="images/○○.png" width="200" height="35" alt="○○" /></a></li> </ul> </div> </div> </div> CSS #sidebar{ width: 200px; float: left; } #sidebar-bg{ background-color: #FFF; filter:alpha(opacity=50); -moz-opacity: 0.5; opacity:0.5; position:absolute; left:0; top:42px; z-index:-1; width: 200px; height:100%; } ul, li { margin:0; padding:0; list-style:none; } #image-navigation ul li a { display:block; width:200px; }

    • ベストアンサー
    • HTML
  • cssについて困っています

    <html> <head> <title>Webサイト</title> <style type="text/css"> body { background-color : #FFEAEF } <!-- #example { /* 親ボックス */ width: 750px; height: 900px; background-color: #FF95E4; position: absolute; top: 50px; left: 100px; ; } #example1 { /* position: absolute; */ width: 750px; height: 300px; top: 50 px; left: 150 px; background-color: #FFAAEA } #boxL { /* ボックス左 */ width: 150px; height: 600px; background-color: #ffffff; position: absolute; top: 150px; left: 1px; } #boxR { /* ボックス右 */ width: 599px; height: 600px; background-color: #ffffff; position: absolute; top: 150px; left: 150px; } #footer { width: 748px; height: 100px; background-color: #ffffff; position: absolute; top: 750px; left: 1px; } --> </style> </head> <body> <div id="example"> <div id="example1"> <h1>テスト中</h1> </div> <div id="boxL"> ボックス左 </div> <div id="boxR"> ボックス右 </div> <div id="footer"> <strong><center>ここに必要ならタグと共に記入<BR> <a href="test2.html">top</a></strong> </div> </div> </body> </html> これを表示した時、下のピンクの部分に文字やリンクを書きたいのですがどうしたらいいですか?

  • IEの時に空白ができてしまします。

    CSSを使ってホームページ制作をしはじめたのですが、まだまだ勉強不足の為修正の仕方がわかりません。申し訳ございませんがどなたか詳しいかた教えて頂けないでしょうか。 内容はと言いますとリモートロールオーバーを設定している際にIEで#Content01 ul li#menu01~03 aの背景画像の下に空白ができてしまうのです。FireFoxでは思い通り表示できているのですが。。。 ---HTML--- <div id="Content01"> <!- コンテンツ01 -!> <ul> <li id="menu01"><a href="#"><span>あああああ</span></a></li> <li id="menu02"><a href="#"><span>いいいいい</span></a></li> <li id="menu03"><a href="#"><span>ううううう</span></a></li> </ul> </div> ---CSS--- /* コンテンツ01 */ #Content01{ position:relative; background:url(../.jpg) no-repeat right top; width:800px; height:300px; } #Content01 ul li#menu01 a{ display:block; width:200px; height:100px; background:url(../.jpg) no-repeat left top; } #Content01 ul li#menu02 a{ display:block; width:200px; height:100px; background:url(../.jpg) no-repeat left top; } #Content01 ul li#menu03 a{ display:block; width:200px; height:100px; background:url(../.jpg) no-repeat left top; } #Content01 ul li{ position:relative; margin:0px; right:40px; top:0px; } #Content01 ul li a span{ display:none; } #Content01 li{ list-style:none; } #Content01 ul li#menu01 a:hover span{ position:absolute; top:0px; right:-40px; display:block; width:600px; height:300px; text-indent:-9999px; } #Content01 ul li#menu02 a:hover span{ position:absolute; top:-100px; right:-40px; display:block; width:600px; height:300px; text-indent:-999px; } #Content01 ul li#menu03 a:hover span{ position:absolute; top:-200px; right:-40px; display:block; width:600px; height:300px; text-indent:-999px; } #Content01 ul li#menu01 a:hover span{ background:url(../.jpg) no-repeat; } #Content01 ul li#menu02 a:hover span{ background:url(../.jpg) no-repeat; } #Content01 ul li#menu03 a:hover span{ background:url(../.jpg) no-repeat; } #Content01 a:hover{ border:none; } このような記述を致しております。 色んなサイトを見ながら作りましたので不適切な箇所も多いとは思いますがどうか宜しくお願い致します。

  • IE6でナビ下に隙間ができてしまいます。

    横並びのナビの下に隙間無く内容を入れたいのですが、IE6だとナビ下に2ミリ位の隙間ができてしまいます。 いろいろ調べてIE6対策でline-height: 0・margin: 0を追加してもうまくいきません。 何が間違っているのか、ご支持お願いします。 <body> <div id="wrapper"> <div id="headnavi"> <ul> <li id="A"><a href=""><span>A</span></a></li> <li id="B"><a href=""><span>B</span></a></li> <li id="C"><a href=""><span>C</span></a></li> <li id="D"><a href=""><span>D</span></a></li> <li id="E"><a href=""><span>E</span></a></li> <li id="F"><a href=""><span>F</span></a></li> </ul> </div><!-- / #headnavi --> <div id="pro_back"> <p>○○○○○</p> </div><!-- / #pro_back --> </div><!-- / #wrapper --> </body> </html> *{ margin: 0px; padding: 0px; font-weight: normal; list-style-type:none; } body { width: 100%; font-size: 75%; font-family:"ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif; line-height: 180%; color: #333; } #wrapper { position: relative; width: 960px; margin-left:auto; margin-right:auto; } #pro_back { width: 960px; height: 623px; background-image: url(images/pro_back.gif); background-repeat: no-repeat; margin: 0; } #headnavi { width:960px; height: 33px; margin: 0; } #headnavi ul { line-height: 0; margin: 0; } #headnavi ul li a { display: block; width: 172px; text-decoration: none; height: 33px; } #headnavi ul li a span { position: absolute; width: 0; height: 0; padding: 0; overflow: hidden; } ul li#A a { position: absolute; left: 890px; top: 0px; background-repeat: no-repeat; background-position: 0 0; background-image: url(images/topbotan.gif); margin: 0; } ul li#B a { position: absolute; left: 632px; top: 0px; background-repeat: no-repeat; background-position: 0 0; background-image: url(images/link.gif); margin: 0; } ul li#C a { position: absolute; left: 474px; top: 0px; background-repeat: no-repeat; background-image: url(images/mail.gif); margin: 0; } ul li#D a { position: absolute; left: 316px; top: 0; background-repeat: no-repeat; background-image: url(images/illustration.gif); margin: 0; } ul li#E a { position: absolute; left: 158px; top: 0; background-repeat: no-repeat; background-image: url(images/designwork.gif); margin: 0; } ul li#F a { position: absolute; left: 0px; top: 0; background-position: 0 0; background-repeat: no-repeat; background-image: url(images/profile.gif); margin: 0; }

    • 締切済み
    • CSS
  • CSS アクティブタブの仕組み

    CSS アクティブタブの仕組み 閲覧ありがとうございます。説明下手ですがお付き合い宜しくお願い致します CSS勉強も兼ねて擬似フレームのサイトを作っているCSS初心者です 解らないことは本やリファレンスサイトで調べ、忘れた時の為にコメントを書きこみ少しずつですが理解しながらサイトを作っています。 現在テンプレートサイト様が配布されている http://10prs.com/material/samples/cdp/mono-vivid/index.html を参考にメニュータブごとに背景色を変え、アクティブになったタブの背景色もタブと同じ色にしようと考察してます。 タブがアクティブになった時にメニューとメイン部分の境界のボーダーが消えるのですが、この仕組みがいまいちよく解りません。 恥ずかしながらアクティブになった時にボーダーが消える部分の記述があるのがどこにあるのか発見できずにいます。 無知なのに無謀な試みと思われるでしょうが御教示頂けないでしょうか、宜しくお願い致します ■以下テンプレートのCSSを抜粋 /* 各#ID&.class */ div#PAGETOP { height: 100%; overflow: auto; } div#HEADER { position: fixed !important; position: absolute; top: 0; left: 0; width: 100%; height: 70px; color: #fff; background: #000; } ul#PAN { display: none; } div#MENU { position: fixed !important; position: absolute; top: 80px; left: 30px; width: 130px; } div#MENU h2 { display: none; } div#MENU ul { margin-top: 20px; margin-left: 0; list-style: none; position: absolute; z-index: 100; height: 100%; } div#MENU ul li a { margin: 5px 0 5px 10px; padding: 5px 0; border: 1px solid; display: block; width: 119px; color: #333; background: #f1f1f1; font-family: 'Book Antiqua', 'MS P明朝', serif; font-size: 116%; text-align: center; text-decoration: none; } div#MENU ul li a:hover { margin-left: 0 !important; width: 129px !important; } li.menu-on a, li.menu-on a:link, li.menu-on a:visited { margin-left: 0 !important; border-right: 1px solid #fff !important; width: 129px !important; background: #fff !important; } div#KIZI { margin-left: 160px; padding: 80px 50px 30px 50px; border-left: 1px solid #333; background: #fff; } ul.modori { display: none; } div#FOOTER { position: fixed !important; position: absolute; bottom: 0; left: 0; width: 100%; height: 22px; color: #fff; background: #000; } div#FOOTER h2, div#FOOTER ul.modori { display: none; } div#FOOTER ul { text-align: center; } div#FOOTER ul li { display: inline; }

    • ベストアンサー
    • HTML
  • cssのfloatで右にメニューを出す方法を勉強し

    cssのfloatで右にメニューを出す方法を勉強しています。 ヘッダの左にロゴ(クリックをするとTOPへ飛ぶ) 右にメニューを横並びで表示したいです。 _________ ■   ■■■■ ロゴ  メニュー _________ のようにしたいのです。 例えばロゴもメニューもそれぞれwidth100px heith50pxのサイズとし、 メニューにもそれぞれ違う画像を入れ、マウスオーバーで違う画像に変わるようにし、marginを10pxあけるとすると ☆★☆★css☆★☆★ /* abc */ #header ul.abc{ float:right; margin: 0 ; padding: 0 ; width: 400px; } #header ul.abc li { float:left; display: inline; } /* 01 */ #header ul.abc li.01 { width:100px; height:50px; margin:0 10 0 0; } #header ul.abc li.01 a { display: block; background: url(../img/01.jpg) no-repeat top left; } #header ul.abc li.01 a:hover { display: block; background: url(../img/01_om.jpg) no-repeat top left; /* 02 */ #header ul.abc li.02 { width:100px; height:50px; margin:0 10 0 0; } #header ul.abc li.02 a { display: block; background: url(../img/02.jpg) no-repeat top left; } #header ul.abc li.02 a:hover { display: block; background: url(../img/02_om.jpg) no-repeat top left; /* 03 */ #header ul.abc li.03 { width:100px; height:50px; margin:0 10 0 0; } #header ul.abc li.03 a { display: block; background: url(../img/03.jpg) no-repeat top left; } #header ul.abc li.03 a:hover { display: block; background: url(../img/03_om.jpg) no-repeat top left; /* 04 */ #header ul.abc li.04 { width:100px; height:50px; margin:0 0 0 0; } #header ul.abc li.04 a { display: block; background: url(../img/04.jpg) no-repeat top left; } #header ul.abc li.04 a:hover { display: block; background: url(../img/04_om.jpg) no-repeat top left; ☆★☆★html☆★☆★ <div id="header"> <div class="logo"><a href="">ロゴ</a></div> <ul class="menu"> <li class="01"><a href=""01</a></li> <li class="02"><a href="">02</a></li> <li class="03"><a href="">03</a></li> <li class="04"><a href="">04</a></li> </ul> <div class="clear"></div> </div> これは例なんですが、 この記述できると思ったのですが、うまくいかず困っています。 何か足りないのでしょうか?それともcssで何か勘違いをしているのでしょうか? お手数をおかけしますが、ご教授お願いします。

    • ベストアンサー
    • CSS

専門家に質問してみよう