ラベル CSS の投稿を表示しています。 すべての投稿を表示
ラベル CSS の投稿を表示しています。 すべての投稿を表示

月曜日, 7月 28, 2025

HTML_CSS_19 
HTMLとCSSの組み合わせ色々

HTMLとCSSの記述組み合わせ3パターンを簡易設定で整理してみました。

■一番簡単なHTMLだけの記述
作成するデータが1ファイルだけだったら、これもアリですが、CSSを知ってしまうとめんどうに感じマスね。

<!-- index.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
</head>
<body bgcolor="midnightblue">
<table width="640" height="480" align="center">
<tr>
<td align="center" valign="middle" bgcolor="royalblue">
<H2><font color="white">
Clip art of graceful goldfish</font></H2>
<!-- 画像はindex.htmlと同じ階層にある
picフォルダー内の640×480pxサイズ -->
<img src="pic/picture.jpg" width="500" alt="金魚の画像">
</td>
</tr>
</table>
</body>
</html>
<!-- index.html -->

表示結果
実は640×480pxで指定したボックスが、なぜか636×476pxになっていました

■CSSを別途作成し手HTMLで読み込む
HTMLデータ作成の基本ですね。

/* rule.css */
@charset "UTF-8";
body {
text-align: center;
background-color: midnightblue;
}
.mainbox {
width: 640px;
height: 480px;
margin: 10px auto;
background-color: royalblue;
}
.f_sizu24 {
padding: 27px;
font-size: 24px;
font-weight: bold;
color: white;
}
/* rule.css */

<!-- index.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<!-- cssファイルを指定 -->
<link rel="stylesheet" type="text/css" href="rule.css">
</head>
<body>
<div class="mainbox">
<div class="f_sizu24">
Clip art of graceful goldfish
</div>
<!-- 画像はindex.htmlと同じ階層にある
picフォルダー内の640×480pxサイズ -->
<img src="pic/picture.jpg" width="500" alt="金魚の画像">
</div>
</body>
</html>
<!-- index.html -->


表示結果。「一番簡単なHTMLだけの記述」での表示とテキスト行間が若干異なります。

■HTML内にCSSを記述
作成するデータが1ファイルだけで、CSS記述が解れば、これもアリですね。

<!-- index.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<!-- <style>~</style>にcssを記述 -->
<style>
body {
text-align: center;
background-color: midnightblue;
}
.mainbox {
width: 640px;
height: 480px;
margin: 10px auto;
background-color: royalblue;
}
.f_sizu24 {
padding: 27px;
font-size: 24px;
font-weight: bold;
color: white;
}
</style>
</head>
<body>
<div class="mainbox">
<div class="f_sizu24">
Clip art of graceful goldfish
</div>
<!-- 画像はindex.htmlと同じ階層にある
picフォルダー内の640×480pxサイズ -->
<img src="pic/picture.jpg" width="500" alt="金魚の画像">
</div>
</body>
</html>
<!-- index.html -->
 
表示結果。「CSSを別途作成してHTMLで読み込む」と全く同じです。

月曜日, 7月 07, 2025

HTML_CSS_18 
HTMLでフォントサイズの設定比較


HTMLで3つのフォントサイズの設定を比較してみました。

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
<title>フォントサイズ指定</title>
<style>
body {
background-color: lemonchiffon;
}
.f_sizu16 {
font-size: 16px;
}
.mainbox {
width: 350px;
height: 300px;
margin: 0px auto;
margin-top: 50px;
}
</style>
</head>
<body>
<div class="mainbox">
<div class="f_sizu16">
このフォントサイズは16px指定です</div>
<p>このフォントサイズはP指定です</p>
<h4>このフォントサイズはH4指定です</h4>
<br>
<div class="f_sizu16"><b>
このフォントサイズは16px指定Boldです</b></div>
<p><b>このフォントサイズはP指定Boldです</b></p>
<h4>このフォントサイズはH4指定です</h4>
</div>
</body>
</html>


上は処理結果です。<P>と<;H4>は16ptと同等です。ただし、<;H4>は太字になるので、16ptと<P>はBold指定すると<;H4>と同じに見えます。

土曜日, 5月 31, 2025

HTML_CSS_17 
HTMLでマウスオーバーでイメージ表示

いわゆるロールオーバーの逆ですね。
表示用のイラストは・・・
pic/fish.pngに保存しています。

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
<title>マウスオーバーでイメージ表示</title>
<style>
body {
background-color: aqua;
}
.box {
width: 600px;
height: 200px;
opacity: 0.0;
}
.box {
width: 300px;
height: 300px;
opacity: 0.0;
transition: opacity 0.3s ease-in-out;
}
.box:hover {
opacity: 1;
}
</style>
</head>
<body>
<center>
<h2>マウスオーバーでイメージ表示</h2>
<div class="box">
<img src="pic/fish.png" width=300px height="300px">
</div>
</center>
</body>
</html>

表示直後の状態

マウスを近づけるとイラスト後表示されます。

日曜日, 3月 30, 2025

HTML_CSS_16 
HTMLでテキストの色々なカーニング設定

HTMLでテキストの色々なカーニング設定を整理してみました。

HTMLでのカーニング適用

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>カーニング設定</title>
<style>
body {
background-color: lemonchiffon;
font-family:'MS P明朝', 'MS 明朝';
font-size: 14pt;
font-weight: 700;
}
.kerning-wide {
letter-spacing: 2px; /* 文字間を広げる */
}
.kerning-tight {
letter-spacing: -1px; /* 文字間を狭める */
}
</style>
</head>
<body>
<p>HTML上のテキストカーニングについて(無設定)</p>
<p class="kerning-wide">
HTML上のテキストカーニングについて(広げる)</p>
<p class="kerning-tight">
HTML上のテキストカーニングについて(狭める)</p>
</body>
</html>

HTMLでのカーニング適用の実行結果
(MS P明朝)

ブラウザの自動カーニング適用(Chromeで実行)

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>カーニング設定</title>
<style>
body {
background-color: lemonchiffon;
font-family:'MS P明朝', 'MS 明朝';
font-size: 14pt;
font-weight: 700;
}
p {
font-kerning: normal; /* ブラウザの自動カーニング */
/* auto ブラウザのデフォルト
                (フォントにカーニング情報があれば適用)
normal 可能ならカーニングを適用
none カーニングを無効化
*/
}
</style>
</head>
<body>
<p>HTML上のテキストカーニングについて
        (ブラウザの自動カーニング)</p>
</body>
</html>

ブラウザの自動カーニング適用の実行結果
(MS P明朝)

OpenTypeのカーニング適用

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>カーニング設定</title>
<style>
body {
background-color: lemonchiffon;
font-family:'MS P明朝', 'MS 明朝';
font-size: 14pt;
font-weight: 700;
}
p {
font-feature-settings: "kern";
            /* OpenTypeのカーニング適用 */
}
</style>
</head>
<body>
<p>HTML上のテキストカーニングについて
        (OpenTypeのカーニング適用)</p>
</body>
</html>

OpenTypeのカーニング適用の実行結果
(MS P明朝)

月曜日, 3月 24, 2025

HTML_CSS_15 
WebFontのGoogleFontをHTMLで記述手順

WebFontであるGoogleFontをHTMLで記述する手順を整理しました。便宜上CSSはHTML内に埋め込んでいます。


(1)body内のテキストを全てゴシック体に設定する場合

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Google Fonts の利用</title>
<!-- Google Fonts の読み込み(例: "Noto Sans JP")-->
<link href="https://fonts.googleapis.com/css2?family=
Noto+Sans+JP:wght@400;700&display=swap" rel="stylesheet">

<style>
body {
background-color: lightcyan;
font-family: 'Noto Sans JP', sans-serif;
}
h2 {
font-weight: 700; /* bold */
font-kerning: normal; /* 自動カーニング */
color: blueviolet;
}
p {
font-weight: 400; /* Regular */
font-kerning: normal; /* 自動カーニング */
color: green;
}
</style>
</head>
<body>
<center>
<h2>Google Fonts を使ってみる</h2>
<p>webフォントを設定すれば表示フォントを共有できます
</p>
</center>
</body>
</html>

(1)の処理結果/全てNoto Sans Japanese

(2)CSS内で&lt;H&gt;や&lt;P&gt;タグを指定する場合

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Google Fonts の利用</title>
<!-- Google Fonts の読み込み(例: "Noto Sans JP") -->
<link href="https://fonts.googleapis.com/css2?family=
Noto+Sans+JP:wght@400;700&family=
Noto+Serif+JP:wght@400;700&display=swap" rel="stylesheet">

<style>
body {
background-color: lightcyan;
font-family: 'Noto Ssans JP', sans-serif; /* デフォルト */
}
h2 {
font-family: 'Noto Serif JP', serif;
font-weight: 700; /* bold */
font-kerning: normal; /* 自動カーニング */
color: blueviolet;
}
p {
font-family: 'Noto Sans JP', sans-serif;
font-weight: 400; /* Regular */
font-kerning: normal; /* 自動カーニング */
color: green;
}
</style>
</head>
<body>
<center>
<h2>Google Fonts を使ってみる</h2>
<p>webフォントを設定すれば表示フォントを共有できます
</p>
</center>
</body>
</html>

(2)の処理結果/上はNoto Serif Japanese、下はNoto Sans Japanese

(3)body内で&lt;H&gt;や&lt;P&gt;タグごとに指定する場合

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Google Fonts の利用</title>
<!-- Google Fonts の読み込み(例: "Noto Sans JP") -->
<link href="https://fonts.googleapis.com/css2?family=
Noto+Sans+JP:wght@400;700&family=
Noto+Serif+JP:wght@400;700&display=swap" rel="stylesheet">

<style>
body {
background-color: lightcyan;
font-family: 'Noto Ssans JP', sans-serif; /* デフォルト */
}
h2 {
font-weight: 700; /* bold */
font-kerning: normal; /* 自動カーニング */
color: blueviolet;
}
p {
font-weight: 400; /* Regular */
font-kerning: normal; /* 自動カーニング */
color: green;
}
</style>
</head>
<body>
<center>
<h2 style="font-family: 'Noto Serif JP', serif;">
Google Fonts を使ってみる</h2>
<p style="font-family: 'Noto Sans JP', sans-serif;">
webフォントを設定すれば表示フォントを共有できます
</p>
</center>
</body>
</html>

(3)の処理結果/上はNoto Serif Japanese、下はNoto Sans Japanese

土曜日, 7月 20, 2024

HTMLとCSSの様々な表現 12 
HTMLとCSSだけでテキストを縦にスクロール

HTMLとCSSだけでテキストを縦にスクロールさせてみました。

<!-- index.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Text Scroll Animation</title>
<link rel="stylesheet" href="links/styles.css">
</head>
<body>
<div class="scroll-container">
<div class="scroll-text">
<center>
<p><b>THE PEACH BOY</b><br>
<br>
Once upon a time, a long time ago,<br>
there lived an old man and an old woman.<br>
The grandfather went to the mountains<br>
to cut grass and the grandmother went<br>
to the river to wash her clothes.<br>
While the grandmother was washing<br>
her clothes in the river,<br>
a big peach floated down.<br>
What a big peach! Let's take it home.<br>
The old woman carried the peach<br>
on her back and went to cut it open,<br>
and a big baby came out of the peach.<br>
</p>
</center>
</div>
</div>
</body>
</html>
<!-- index.html -->

 /* styles.css */

* {
margin: 0px;
padding: 0px;
}
body {
background-color: #000;
font-family: 'Arial', sans-serif;
overflow: hidden;
/* 水平スクロールバーを隠す */
}
.scroll-container {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
/* コンテナを水平に中央揃えする */
width: 80%;
max-width: 500px;
/* 必要に応じてコンテナの幅を調整する */
}
.scroll-text {
position: relative;
overflow: hidden;
height: 600px;
/* 必要に応じてコンテナの高さを調節する */
}
.scroll-text p {
position: absolute;
margin: 0;
padding: 20px;
color: #fff;
font-size: 24px;
line-height: 40px;
animation: scroll-up 30s linear infinite;
/* 要に応じてアニメーションの時間を調整する */
}
@keyframes scroll-up {
0% {
transform: translateY(100%);
}
100% {
transform: translateY(-100%);
}
}
/* styles.css */

作ってみると、色々不満が出てきますが、ユニバーサルデザインの観点では動く文字は好ましくない処理なので、こんなことも出来る・・・程度で良いかも。

火曜日, 5月 28, 2024

HTMLとCSSの様々な表現 11 
HTMLとCSSだけでプルダウンでページを切り替える

プルダウンでページを切り替える流れをHTMLとCSSだけで整理してみました。今回は前回のJavaScript仕様版をベースにイラストで選択するインターフェースを整理しました。

前回の内容

page_01.html〜page_03.htmlは前回と全く同じです。

<!-- index.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Dropdown Menu Redirect</title>
<style>
/* スタイル(css)設定 */
* {
margin: 0px;
padding: 0px;
}
div#mainbox {
width: 100px;
height: 50px;
margin: 50px auto;
text-align: center;
background-color: forestgreen;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: aquamarine;
min-width: 100px;
z-index: 1;
}
.dropdown-content img {
width: 100%;
height: auto;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body bgcolor="aquamarine">
<div id="mainbox">
<div class="dropdown">
<img src="links/menu.png" alt="fish picture menu">
<div class="dropdown-content">
<img src="links/fish_01s.png" alt="fish 01 picture"
onclick="redirectToPage('page_01.html')">
<img src="links/fish_02s.png" alt="fish 02 picture"
onclick="redirectToPage('page_02.html')">
<img src="links/fish_03s.png" alt="fish 03 picture"
onclick="redirectToPage('page_03.html')">
<!--
.dropdownクラスが親要素で画像とプルダウンメニューを含む。
.dropdown-contentクラスはプルダウンメニューのコンテンツを表し、
デフォルトでは非表示だが.dropdown要素にマウスを重ねると、
プルダウンメニューが表示される
-->
</div>
</div>
<script>
function redirectToPage(url) {
window.location.href = url;
}
</script>
</body>
</html>
<!-- index.html -->
 
<!-- page_01.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Blue Fish Image</title>
<style>
* {
margin: 0px;
padding: 0px;
}
a:link {
color: white;
}
a:visited {
color: white;
}
div#mainbox {
width: 800px;
height: 600px;
margin: 0px auto;
}
</style>
</head>
<body bgcolor="crimson">
<div id="mainbox">
<div class="container">
<img src="links/fish_01.png" alt="Blue Fish Image">
<a href="index.html">Go to Top Page</a>
</div>
</div>
</body>
</html>
<!-- page_01.html -->

<!-- page_02.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Yellow Fish Image</title>
<style>
* {
margin: 0px;
padding: 0px;
}
a:link {
color: white;
}
a:visited {
color: white;
}
div#mainbox {
width: 800px;
height: 600px;
margin: 0px auto;
}
</style>
</head>
<body bgcolor="mediumblue">
<div id="mainbox">
<div class="container">
<img src="links/fish_02.png" alt="Yellow Fish Image">
<a href="index.html">Go to Top Page</a>
</div>
</div>
</body>
</html>
<!-- page_02.html -->

<!-- page_03.html -->
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Green Fish Image</title>
<style>
* {
margin: 0px;
padding: 0px;
}
a:link {
color: white;
}
a:visited {
color: white;
}
div#mainbox {
width: 800px;
height: 600px;
margin: 0px auto;
}
</style>
</head>
<body bgcolor="darkorange">
<div id="mainbox">
<div class="container">
<img src="links/fish_03.png" alt="Green Fish Image">
<a href="index.html">Go to Top Page</a>
</div>
</div>
</body>
</html>
<!-- page_03.html -->

トップページ
[SELECT FISH]をクリックするとイラスト一覧が表示されます。

Blue Fish Page

Yellow Fish Page

Green Fish Page