S
S
Sergey2022-01-28 12:30:46
css
Sergey, 2022-01-28 12:30:46

How to make a label with text of unknown length in one line?

I'm trying to make a label as text. Text must be on a white background and framed. Attempts result in the div not being stretched to fit the text.
How can this be defeated?

Label output code
var myPlacemark = ymaps.templateLayoutFactory.createClass(
     `<div class="placemark_layout_container"><div class="plant_caption">{{properties.name}}</div></div>`
);

ymaps.layout.storage.add('my#simplePlacemark', myPlacemark);
 data = {
       type: "FeatureCollection",
       features: [
            {
                  type: "Feature",
                  id: "0",
                  geometry: {
                  type: "Point",
                  coordinates: [
                        55.818948,
                        37.702706
                    ]
           },
           properties: {name: 'test name'},
           options: {
                 iconLayout: 'my#simplePlacemark',
           }
      }
   ]
}
gObjectManager = new ymaps.ObjectManager({});
 gObjectManager.add(data)
map.geoObjects.add(gObjectManager);

.placemark_layout_container {              
                position: relative;             
                font-family: Georgia;             
                font-size: 40px;             
                text-align: center;             
                font-weight: bold;         
}    
.plant_caption{
       border: 2px solid #218703;             
       background-color: white;             
       color: #218703;   
}

Result:
61f3b7c158896683509925.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2022-01-28
@Prow1er

Add block with text

white-space: nowrap;
position: absolute;

https://jsfiddle.net/b5koa7dm/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question