プログラミング備忘録 foo

シンプル

目的

  • 左にロゴ・住所・電話番号などの会社情報を入れ、右に各メニューを列挙したい(スマホ版は上下に配置してアコーディオンメニュー)。

実行結果

解説

  • シンプルで使いやすいフッターメニューです。
  • 右側のメニュー数を削除・追加しても横幅は自動で均等横並びになります。

HTML

<footer>
	<div class="structure_5_1">
		<div>
			<div><img src="../../image/example-logo.png" /></div>
			<div>プログラミング備忘録 foo</div>
			<div>〒123-4567<br />東京都○○区○○町<br />TEL:1234-567-890<br />FAX:1234-567-891</div>
		</div>
		<div>
			<div><span><a href="https://note-book.foo/">HOME</a></span><a href="https://note-book.foo/#news">新着情報</a><a href="https://note-book.foo/inquiry/">お問い合わせ</a></div>
			<div><span><a href="https://note-book.foo/layout/">装飾</a></span><a href="https://note-book.foo/layout/2/">見出し</a><a href="https://note-book.foo/layout/4/">テキスト+画像</a><a href="https://note-book.foo/layout/5/">画像メニュー</a><a href="https://note-book.foo/layout/3/">リスト</a><a href="https://note-book.foo/layout/6/">テーブル</a><a href="https://note-book.foo/layout/1/">均等横並び</a></div>
			<div><span><a href="https://note-book.foo/structure/">構造</a></span><a href="https://note-book.foo/structure/3/">新着情報</a><a href="https://note-book.foo/structure/1/">パンくずリスト</a><a href="https://note-book.foo/structure/5/">フッター</a><a href="https://note-book.foo/structure/2/">タブメニュー</a><a href="https://note-book.foo/structure/4/">ドロップダウンメニュー</a></div>
			<div><span><a href="https://note-book.foo/management/">管理</a></span><a href="https://note-book.foo/management/1/">.htaccess</a><a href="https://note-book.foo/management/2/">パス</a></div>
		</div>
	</div>
</footer>
<footer>
	<div class="structure_5_1">
		<div>
			<div><img src="../../image/example-logo.png" /></div>
			<div>
				<div>プログラミング備忘録 foo</div>
				<div>〒123-4567<br />東京都○○区○○町<br />TEL:1234-567-890<br />FAX:1234-567-891</div>
			</div>
		</div>
		<div>
			<div>
				<input type="checkbox" id="structure_5_1_home">
				<label for="structure_5_1_home">HOME</label>
				<div>
					<a href="https://note-book.foo/#news">新着情報</a>
					<a href="https://note-book.foo/inquiry/">お問い合わせ</a>
				</div>
			</div>
			<div>
				<input type="checkbox" id="structure_5_1_layout">
				<label for="structure_5_1_layout">装飾</label>
				<div>
					<a href="https://note-book.foo/layout/2/">見出し</a>
					<a href="https://note-book.foo/layout/4/">テキスト+画像</a>
					<a href="https://note-book.foo/layout/5/">画像メニュー</a>
					<a href="https://note-book.foo/layout/3/">リスト</a>
					<a href="https://note-book.foo/layout/6/">テーブル</a>
					<a href="https://note-book.foo/layout/1/">均等横並び</a>
				</div>
			</div>
			<div>
				<input type="checkbox" id="structure_5_1_structure">
				<label for="structure_5_1_structure">構造</label>
				<div>
					<a href="https://note-book.foo/structure/3/">新着情報</a>
					<a href="https://note-book.foo/structure/1/">パンくずリスト</a>
					<a href="https://note-book.foo/structure/5/">フッター</a>
					<a href="https://note-book.foo/structure/2/">タブメニュー</a>
					<a href="https://note-book.foo/structure/4/">ドロップダウンメニュー</a>
				</div>
			</div>
			<div>
				<input type="checkbox" id="structure_5_1_management">
				<label for="structure_5_1_management">管理</label>
				<div>
					<a href="https://note-book.foo/management/1/">.htaccess</a>
					<a href="https://note-book.foo/management/2/">パス</a>
				</div>
			</div>
		</div>
	</div>
</footer>
  • スマホ版は画面が狭いので、PC版のようにロゴとメニューを横並びにすると見にくいため縦並びにします。その際にアコーディオンメニューを使うので<input><label>を使っています。

CSS

footer {

}

.structure_5_1 {
	background-color: #F6F6F6;
	display: flex;
	width: 94%;
	padding-top: 10px;
	padding-right: 10px;
	padding-bottom: 10px;
	padding-left: 10px;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 0px;
	margin-left: auto;
}

.structure_5_1 > div:first-child {
	width: 25%;
	margin-top: 0px;
	margin-right: 10px;
	margin-bottom: 0px;
	margin-left: 0px;
}

.structure_5_1 > div:first-child > div {
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 10px;
	margin-left: 0px;
}

.structure_5_1 > div:first-child > div:nth-child(1) {
	text-align: center;
}

.structure_5_1 > div:first-child > div:nth-child(1) img {
	width: 80%;
}

.structure_5_1 > div:first-child > div:nth-child(2) {
	font-size: 12px;
	font-weight: bold;
	text-align: center;
}

.structure_5_1 > div:first-child > div:nth-child(3) {
	font-size: 12px;
	line-height: 1.7;
	text-align: right;
}

.structure_5_1 > div:last-child {
	flex-grow: 1;
	flex-shrink: 1;
	flex-basis: 0;
	display: flex;
}

.structure_5_1 > div:last-child > div {
	flex-grow: 1;
	flex-shrink: 1;
	flex-basis: 0;
	padding-top: 0px;
	padding-right: 5px;
	padding-bottom: 0px;
	padding-left: 10px;
	border-left-style: dotted;
	border-left-width: 1px;
	border-left-color: #333333;
}

.structure_5_1 > div:last-child > div:last-child {
	border-right-style: dotted;
	border-right-width: 1px;
	border-right-color: #333333;
}

.structure_5_1 > div:last-child > div span a {
	font-size: 16px;
	line-height: 1;
	font-weight: bold;
	color: #4B4B4B;
	text-decoration: underline;
	display: block;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 12px;
	padding-left: 0px;
}

.structure_5_1 > div:last-child > div a {
	font-size: 14px;
	color: #4B4B4B;
	text-decoration: none;
	display: block;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 12px;
	padding-left: 0px;
}

.structure_5_1 > div:last-child > div a:hover {
	opacity: 0.7;
}
  • 左にロゴ、右にメニューの構成です。16行目で左側メニューの横幅を25%に指定しています。余った横幅は右側でメニューが均等横並びになります。メニュー数を変更しても自動で均等横並びになるので便利です。
footer {

}

.structure_5_1 {
	display: flex;
	flex-direction: column;
	width: 100%;
	margin-top: 10px;
	margin-right: 0px;
	margin-bottom: 0px;
	margin-left: 0px;
}

.structure_5_1 > div:first-child {
	display: flex;
	align-items: center;
	width: 94%;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 10px;
	margin-left: auto;
}

.structure_5_1 > div:first-child > div:nth-child(1) {
	width: 25%;
}

.structure_5_1 > div:first-child > div:nth-child(1) img {
	width: 100%;
}

.structure_5_1 > div:first-child > div:nth-child(2) {
	flex-grow: 1;
	flex-shrink: 1;
	flex-basis: 0;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	margin-left: 15px;
}

.structure_5_1 > div:first-child > div:nth-child(2) > div:nth-child(1) {
	font-size: 16px;
	font-weight: bold;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 5px;
	margin-left: 0px;
}

.structure_5_1 > div:first-child > div:nth-child(2) > div:nth-child(2) {
	font-size: 14px;
	line-height: 1.7;
}

.structure_5_1 > div:last-child {
	display: flex;
	flex-direction: column;
	width: 100%;
}

.structure_5_1 > div:last-child > div {
	border-bottom: solid 1px #DDDDDD;
	position: relative;
}

.structure_5_1 > div:last-child > div input {
	display: none;
}

.structure_5_1 > div:last-child > div label {
	font-size: 17px;
	font-weight: bold;
	color: #4B4B4B;
	background-color: #F5F5F5;
	display: block;
	padding-top: 15px;
	padding-right: 0px;
	padding-bottom: 15px;
	padding-left: 15px;
	cursor: pointer;
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.structure_5_1 > div:last-child > div label::after {
	content: "+";
	position: absolute;
	right: 20px;
}

.structure_5_1 > div:last-child > div > div {
	background-color: #FBFBFB;
	max-height: 0;
	overflow: hidden;
	transition: max-height 0.2s ease-out;
}

.structure_5_1 > div:last-child > div > div a {
	font-size: 16px;
	color: #4B4B4B;
	display: block;
	padding-top: 10px;
	padding-right: 10px;
	padding-bottom: 10px;
	padding-left: 20px;
	text-decoration: none;
	border-top: solid 1px #F6F6F6;
}

.structure_5_1 > div:last-child > div input:checked + label + div {
	max-height: 500px;
}

.structure_5_1 > div:last-child > div input:checked + label::after {
	content: "-";
}
  • ロゴや住所などは横並びにしています。
  • スマホ版ではアコーディオンメニューを使うのでHTMLに<input><label>を使いました。そのアコーディオンメニューを開閉するための構文です。