I have a few adjacent span
tags that are styled to be display: inline-block;
like so:
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 currently these span
tags all get their own little borders. However, I want them to look like there's just one border around them all together. So, technicall, the outer ones should have border-width-left: 1px;
for the first one and border-width-right: 1px;
for the last one and the ones in the middle should have border-width: 1px 0px;
.
Is there a way to do this in CSS? Basically the rule should be: "If this is a span with a mark class and the elements before and after me are spans with a mark class then apply middle element styling. If this is a span with a mark class and the element before me is not a element with a mark style and the element after me is a span element with a mark style, apply left element styling. Etc..."
I know there is span.mark:before
and span.mark:after
, but I don't actually want to style the element before or after the current one. I want to style the current one best on what comes before and after it. Also, I need to check for the class of the :before
and :after
elements.
edit:
Maybe my example was too simplistic. There will be more than one string of <span>
tags in a given <p>
. The whole :first-of-type
:last-of-type
is looking very promising, I didn't know about those. I'm afraid the solution will be more complicated though, if it works at all...