Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

with css3, is is possible to have left/right padding in a span iff not empty

Tags:

html

css

have span that may or may not have text content.

is there a way to have left and right padding if and only if there is text content?

was thinking of using pseudo classes :first and :last, seeing how some css3 examples make the first character extra large for example.

will this work or is it a pipe dream?

like image 959
cc young Avatar asked Feb 24 '23 13:02

cc young


1 Answers

There is an :empty pseudo-selector that will do what you need.

span {
  padding:0 20px;
}

span:empty {
  padding:0;
}

More here - http://www.w3.org/TR/css3-selectors/#empty-pseudo

like image 92
Gary Chambers Avatar answered May 02 '23 03:05

Gary Chambers