2016-04-01 22 views
0

これが可能かどうかわかりませんが、マップ上に半透明レイヤーを追加したいと思います。次に、レイヤー上にテキストを配置します。私は次のことを試しましたが、レイヤーはマップの後ろにあるのではなく、テキストの上にあります。どうすればこの問題を回避できますか?CSS over半透明レイヤーが機能しない

/*GOOGLE MAPS*/ 
 

 
section#map { 
 
    width: 100%; 
 
    height: 250px; 
 
} 
 
/*layers*/ 
 

 
.layer { 
 
    background-color: black; 
 
    opacity: 0.5; 
 
    -khtml-opacity: 0.5; 
 
    -moz-opacity: 0.5; 
 
    /*netscape*/ 
 
    filter: alpha(opacity=50); 
 
    /*IE*/ 
 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; 
 
    /*IE 8*/ 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
}
<section id='map'> 
 
    <div class="layer"> 
 

 
    <h3 id="area">Restaurants delivering to</h3> 
 

 
    <script type="text/javascript"> 
 
     // When the window has finished loading create our google map below 
 
     google.maps.event.addDomListener(window, 'load', init); 
 

 
     function init() { 
 
     // Basic options for a simple Google Map 
 
     // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions 
 
     var mapOptions = { 
 
      // How zoomed in you want the map to start at (always required) 
 
      zoom: 11, 
 
      // The latitude and longitude to center the map (always required) 
 
      center: new google.maps.LatLng(40.6700, -73.9400), // New York 
 

 
      // How you would like to style the map. 
 
      // This is where you would paste any style found on Snazzy Maps. 
 
      styles: [{ 
 
      "featureType": "all", 
 
      "elementType": "labels", 
 
      "stylers": [{ 
 
       "visibility": "off" 
 
      }] 
 
      }, { 
 
      "featureType": "landscape", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#f3f4f4" 
 
      }] 
 
      }, { 
 
      "featureType": "landscape.man_made", 
 
      "elementType": "geometry", 
 
      "stylers": [{ 
 
       "weight": 0.9 
 
      }, { 
 
       "visibility": "off" 
 
      }] 
 
      }, { 
 
      "featureType": "poi.park", 
 
      "elementType": "geometry.fill", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#83cead" 
 
      }] 
 
      }, { 
 
      "featureType": "road", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#ffffff" 
 
      }] 
 
      }, { 
 
      "featureType": "road", 
 
      "elementType": "labels", 
 
      "stylers": [{ 
 
       "visibility": "off" 
 
      }] 
 
      }, { 
 
      "featureType": "road.highway", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#fee379" 
 
      }] 
 
      }, { 
 
      "featureType": "road.arterial", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#fee379" 
 
      }] 
 
      }, { 
 
      "featureType": "water", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#7fc8ed" 
 
      }] 
 
      }] 
 
     }; 
 

 
     // Get the HTML DOM element that will contain your map 
 
     // We are using a div with id="map" seen below in the <body> 
 
     var mapElement = document.getElementById('map'); 
 

 
     // Create the Google Map using our element and options defined above 
 
     var map = new google.maps.Map(mapElement, mapOptions); 
 

 
     // Let's also add a marker while we're at it 
 
     var marker = new google.maps.Marker({ 
 
      position: new google.maps.LatLng(40.6700, -73.9400), 
 
      map: map, 
 
      title: 'Snazzy!' 
 
     }); 
 
     } 
 
    </script> 
 

 
    <!-- FLAT DESIGN MAP --> 
 
</section> 
 
</div>

のみマップショーやブラウザに何もありません。しかし、私はそれがこのように見えるようにしたい。あなたは以下のようなあなたのメインセクションの位置を与える場合も、下図のように、単に使用レイヤーの不透明度を減らすこととは対照的に、

enter image description here

+1

は、セクション#マップのinnerHTMLプロパティが上書きされた作成されます。あなたのレイヤーをセクションの外側に置きます。# –

+0

@DimaFitiskinありがとうございます。それは – jerneva

答えて

0

は、あなたがして、上部と左の値を含む絶対あなたの層の位置を与えることができます代わりにあなたの背景色のrgba値:

**また、マップセクションからh3を移動して上に置きます。マップ後

/*GOOGLE MAPS*/ 
 

 
section#map { 
 
    width: 100%; 
 
    height: 250px; 
 
    position:relative; 
 
    margin:auto; 
 
} 
 
/*layers*/ 
 

 
.layer { 
 
    background-color: rgba(0,0,0,0.5); 
 
    position:absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 

 
h3 { 
 
width:100%; 
 
position:relative; 
 
z-index:999; 
 
}
<section id='map'> 
 
    <div class="layer"> 
 

 
    <h3 id="area">Restaurants delivering to</h3> 
 

 
    <script type="text/javascript"> 
 
     // When the window has finished loading create our google map below 
 
     google.maps.event.addDomListener(window, 'load', init); 
 

 
     function init() { 
 
     // Basic options for a simple Google Map 
 
     // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions 
 
     var mapOptions = { 
 
      // How zoomed in you want the map to start at (always required) 
 
      zoom: 11, 
 
      // The latitude and longitude to center the map (always required) 
 
      center: new google.maps.LatLng(40.6700, -73.9400), // New York 
 

 
      // How you would like to style the map. 
 
      // This is where you would paste any style found on Snazzy Maps. 
 
      styles: [{ 
 
      "featureType": "all", 
 
      "elementType": "labels", 
 
      "stylers": [{ 
 
       "visibility": "off" 
 
      }] 
 
      }, { 
 
      "featureType": "landscape", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#f3f4f4" 
 
      }] 
 
      }, { 
 
      "featureType": "landscape.man_made", 
 
      "elementType": "geometry", 
 
      "stylers": [{ 
 
       "weight": 0.9 
 
      }, { 
 
       "visibility": "off" 
 
      }] 
 
      }, { 
 
      "featureType": "poi.park", 
 
      "elementType": "geometry.fill", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#83cead" 
 
      }] 
 
      }, { 
 
      "featureType": "road", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#ffffff" 
 
      }] 
 
      }, { 
 
      "featureType": "road", 
 
      "elementType": "labels", 
 
      "stylers": [{ 
 
       "visibility": "off" 
 
      }] 
 
      }, { 
 
      "featureType": "road.highway", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#fee379" 
 
      }] 
 
      }, { 
 
      "featureType": "road.arterial", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#fee379" 
 
      }] 
 
      }, { 
 
      "featureType": "water", 
 
      "elementType": "all", 
 
      "stylers": [{ 
 
       "visibility": "on" 
 
      }, { 
 
       "color": "#7fc8ed" 
 
      }] 
 
      }] 
 
     }; 
 

 
     // Get the HTML DOM element that will contain your map 
 
     // We are using a div with id="map" seen below in the <body> 
 
     var mapElement = document.getElementById('map'); 
 

 
     // Create the Google Map using our element and options defined above 
 
     var map = new google.maps.Map(mapElement, mapOptions); 
 

 
     // Let's also add a marker while we're at it 
 
     var marker = new google.maps.Marker({ 
 
      position: new google.maps.LatLng(40.6700, -73.9400), 
 
      map: map, 
 
      title: 'Snazzy!' 
 
     }); 
 
     } 
 
    </script> 
 

 
    <!-- FLAT DESIGN MAP --> 
 
</section> 
 
</div>

+0

ありがとうございました。私のために働いていない – jerneva

関連する問題