My legend is too big and it is blocking the view of my map.
The size of the map is fixed, so the only solution is to make the legend smaller? Is there any way to do this?
<div class='cartodb-legend custom'style='width: auto; height: 50px'>
<ul>
<li class="bkg" style="font-size: 50%">
<div class="bullet" style="background:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728034821Decreasing%20Cases.png)"; background-size: 13px 13px !important;background-repeat: no-repeat;"></div>
Cases reported are decreasing or circulation is ongoing
</li>
<li class="bkg" style="font-size: 50%">
<div class="bullet" style="background:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728035235Rising_Cases-triangle.png)"; background-size: 13px 13px !important;background-repeat: no-repeat;"></div>
Cases reported are increasing or peaking
</li>
<li class="bkg" style="font-size: 50%">
<div class="bullet" style="background:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728034515Risk%20of%20Spreading.png)"; background-size: 13px 13px !important;background-repeat: no-repeat;"></div>
Risk of spreading
</li>
<li class="bkg" style="font-size: 50%">
<div class="bullet" style="background:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728032334Awaiting%20Confirmation.png)"; background-size: 13px 13px !important;background-repeat: no-repeat;"></div>
Awaiting Confirmation
</li>
New code:
<div.cartodb-legend.custom {
width: auto; height: 50px;
}
div.cartodb-legend.custom.bkg {
font-size: 50%;
}
div.cartodb-legend.custom ul li.bkg .bullet {
background-size: 15px 15px !important;
background-repeat: no-repeat !important;
}
<ul>
<li class="bkg" style="font-size: 80%">
<div style="background-image:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728034821Decreasing%20Cases.png)"; background-size: 15px 15px !important; background-repeat: no-repeat !important; width: 15px; height: 15px; display: inline-block; vertical-align: middle;
margin: 0 5px 0 0;"></div>
Cases reported are decreasing or circulation is ongoing
</li>
<li class="bkg" style="font-size: 80%">
<div style="background-image:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728035235Rising_Cases-triangle.png)"; background-size: 15px 15px !important; background-repeat: no-repeat !important; width: 15px; height: 15px; display: inline-block; vertical-align: middle;
margin: 0 5px 0 0;"></div>
Cases reported are increasing or peaking
</li>
<li class="bkg" style="font-size: 80%">
<div style="background-image:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728034515Risk%20of%20Spreading.png)"; background-size: 15px 15px !important; background-repeat: no-repeat !important; width: 15px; height: 15px; display: inline-block; vertical-align: middle;
margin: 0 5px 0 0;"></div>
Risk of spreading
</li>
<li class="bkg" style="font-size: 80%">
<div style="background-image:url(https://s3.amazonaws.com/com.cartodb.users-assets.production/production/sengyapglobalmomentum/assets/20160728032334Awaiting%20Confirmation.png)"; background-size: 15px 15px !important; background-repeat: no-repeat !important; width: 15px; height: 15px; display: inline-block; vertical-align: middle;
margin: 0 5px 0 0;"></div>
Awaiting Confirmation
</li>
Best Answer
In order to change the size of your legend, you can make a custom one setting the
width
andheight
CSS parameters as you wish. First, I recommend you to have a look at CSS properties here, this will help you to customize any HTML element in your CARTO maps such as legends and infowindows. If you are using CARTO.js, you only need to add this within your<style>
section:But if you are using the Editor you need to add this attributes to each element. But for the bullets it is more tricky:
But because your legend is too big, maybe a better solution could be adding/removing the legend with a couple of buttons with CARTO.js. First, get your viz.json from your map without legend and build a createVis application. Then add a couple of buttons within your
<body>
with a proper style, something like this:Finally, create two functions in order to add and remove your legend using JQuery:
Here you have a working example.