I am newbie working on his front end skills and I am designing my own website to learn. I am trying to implement a map using the Mapbox API and I cannot get the styling of the description box I am using in the map.
The map is at the bottom. Now I have managed to place a hidden description box on the map. When a marker on the map is clicked, the hidden property is removed and when the map is clicked it is added back again.
map.css
#map {
width:100%;
height: 500px;
}
pre#description{
position: relative;
top: -100px;
left: 20px;
padding:5px 10px;
background: rgba(0,0,0,0.5);
color: #fff;
font-size: 11px;
line-height: 18px;
border-radius: 5px;
max-width: 25%;
overflow-x: hidden;
overflow-y: visible;
}
map.js
L.mapbox.accessToken = 'pk.eyJ1Ijoicm9oYW4wNzkzIiwiYSI6IjhFeGVzVzgifQ.MQBzoHJmjH19bXDW0b8nKQ';
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
.setView([30, 60])
.on('click', function(){
$("#description").addClass('hidden');
});
L.marker([28.612896, 77.177275], {
icon: L.mapbox.marker.icon({
'marker-size': 'large',
'marker-symbol': 'warehouse',
'marker-color': '#2880CA'
}),
title: 'My Location'
})
.on('click', function(){
$("#description").removeClass('hidden').empty().append('My Location');
})
.addTo(map);
L.marker([51.081482, 10.300311], {
icon: L.mapbox.marker.icon({
'marker-size': 'large',
'marker-symbol': 'circle-stroked',
'marker-color': '#74DF00'
}),
title: 'Social Accounting System'
})
.on('click', function(){
$("#description").removeClass('hidden')
.empty()
.append('Social Accounting System developed using Laravel + Bootstrap.Project includes different user roles performing a variety of operations such as transferring commodities and selling them on the market');
})
.addTo(map);
L.marker([22.281385, 114.171317], {
icon: L.mapbox.marker.icon({
'marker-size': 'large',
'marker-symbol': 'circle-stroked',
'marker-color': '#74DF00'
}),
title: 'Social Accounting System'
})
.on('click', function(){
$("#description").removeClass('hidden')
.empty()
.append('AngulAir was a demo project developed to show basic CRUD operations performed on the front end using AngularJS');
})
.addTo(map);
map.fitBounds([
[22.281385, 114.171317],
[51.081482, 10.300311]
]);
The problem is I am not very good with CSS and I am trying to position the description box on the top left of top right. I have successfully placed it on the bottom left corner but whenever the box appears, a white space also appears on the bottom of the map.
Other than this, there was a horizontal scroll on the box but I wanted a vertical scroll. So I made overflow-x: hidden
and overflow-y: visible
. The horizontal scroll is off now but I need to wrap the text to a vertical scroll.
And also I figured that I would use max-width: 25%
so that it is responsive on all view ports. Is there a better way to do this?
How to accomplish these tasks?