No, you cannot set any attributes in CSS. Attributes belong to elements; CSS deals with the rendering of elements and may use the attributes in certain ways, but not set or change them.
Consider presenting the actual problem you are facing, instead of assumed (and dead-end) approach to an unspecified problem. There are several units that you can use in setting the width property of an element, not just px. But if you are looking for a unit corresponding to the width of a character, as I suspect, then what comes closest is the ch unit (e.g., width: 40ch), but (a) it is defined as the width of the digit 0, and it’s just somewhat close to the average width of characters and (b) support isn’t universal yet.
display: flex;before grow or shrink are applied. This could be a valid reason to want this. Specifying an explicit width might not have the same effect.