CSSの書き方について

このQ&Aのポイント
  • CSSの書き方についての質問となります。
  • 具体的には、JqueryのポップアッププラグインであるPopboxを使用する際の改造方法についての質問です。
  • クリックしたボタンの表示位置をスマートフォンの表示枠の一番上にしたいという要望です。
回答を見る
  • ベストアンサー

CSSの書き方について

Jquery のポップアッププラグインであるPopboxを使おうとしています。 http://gristmill.github.io/jquery-popbox/ 実装は出来たのですが、下記の改造で戸惑っています。 ●デフォルトでは、クリックしたボタンから吹き出しの形で、ボタンより下にポップアップが表示されます。 ●当方の希望 クリックしたボタンの場所にかかわらず、スマートフォンの表示枠の一番上から表示させたいです。 CSSのどこを弄ると当方の希望の状況になるでしょうか? よろしくお願いいたします。 <style> .popbox { margin:0px auto; text-align:center; position:relative; } .collapse { position:static; } .open { background:#DDD; border:solid 1px #FFF; border-radius:5px; box-shadow: 0px 0px 5px #CCC; background:-webkit-gradient(linear,left top,left bottom,from(#f4f4f4),to(#e8e8e8)); background:-moz-linear-gradient(top,#f4f4f4,#e8e8e8); background:linear-gradient(top,#f4f4f4,#e8e8e8); padding:8px; } .box { width:280px; display:block; display:none; background:#FFF; border:solid 1px #BBBBBB; border-radius:5px; box-shadow:0px 0px 15px #999; position:absolute; } .box a.close { color:red; font-size:12px; font-family:arial; text-decoration:underline; } .arrow { width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent; border-bottom: 11px solid #FFF; position:absolute; left:1px; top:-10px; z-index:1001; } .arrow-border { width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent; border-bottom: 11px solid #BBBBBB; position:absolute; top:-12px; z-index:1000; } </style> <script type='text/javascript' charset='utf-8'> $(document).ready(function(){ $('.popbox').popbox(); }); </script> <h1>PopBox</h1> <div class='popbox'> <a class='open' href='#'> <img src='images/plus.png' style='width:14px;position:relative;'> Click Here! </a> <div class='collapse'> <div class='box'> <div class='arrow'></div> <div class='arrow-border'></div> 表示内容 </div> </div> </div>

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

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

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

absoluteを使います。absolute(絶対配置)の場合、直近のstticでない親コンテナブロックの位置が基準になります。  ⇒'display'、'position'、'float'の関係( http://momdo.s35.xrea.com/web-html-test/spec/CSS21/visuren.html#dis-pos-flo )  ⇒'display'プロパティ( http://momdo.s35.xrea.com/web-html-test/spec/CSS21/visuren.html#containing-block )

tajix14
質問者

お礼

わかりました。 ここでは記入しなかったjavascriptで制御されていたようです。 javascriptの制御を外したらキチンと表示されました。 ありがとうございました。

tajix14
質問者

補足

ありがとうございます。 position:absolute; margin-top:0px;top:0px; を .open { の下、 または .box { の下に配置しましたが、上からの距離に変化ありません。相変わらずボタンの直下に吹き出しとして表示されます。 .popbox { 直下に置いたところ、ボタンが一番上に張りつきました。 もう少しのヒントをお願いします。

関連するQ&A

  • ギザギザボーダーの向きを下向きにしたいのですが

    CSS3初心者です。宜しくお願いします。 Jagged Border http://codepen.io/SomeStuffer/details/uwstc ヘッダーとフッターに配置したいのですが、 ヘッダーでギザギザが逆にならなくて困ってます。 画像のようにしたいのですが、CSSのどの部分を変更したらよいでしょうか。 宜しくお願いします。 .jagged-border { position: relative; width: 100%; height: 50px; -webkit-filter: drop-shadow(rgba(0, 0, 0, 0.3) 0px 1px 2px); filter: drop-shadow(rgba(0, 0, 0, 0.3) 0px 1px 2px); } .jagged-border:before { content: ""; display: block; position: absolute; top: -10px; width: 100%; height: 10px; } .lightgray-bg { background: #ECF0F1; } .lightgray-bg:before { background: -webkit-linear-gradient(45deg, transparent 33.333%, #ecf0f1 33.333%, #ecf0f1 66.667%, transparent 66.667%), -webkit-linear-gradient(135deg, transparent 33.333%, #ecf0f1 33.333%, #ecf0f1 66.667%, transparent 66.667%); background: linear-gradient(45deg, transparent 33.333%, #ecf0f1 33.333%, #ecf0f1 66.667%, transparent 66.667%), linear-gradient(-45deg, transparent 33.333%, #ecf0f1 33.333%, #ecf0f1 66.667%, transparent 66.667%); -webkit-background-size: 20px 40px; background-size: 20px 40px; } .white-bg { background: #FFF; } .white-bg:before { background: -webkit-linear-gradient(45deg, transparent 33.333%, #ffffff 33.333%, #ffffff 66.667%, transparent 66.667%), -webkit-linear-gradient(135deg, transparent 33.333%, #ffffff 33.333%, #ffffff 66.667%, transparent 66.667%); background: linear-gradient(45deg, transparent 33.333%, #ffffff 33.333%, #ffffff 66.667%, transparent 66.667%), linear-gradient(-45deg, transparent 33.333%, #ffffff 33.333%, #ffffff 66.667%, transparent 66.667%); -webkit-background-size: 20px 40px; background-size: 20px 40px; } .darkgray-bg { background: #C3C9CC; } .darkgray-bg:before { background: -webkit-linear-gradient(45deg, transparent 33.333%, #c3c9cc 33.333%, #c3c9cc 66.667%, transparent 66.667%), -webkit-linear-gradient(135deg, transparent 33.333%, #c3c9cc 33.333%, #c3c9cc 66.667%, transparent 66.667%); background: linear-gradient(45deg, transparent 33.333%, #c3c9cc 33.333%, #c3c9cc 66.667%, transparent 66.667%), linear-gradient(-45deg, transparent 33.333%, #c3c9cc 33.333%, #c3c9cc 66.667%, transparent 66.667%); -webkit-background-size: 20px 40px; background-size: 20px 40px; }

    • 締切済み
    • CSS
  • クリックした際にCSSが変更できない jQuery

    jQueryについて詳しい方教えていただけませんでしょうか? クリックをした際、スライドさせるように作っているのですが、同時にspanのCSS変更(arrowFD→arrowFR)もやりたいのですがなぜかうごきません・・・ <jQuery> $(window).load(function(){ $('#faq .answer').not(':first').hide(); $('#faq .question').click(function() { if($(this).next('.answer').is(':visible')) { $(this).next('.answer').slideUp(300); $("span.arrowFD").html('<span class="arrowFR"></span>'); //★ホントは、CSSだけ変更したい } else { $(this).next('.answer').slideDown(300).siblings('.answer').slideUp(300); } }); });//]]> <CSS> .question { padding:5px; font-weight:500; font-family: メイリオ; font-size:14px; border:1px solid #ddd; background:#eee; cursor: pointer; } .answer { padding:25px; font-family:MS UI Gothic; font-weight:500; font-size:13px; border:1px solid #ddd; } /* 三角矢印を前(Front)に(右向き:Right)でつける */ .arrowFR { position:relative; top:0; left:0; padding-left:18px; } .arrowFR:before { content: ""; position: absolute; top: 3px; left: 2px; border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-left: 12px solid #000000; } /* 三角矢印を前(Front)に(下向き:Down)でつける */ .arrowFD { position:relative; top:0; left:0; padding-left:18px; } .arrowFD:before { content: ""; position: absolute; top: 3px; left: 2px; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 12px solid #000000; } <HTML> <div id="faq"> <div class="question" id="tenmetsu"> <span class="arrowFD"></span> <span style="font-weight:bold">|</span> 香川真司 </div> <div class="answer">Answer 01<br />Answer 01<br />Answer 01<br />Answer 01<br /></div> <div class="question"> <span class="arrowFR"></span> <span style="font-weight:bold">|</span>  長友佑都 </div> <div class="answer">Answer 02<br />Answer 02<br />Answer 02<br />Answer 02<br /></div> <div class="question"> <span class="arrowFR"></span> <span style="font-weight:bold">|</span> 本田圭佑 </div> <div class="answer">Answer 03<br />Answer 03<br />Answer 03<br />Answer 03<br /></div> </div>​

  • CSS 左右違う大きさのボックスでheightを合わせたい

    外部CSSでHPを作成しています。 基本的なことかと思いますが、調べてもどうしてもうまくいかないので 皆さまのお力をお貸しください。 左右にボックス(で良いのでしょうか?)を置き、その中にテキストを入れています。 それぞれ文字数が違うためheightのサイズがばらばらのため、現在指定していません。 固定すれば解決しそうですが、縦には数十個のボックスを並べているのでできません。 どのようにしたら文字数の少ないボックスを、文字数の多いボックスに合わせられるのでしょうか? また、テキストを何も入れていない状態で、左右のheightがずれているのはなぜなのでしょうか? どうぞご教授ください。 よろしくお願い致します。 /*CSSファイルの記述*/ .waku1{ border : solid 1px #999999; border-bottom: none; width :150px; float : left; background-color : #e8e8e8; line-height: 160%; } .waku2{ border : solid 1px #999999; border-left: none; border-bottom: none; width :335px; line-height: 160%; word-break: break-all; } .waku3{ border : none; border-bottom: solid #999999 1px; border-top: solid #999999 1px; width :150px; float : left; background-color : #e8e8e8; line-height: 160%; } .waku4{ border : none; border-bottom: solid #999999 1px; border-top: solid #999999 1px; border-left: none; border-bottom: none; width :335px; line-height: 160%; word-break: break-all; } .clear{ clear : left; } /*HTMLファイルの記述*/ <div class="waku1"></div> <div class="waku2"></div> <div class="clear"></div> <div class="waku1"></div> <div class="waku2"></div> <div class="clear"></div> <div class="waku1"></div> <div class="waku2"></div> <div class="clear"></div> <div class="waku3"></div> <div class="waku4"></div> <div class="clear"></div>

    • ベストアンサー
    • HTML
  • CSSが反映されなくて困っています。

    iframeを使ってhtmlファイルのdiv要素を表示しようとしていますが表示すると iframeの左端に意図しないスペースができてしまい困っています。 "IEの要素を検証"でデバッグしながら検証しているのですが、 レイアウトを見るとOffsetが60となっています。 "IEの要素を検証"を使いdiv要素のスタイルを指定しているwidthを変更すると IE上でスペースが小さくなっていくのが確認できるので、 その通りにCSSファイルの中身を書き換えるのですが、 何故か反映されず困っています。 ブラウザのキャッシュはクリアしています。 div要素のクラス以外で考えてみる必要のある項目が有るのかとも思うのですが、 何かアドバイス頂けませんでしょうか? 下記ソースです。 HTML(覗く側)-------------------------------------------------------------------- <IFRAME src="xxx/index.html" name="Topページメイン画像" width="900px" height="550px" frameborder="0" scrolling="no"> ブラウザがインラインフレームに対応していません。 表示される文章はこちらです。 </IFRAME> HTML(index.html)覗かれる側---------------------------------------------------------- <div class="fallback-message"> <img src="top2.jpg" width="900px"></img> </div> ---------------------------------------------------------------------------------- CSS------------------------------------------------------------------------------ .fallback-message { width: 818px; line-height: 0; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; font-family: sans-serif; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; border-top-color: #e4c652; border-right-color: #e4c652; border-bottom-color: #e4c652; border-left-color: #e4c652; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; background-image: none; background-attachment: scroll; background-repeat: repeat; background-position-x: 0%; background-position-y: 0%; background-color: rgb(238, 220, 148); } ---------------------------------------------------------------------------------- 何卒お願いいたします。

    • 締切済み
    • CSS
  • css3でボタンの中にアイコンを表示するには?

    css3でリンクボタンのデザインを作っています。 グラデーションや角の丸め、影の付け方はわかりました。 しかしボタンの中にアイコンを入れる方法がネットを探しても全く見つかりません。 アイコン画像を用意して、どのようにしてボタンの中に表示させればよいのでしょうか? (画像の赤い矢印で示した部分です) 作っているcssは以下のような感じです。 a{   border-top: 1px solid #57b4ff;   border-left: 1px solid #57b4ff;   border-right: 1px solid #0d78ff;   border-bottom: 1px solid #0d78ff;   -webkit-border-radius: 3px;   -moz-border-radius: 3px;   border-radius: 3px;   -webkit-box-shadow: 1px 1px 2px #a2c1dc;   -moz-box-shadow: 1px 1px 2px #a2c1dc;   background: -moz-linear-gradient(top, #fff, #ccc);   background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ccc)); } よろしくお願い致します。

    • ベストアンサー
    • CSS
  • IE9でa:hoverが効かない

    IE9でa:hoverが効かなくて困っています。 droppy.jsというJavaScriptを使ってドロップメニューにしているのが原因でしょうか? 以下ソースです。 html <div id="navi"> <div class="inner"> <ul> <li><a href="サイトトップのURL">トップ</a></li><!-- ←ここのa:hoverは正常に動作する --> <li> <a href="メニュー1のURL">メニュー1</a><!-- ←ここのa:hoverは正常に動作する --> <ul> <li><a href="メニュー1-1のURL">メニュー1-1</a></li><!-- ←ここのa:hoverが効かない --> <li><a href="メニュー1-2のURL">メニュー1-2</a></li><!-- ←ここのa:hoverが効かない --> </ul> </li> </ul> </div> </div> css #navi { background: url(naviの背景画像のURL) repeat-x left top #000000; border-bottom: 1px solid #000000; -moz-box-shadow: 0 0 3px #484848;/* Firefox用 */ -webkit-box-shadow: 0 0 3px #484848;/* Safari,Google Chrome用 */ box-shadow: 0px 0px 3px rgba(0,0,0,0.5); } #navi .inner { margin: 0 auto; width: 940px; } #navi .inner ul li { float: left; margin: 15px 0; padding: 0 10px; position: relative; } #navi .inner ul li a { padding: 5px 11px; color: #ffffff; text-decoration: none; } #navi .inner ul li a:hover { border: 1px solid #ffffff; padding: 5px 10px; color: #333333; background: #ffffff; background:linear-gradient(#eaeeee, #e2e3e3); background: -moz-linear-gradient(top, #eaeeee, #e2e3e3);/* Firefox用 */ background: -webkit-gradient(linear, left top, left bottom, from(#eaeeee), to(#e2e3e3));/* Safari,Google Chrome用 */ filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startcolorstr=#eaeeee, endcolorstr=#e2e3e3);/* IE6,7 */ -ms-filter:"progid:DXImageTransform.Microsoft.gradient(GradientType=0,startcolorstr=#eaeeee, endcolorstr=#e2e3e3)";/* IE8 */ -moz-border-radius: 5px; -webkit-border-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; behavior: url(/PIE.htc); } #navi .inner ul li ul { position: absolute; top: 39px; left: 0; zoom: 1; display: none; background: #dae4d7; border: 1px solid #8db0a0; border-top: none; border-bottom: none; font-size: 85%; width: 150px; } #navi .inner ul li ul li { float: none; padding: 0; margin: 0; background: none; } #navi .inner ul li ul li:hover { background: none; } #navi .inner ul li ul li a { color: #2d595f; text-align: left; display: block; background: url(icon画像のURL) no-repeat 5px center; border-top: 1px solid #ffffff; border-bottom: 1px solid #8db0a0; padding: 5px 5px 5px 20px; } #navi .inner ul li ul li a:hover { background: url(hoer用icon画像のURL) no-repeat 5px center #2d595f; color: #ffffff; -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; border-top: 1px solid #2d595f; border-bottom: 1px solid #2d595f; border-left: none; border-right: none; padding: 5px 5px 5px 20px; margin: 0; } どこがおかしいのかわからないのでnaviv部分全体を載せます。 宜しくお願いします。

    • ベストアンサー
    • CSS
  • cssのボタンについて(IEで背景が表示されない)

    リンク先を表示するためにcssでボタンを以下のように作製しました。 FireFoxでは正常にきちんと表示されるものの、 IE10で確認したところ、IEでは背景色が表示されませんでした。 そこでzoom: 1;などを足すなどしてみたのですが やはり表示されません。どうしたらいいのかご指南いただけませんか? どうかよろしくお願いいたします。 a.btn { position: relative; background: -moz-linear-gradient(top,#0099CC 0%,#006699); background: -webkit-gradient(linear, left top, left bottom, from(#0099CC), to(#006699)); border: 2px solid #FFF; color: #FFF; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; -moz-box-shadow: 1px 1px 1px rgba(000,000,000,0.3); -webkit-box-shadow: 1px 1px 1px rgba(000,000,000,0.3); text-shadow: 0px 0px 3px rgba(0,0,0,0.5); padding: 10px 10px; margin: 4px 2px 4px 2px; }

    • ベストアンサー
    • CSS
  • IEのレイアウト崩れについて 助けてください

    いつもお世話になっております。 実はブログを作成していて一部、IEのみ配置が違っている部分(検索フォーム部分のみ)がございました。 どのようにCSSを変更しても他ブラウザのように表示されず困っております。 そこでIEハックをして修正しようと思いました。 IE11でのハック方法が分からず、どなたかご教示頂けませんでしょうか。 また、CSSなど修正可能な方がいらっしゃいましたら助言頂けると嬉しいです。 【HTML】 <!-- コンテンツ部分 --> <div id="contents"> <a href="#" title="トップページ"><div class="btn">Home</div></a> <a href="#" title="当サイトについて"><div class="btn">about</div></a> <a href="#" title="写真・画像置き場"><div class="btn">Photo</div></a> <a href="#" title="ツイッター - Twitter -"><div class="btn">Twitter</div></a> <a href="#" title="お問い合わせ"><div class="btn">Mail</div></a> <!-- 検索フォーム --> <div class="search" align="right"> <form action="./" method="get" >サイト内検索 <input class="search_input" type="text" name="q" maxlength="200" value="<%search_word>"> <input class="search_btn" type="image" src="pngファイル(15px*14px)"> </form> </div> </div> 【CSS】 /***** ボタン部分 *****/ #contents{ width: 1200px; height: 35px; margin-bottom: 25px; } .btn{ float: left; width: 100px; height: 33px; padding-left: 20px; padding-right: 20px; border: 1px solid #15aeec; background-color: #49c0f0; background-image: -webkit-linear-gradient(top, #49c0f0, #2cafe3); background-image: linear-gradient(to bottom, #49c0f0, #2cafe3); color: #fff; -webkit-transition: none; transition: none; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); line-height: 33px; } /* マウスオーバー */ .btn:hover{ border:1px solid #1090c3; background-color: #1ab0ec; background-image: -webkit-linear-gradient(top, #1ab0ec, #1a92c2); background-image: linear-gradient(to bottom, #1ab0ec, #1a92c2); } /* クリック */ .btn:active { background: #1a92c2; box-shadow: inset 0 3px 5px rgba(0, 0, 0, .2); color: #1679a1; text-shadow: 0 1px 1px rgba(255, 255, 255, .5); } /***** 検索部分 *****/ .search{ /*float: left;*/ height: 33px; margin-left: auto; border: 1px solid #15aeec; background-color: #49c0f0; color: #fff; -webkit-transition: none; transition: none; text-shadow: 0 1px 1px rgba(0, 0, 0, .3); line-height: 33px; } .search_input{ width: 220px; padding: 5px 35px 5px 6px; border:1px solid #333; } /* 可能であれば:root .search_btnを共通で使用したいです */ :root .search_btn{ position: relative; top: 3px; left:-30px; } /* まだIE10の配置修正はしていません */ @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { .search_btn{ position: relative; top: 0px; left:-30px; } } 動きを確認したところ .search_inputのheightをデフォルトより広くとるとIEのレイアウトのみ崩れるようになりました。 何卒、ご返事よろしくお願い致します。

    • ベストアンサー
    • CSS
  • Cssで

    次のようなHTMLとCssを作成し、見出しを表示しようとしています。 1つ目の見出しと2つ目の見出しは全く違うものにしたいので、2つ目の見出しにはh2にクラス名を指定しています。 しかし2つ目の見出しは1つ目の見出しの属性を引き継いでいるようで、 border-left: 5px solid #0086b9;などは有効になり2つ目の見出しでも左側に線が表示されてしまいます。 1つ目のcssの情報を完全に消した後、2つ目の見出しを表示する方法をご教授下さい。 ▼HTML <h2>見出し2</h2> <h2 class="sample1">見出し2</h2> ■Css h2 { font-size: 145%; margin-top: 10px; margin-bottom: 10px; padding-left: 10px; border-left: 5px solid #0086b9; border-right: 1px solid #0086b9; border-top: 1px solid #0086b9; border-bottom: 1px solid #0086b9; line-height: 1.4; background-color:#F7F7EF; } h2.sample1{ border-right:solid 2px #808080; border-bottom:solid 2px #808080; background-color:#c0c0c0; padding-top:3px;padding-left:3px; width:300px; }

  • JS 正三角形から正六角形にするには

    JavScript で正三角形から正六角形にするには? 赤い円と一辺が100pxの正三角形を描きました。 青い正三角形は、頂点が円の中心にあり、2点が円周上にあります。 この時、ボタンを押したら6色の正六角形を描画します。(添付図参照) それには、どのようなコードになりますか? 正三角形の色 (反時計回り) blue -> red ->violet ->green -> orange -> lightgrey <style> .wrap3 { margin: 0 auto; position: relative; width: 200px; height: 200px; border: solid 1px red; border-radius: 50%; } .triangle3 { position: absolute; left: 50px; top: 100px; width: 0; height: 0; border-style: solid; border-right: 50px solid transparent; border-left: 50px solid transparent; border-bottom: 87px solid blue; border-top: 0; } </style> <button id="btn3">正六角形にする</button> <div class="wrap3"> <div class="triangle3"></div> </div> <script> function draw() { // ? }; btn3.onclick = draw; </script>

専門家に質問してみよう