CSSで特定のハイパーリンクの色を変えたい

このQ&Aのポイント
  • CSSを使用して、特定のハイパーリンクの色を変更する方法について教えてください。
  • デフォルトでは、リンクにはカラーコード#27595aが適用されています。しかし、IDが「Title」のハイパーリンクだけを白色にしたい場合、どのようにCSSを書けばよいでしょうか?
  • 試しにいくつかの方法を試しましたが、うまくいきませんでした。ご教授いただけると幸いです。
回答を見る
  • ベストアンサー

css で一部のハイパーリンクの色を変えたい

デフォルトでは 27595a というカラーで各リンクに対してハイパーリンクを貼り、Title という ID 内のみハイパーリンクに触れた時やハイパーリンクそのものの色を白にしたい場合、どのように css を書けばいいいですか? 色々やってみたのですが、うまくいきません。 ご教授よろしくお願い致します。 <style type+"text/css"> a:link { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } a:visited { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } a:active { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } a:hover { text-decoration: none; color: #27595a; font-family: "Tahoma","メイリオ","Meiryo","Courier New"; } </style> <div id="Title"><a href="./" target="_top">Toppage</a></div>

  • Boos_
  • お礼率42% (16/38)
  • HTML
  • 回答数2
  • ありがとう数2

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

  • ベストアンサー
noname#119508
noname#119508
回答No.2

質問をよく見てませんでした。すみません。 <style type="text/css"> <!-- #Title a:link { text-decoration: none; color: #ffffff; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } #Title a:visited { text-decoration: none; color: #ffffff; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } #Title a:active { text-decoration: none; color: #ffffff; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } #Title a:hover { text-decoration: none; color: #ffffff; font-family: "Tahoma","メイリオ","Meiryo","Courier New"; } a:link { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } a:visited { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } a:active { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } a:hover { text-decoration: none; color: #27595a; font-family: "Tahoma","メイリオ","Meiryo","Courier New"; } --> </style> で良いですかね。

Boos_
質問者

お礼

ベストアンサーでした。 どうもありがとうございました。

その他の回答 (1)

noname#119508
noname#119508
回答No.1

僕はこんな感じに書きますね。 ========================== スタイルシートソース ========================== <style type="text/css"> <!-- #Title a:link { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } #Title a:visited { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } #Title a:active { text-decoration: none; color: #27595a; font-family: "メイリオ","Meiryo","Tahoma","Courier New"; } #Title a:hover { text-decoration: none; color: #27595a; font-family: "Tahoma","メイリオ","Meiryo","Courier New"; } --> </style> ================================== <div id="Title"><a href="./" target="_top">Toppage</a></div> ================================== 変更点 :<style type+"text/css">から<style type="text/css">にした :TitleのIDだけにリンクの色などを適用するようにした :<style type="text/css">のあとに『<!--』を入れた :</style>の前に『-->』を入れた。 などです。

Boos_
質問者

お礼

style type+ のところは style type= と書いたつもりでしたが、記述ミスです。 #Title a:link #Title a:visited #Title a:active #Title a:hover の指定で実現できました。 どうもありがとうございました。

関連するQ&A

  • ページ毎に位置が変わってしまう。HTML

    サイト見ていただければ一目瞭然なのですが、メニューの行の下の余白部分がindex.htmlとそれ以外で違ってしまいます。 HTML構文はコピペしているので同じはずなのですが、素人同然の私としては限界です。 どなたかご教示お願い致します。 URLは http://frecklejp.com/ です。それではお願いします。 また、外部CSSファイル一応作っています。それは以下になります。 ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー @charset "utf-8"; /* CSS Document */ /*====================================== すべて =======================================*/ body,td,th,Table_01 { font-family: Verdana, Tahoma, Arial, sans-serif, Meiryo UI; color: #666666; font-size:medium; } body { background-color: #FFFFFF; margin-left: 50px; margin-top: 100px; margin-right: 0px; margin-bottom: 0px; } /*====================================== リンク =======================================*/ a:link { color: #a9a9a9; text-decoration: none; } a:visited {     color: #a9a9a9;     text-decoration: none; } a:hover { text-decoration: underline; color: navy;  text-decoration: none; } a:active { text-decoration: none; color: navy; text-decoration: none; } /*====================================== ベース =======================================*/ メイン =======================================*/ t { line-height: 15px; margin-left: 30px } ui { list-style-type: square; } span-class { font-size: x-small; text-align: right } .div-class { border-width: 0px 0px 0px 10px; border-left-width: 5px; border-left-style: solid; border-left-color: firebrick; padding: 0px 0px 0px 6px; /* 余白の幅 */ } prof { font-family: Verdana, Tahoma, Arial, sans-serif, Meiryo UI; color: #666666; font-size:medium; }

  • HTML、CSSについて分からないことがあります

    下記の2パターンのコードを書きました。 一番目のコードのように、CSSファイルでdivの中に、text-decoration: noneと書いたのですが、うまく実行されませんでした。しかし2番目のCSSファイルのように、<a>で指定するとうまくできました。 質問ですが、 (1)<a>で区切らずに、<div>ではできないのでしょうか? ーーーーーーーーーーーーーーーーーーCSS----------------- img { display: block; height: 100px; width: 300px; margin: auto; } p { text-align: center; font-family: Garamond, serif; font-size: 18px; } /*Start adding your CSS below!*/ div{ height: 50px; width: 120px; border-color: #6495ED; background-color: #BCD2EE; border-radius: 5px; margin:auto; text-align:center; text-decoration: none; color: red; } div { height: 20px; width: 200px; border-color:#6495ED; background-color: #BCD2EE; border-radius:5px; margin: auto; text-align:center; } a { text-decoration:none; font-family:Arial; display: block; } span{ color: red; } ーーーーーーーーーーーーーーーーーーCSS----------------- img { display: block; height: 100px; width: 300px; margin: auto; } p { text-align: center; font-family: Garamond, serif; font-size: 18px; } /*Start adding your CSS below!*/ div{ height: 50px; width: 120px; border-color: #6495ED; background-color: #BCD2EE; border-radius: 5px; margin:auto; text-align:center; text-decoration: none; color: red; } div { height: 20px; width: 200px; border-color:#6495ED; background-color: #BCD2EE; border-radius:5px; margin: auto; text-align:center; text-decoration:none; font-family:Arial; display: block; } span{ color: red; } ーーーーーーーーーーーーーーーーーーHTML---------------- <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> <title>About Me</title> </head> <body> <img src="http://s3.amazonaws.com/codecademy-blog/assets/46838757.png"/> <p>We're Codecademy! We're here to help you learn to code.</p><br/><br/> <div> <a href="https://facebook.com">Join us<span>Facebook<span> </a> </div> </body> </html>

  • HTML、CSSについて分からないことがあります

    下記の2パターンのコードを書きました。 一番目のコードのように、CSSファイルでdivの中に、text-decoration: noneと書いたのですが、うまく実行されませんでした。しかし2番目のCSSファイルのように、<a>で指定するとうまくできました。 質問ですが、 (1)<a>で区切らずに、<div>ではできないのでしょうか? ーーーーーーーーーーーーーーーーーーCSS----------------- img { display: block; height: 100px; width: 300px; margin: auto; } p { text-align: center; font-family: Garamond, serif; font-size: 18px; } /*Start adding your CSS below!*/ div{ height: 50px; width: 120px; border-color: #6495ED; background-color: #BCD2EE; border-radius: 5px; margin:auto; text-align:center; text-decoration: none; color: red; } div { height: 20px; width: 200px; border-color:#6495ED; background-color: #BCD2EE; border-radius:5px; margin: auto; text-align:center; } a { text-decoration:none; font-family:Arial; display: block; } span{ color: red; } ーーーーーーーーーーーーーーーーーーCSS----------------- img { display: block; height: 100px; width: 300px; margin: auto; } p { text-align: center; font-family: Garamond, serif; font-size: 18px; } /*Start adding your CSS below!*/ div{ height: 50px; width: 120px; border-color: #6495ED; background-color: #BCD2EE; border-radius: 5px; margin:auto; text-align:center; text-decoration: none; color: red; } div { height: 20px; width: 200px; border-color:#6495ED; background-color: #BCD2EE; border-radius:5px; margin: auto; text-align:center; text-decoration:none; font-family:Arial; display: block; } span{ color: red; } ーーーーーーーーーーーーーーーーーーHTML---------------- <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> <title>About Me</title> </head> <body> <img src="http://s3.amazonaws.com/codecademy-blog/assets/46838757.png"/> <p>We're Codecademy! We're here to help you learn to code.</p><br/><br/> <div> <a href="https://facebook.com">Join us<span>Facebook<span> </a> </div> </body> </html>

    • ベストアンサー
    • CSS
  • livedoorblog css フォント

    cssの一部不適応についての対策を教えて下さい。 初めに申しておきますとかなりの素人です。 cssをみて、body….font….とは?どこ?と試しに変更してみてなんとかやっている状態です。 表題にあるとおりlivedoorにてblogをしており、この度ブログ内の全フォントをメイリオに変更致しましたが記事の本文のみ反映されません。 他のブログ名・記事名・サイドバー・ページ数・次へ・コメント等には反映致しました。 やったことといえばcssから”font-family”を探し出し、すべての頭にmeiryo,"メイリオ"を追加しました。 追加した部分は body { line-height: 1.3; background: #fff; color: #333333; font-size: 80%;/*サイドバー?全体?*/ font-family: meiryo,"メイリオ","Arial","Hiragino Kaku Gothic Pro","ヒラギノ角ゴ Pro W3","MS Pゴシック",sans-serif; } h1,h2,h3,h4,h5,h6 { font-family: "meiryo","メイリオ", "Hiragino Mincho Pro","ヒラギノ明朝 Pro W3","ヒラギノ角ゴ Pro W3","MS P明朝",serif; } div#introductionOuter h1 a:link, div#introductionOuter h1 a:active, div#introductionOuter h1 a:visited { color: #333; font-weight: normal; font-size: 100%;/*ブログタイトル*/ font-family: "meiryo","メイリオ","Arial","Hiragino Kaku Gothic Pro", "ヒラギノ角ゴ Pro W3","MS Pゴシック",sans-serif; text-decoration: none; } div.archiveTitleOuter h2 { margin-bottom: 50px; padding: 15px 0; border-top: dotted 1px #666; border-bottom: dotted 1px #666; font-family: "meiryo","メイリオ"," Arial","Hiragino Kaku Gothic Pro","ヒラギノ角ゴ Pro W3","MS Pゴシック",sans-serif; font-weight: normal; text-align: center; } div#article-options h3 { font-family: "meiryo","メイリオ","Arial","Hiragino Kaku Gothic Pro","ヒラギノ角ゴ Pro W3","MS Pゴシック",sans-serif; font-weight: normal; } の5箇所です。 スタイルはExtensible Gallery (プレーン) CSSを使用しております。 本文はMS Pゴシックが適応されています。 過去の質問等調べたところ文字コードの指定?@charset "utf-8";をcssの最後に追加は反映せず。 body a による全体?の指定をcssの最後に追加はやってみましたが反映せず。 普段はクローム(シークレットモード)を使用しておりますが、サイドバーなどは反映されていることよりブラウザ側の設定ではないですよね?念のため設定のフォントカスタマイズよりメイリオに変更してみましたがコレも反映せず。 IEでの表示もクロームと同様。 上記が試してみたことです。 原因、対策がお解かりの方がおられましたらご教授下さい。 また、提示情報に不足があれば追加致しますので宜しくお願い致します。

  • CSSで表示が異なってしまう

    下記のようなCSSを使っているのですが、リンクが入ると表示が異なってしまいます。 画像の下のようにしたいのですが、どうすればよろしいでしょうか? よろしくお願いします。 ■ CSS A:link{ color:#0095ff; text-decoration: none;} A:visited{ color:#0095ff; text-decoration: none;} A:hover{ color:#00efff; text-decoration: underline;} A:active{ color:#00efff; text-decoration: underline;} .style02{ padding:3px 0 0 6px; margin-bottom: 5px; font-size:16px; font-weight:bold; background-image:url(../_images/h_02.gif); background-repeat:repeat-x; border: 1px solid #000000; color: #000000; } ■ ソース <a class="style02" href="http://www.hogehoge.com">トップページ</a> <div class="style02">トップページ</div>

    • ベストアンサー
    • HTML
  • CSS:スタイルシートでテキストリンク

    教えてください!! 外部ファイルのスタイルシート(CSS)を使って、各ページへジャンプするテキストリンクをマウスオーバー時に太字になるように設定しています。 IE6.0では問題なく起動していますが、NS7.1,Firefox1.0では、機能していません。何か対処方法はないでしょうか? ↓私の記述は以下の通りです↓ 【外部ファイルへのリンクの記述】 <link rel="stylesheet" type="text/css" href="../menu.css" title="menu" /> 【外部ファイル内のCSSの記述】 .menu { font-family: "MS Pゴシック", Osaka; font-size: 12px; font-style: normal; line-height: 14px; color: #FFFFFF; text-decoration: none; } .menu a:link { color: #FFFFFF; text-decoration: none; } .menu a:visited { color: #FFFFFF; text-decoration: none; } .menu a:hover { color: #FFFFFF; font-weight: bold; text-decoration: none; } .menu a:active { color: #FFFFFF; font-weight: bold; text-decoration: none; }

  • 外部CSSがうまく表示されません

    下記ファイル(index.html・sld01.html・sld02.html) について相互にリンクし、外部CSSで制御したいのですが、うまくできません。 1.index.html→sld01.html(CSS反映せずdefault表示)さらにsld02.htmlへはリンク切れとなる。 2.sld01.html→sld02.htmlの場合、sld01.htmlでの文字色が a:visitedになりsld02.htmlジャンプでCSS反映せずdefault表示となりindex.htmlへはリンク切れとなります。 どなたかご教授いただけませんでしょうか? index.html <html> <head>省略 <link href="/styles-site.css/navi.css" rel="stylesheet" type="text/css"> <link href="/styles-site.css/waku.css" rel="stylesheet" type="text/css"> </head> <body> <table>省略 <div> <a href="index.html">top</a> </div> <div> <a href="../sldset/sld01.html">gallery</a> </div> </table> </body> </html> sld01.html・sld02.html(slid.01へ) <html> <head>省略 <title>gallery</title> <link href="/css/base.css" rel="stylesheet" type="text/css"> </head> <body> <TABLE> <TBODY> <TABLE> <TBODY> 省略(java) <font size="-1"> <a href="/contents/sldset/sld02.html">slid.02へ</a></font> </TBODY> </TABLE> <font size="-1"> <a href="/contents/index/index.html">元のページに戻る</a></font> </TBODY> </TABLE> </body> </html> base.css(一部省略) a:link { color: #FFCC33; text-decoration: none; } a:visited { color: #CCCCCC; text-decoration: none; } a:hover { color: #66CCFF; text-decoration: none; } a:active { color: #FF3366; text-decoration: none; }

  • CSSの質問です。1行にある「●タイトル」を別々の色にしたいです。

    CSSの質問です。1行にある「●タイトル」を別々の色にしたいです。 ●タイトル ↑ ●とタイトルを別々の色にしたいです。 現在のCSSはこうなっています。 div.post h2 {font-size: 0.87em} div.post h2 a {text-decoration: none; color:red} これをどうすれば、別々の色に指定できますか? h3を作ると改行されて、a1というタグは無理っぽいです。 CSSがわからないので、助けてください。

  • ホームページの作成(CSS)について

    「Dreamwever独習ナビCS3/8対応」でホームページの勉強をしているものです。 質問内容はプレビューで見ると、リンクの表示が想定しているものと、 違うのです。具体的にはにじんで見える感じです。文字は読めません。 CSSの設定をしたところ、この現象となりました。 プレビューのリンクの箇所を反転させると、読むことができます。 環境はWindowsXP、IE6です。firefoxでも同様の症状です。 お忙しいところお手数ですが、ご教授願います。 CSSの内容は以下のとおりです。 ------------------------------- body{ font-family: sans-serif; font-size: 75%; line-height: 1.6; color:#333333; background-color: #999999; background-image; url(image/bg.gif); background-repeat: repeat; } hr{ display: none; } aimg{ border-style: none; } a:link{ color: #333333; text-decoration: underline; } a:visited{ color: #999999; text-decoration: underline; } a:hover{ color: #000000; text-decoration: underline; } a:active{ text-decoration: none; position: relative; left: +1px; top: +1px; } ------------------------------- ※テキストP60の「リンクをCSSで設定しよう」という箇所です。

    • ベストアンサー
    • HTML
  • CSS, リンクの色を一部変えるには?

    全体にこちらを指定してまして a { text-decoration: none; color: #0099ff; } a:hover { text-decoration: none; color: pink; } 一部だけ緑色にしたいのですが .green a { text-decoration: none; color: green; } .green a:hover { text-decoration: none; color: black; } <a href="http://www.google.co.jp" class="green">Google</a> こうすると変わりません。。。 どなたかご存知でしょうか?

    • ベストアンサー
    • CSS

専門家に質問してみよう