I have several adjacent span tags that have a display: inline-block; style display: inline-block; , eg:
span.mark { background-color: yellow; display: inline-block; vertical-align: center; border-width: 1px; border-color: red; border-style: solid; border-radius: 3px; }
<p>Some <span class="mark">standalone</span> test. Some <span class="mark">continuous </span><span class="mark">elements </span><span class="mark">that</span> should be formatted together.</p> <p>Some <span class="mark">normal </span><b><span class="mark">and strong</span></b> text that should be formatted together.</p>
So, at present, these span tags all get their own small borders. However, I want them to look like one border around them. So, technical, external ones should have border-width-left: 1px; for the first and border-width-right: 1px; for the latter, and those in the middle should have border-width: 1px 0px; .
Is there a way to do this in CSS? Basically, the rule should be: "If it is a span with a label class, and the elements before and after me are spaces between the label class, then apply the middle element style. If it is a span with a label class, and the element in front of me is not an element with a label style, and the element after me is the span element with the label style, use the style of the left element. Etc ... "
I know there is span.mark:before and span.mark:after , but I really don't want to style the element before or after the current one. I want the style of the current best for what came before and after. In addition, I need to check the element class :before and :after .
edit Maybe my example was too simplistic. The specified <p> will have more than one line of <span> tags. All :first-of-type :last-of-type looks very promising, I did not know about it. I'm afraid the solution will be harder though, if it works at all ...
source share