Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content width + some amount of px with calc()

Tags:

css

width

sass

I know i can do calc(100% + 15px), but is there way to do calc("content width" + 15px)?

fit-content and auto didn't work, which kinda makes sense.

I have unknown number of items that i want just to take width they need (inline-block) + some amount of px for justify-content: space-between;

If this can't be done with calc, is there an alternative?

(I'm using scss if that changes anything)

like image 483
Archaeologist03 Avatar asked Jan 15 '19 14:01

Archaeologist03


2 Answers

Use padding. The content+padding => determines size without using % percentage for width.

In my scenario, a button added a '>' using pseudo ::after, and was positioned 18px from the right edige.

like image 101
alturium Avatar answered Oct 20 '22 19:10

alturium


I also found myself in this situation, unfortunately not having found a solution I used a small JS function that assigns the value

width: calc ($(element).width() + 10px);

Unfortunately, rather than calculating the measure via javascript when loading the page I can not help you.

like image 32
Il_Sapo Avatar answered Oct 20 '22 20:10

Il_Sapo