dayjournal memo

Total 975 articles!!

CSS #001 – 背景に上塗り表示

Yasunori Kirimoto's avatar

CSS3で背景に上塗り表示したい場合は下記のように記述します。

index.html


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>sample</title>

    <script src="./js/leaflet-0.7.3/leaflet.js"></script>
    <link href="./js/leaflet-0.7.3/leaflet.css" rel="stylesheet" />
    <link href="./css/stylesheet.css" rel="stylesheet" />

</head>

<body>

    <div id="nuri"></div>

    <div id="map"></div>

    <script src="js/script.js"></script>

</body>

</html>

stylesheet.css


        html, body {
            height: 100%;
            padding: 0;
            margin: 0;
        }

        #map {
            z-index: 0;
            height: 100%;
        }

        #nuri {
            z-index: 1;
            bottom: 0;
            width: 100%;
            height: 100%;
            position: absolute;
            background-color: rgba(128, 128, 128,0.7);
        }

script.js


var map = L.map('map');

L.tileLayer('http://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
    attribution: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院</a>"
}).addTo(map);

map.setView([35.681382, 139.766084], 15);

index.htmlを実行すると下記のようにブラウザで表示されます。 ※「この地図は、国土地理院長の承認を得て、同院発行の電子地形図(タイル)を複製したものである。 (承認番号 平27情複、 第224号)」

CSS3_001_01


表示順序を指定したい時: 数字が大きいほど一番上に表示されます。


z-index: 1;

色と透過率を変更したい場合:


background-color: rgba(128, 128, 128,0.7);


book

Q&A