Solved

CSS help matching specific span class

Posted on 2016-11-21
2
20 Views
Last Modified: 2016-11-21
Below is a code snippet that is output of a SharePoint page.  I need help selecting the <span class="ms-rteElement-btnWhite1">Want to style only this span</span> line below.   I realize I could just do "span.ms-rteElement-btnWhite1" but this formats it everywhere else it's found on the page.  Is it possible for me to just apply a style to it only when it's in the code below?

<td class="ms-cui-gallery-td ms-cui-gallery-element-sizeCustom">
	<div class="ms-cui-gallerybutton ms-cui-gallerybutton-SizeCustom ms-cui-gallerybutton-highlighted">
		<div tabindex="0" title="White Button" class="ms-cui-gallerybutton-a">
			<div class="ms-rte-stylePreview ms-rte-styleGalleryPreview">
				<div class="ms-rte-stylePreviewBox">
					<div class="ms-rte-stylePreviewBoxInner">
						<div class="ms-rte-stylePreviewHolder">
							<span style="white-space: nowrap;">
								<span class="ms-rteElement-btnWhite1">Want to style only this span</span>
							</span>
						</div>
					</div>
				</div>
				<div class="ms-rte-stylePreviewTitle ms-cui-ctl-mediumlabel">White Button</div>
			</div>
		</div>
	</div>
</td>

Open in new window


Thanks!
0
Comment
Question by:greddin
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 41896277
Depending on how detailed you want to get you can specify parent tags be included in your CSS defintion. In the most extreme case of your example above, your CSS declaration would look something like this:
td.ms-cui-gallery-td.ms-cui-gallery-element-sizeCustom > div.ms-cui-gallerybutton.ms-cui-gallerybutton-SizeCustom.ms-cui-gallerybutton-highlighted > div.ms-cui-gallerybutton-a > div.ms-rte-stylePreview > div.ms-rte-stylePreviewBox > div.ms-rte-stylePreviewBoxInner > div.ms-rte-stylePreviewHolder > span > span.ms-rteElement-btnWhite1 {
  background-color: green;
}

Open in new window

This is the most detailed selection I could come up with. It's very specific but not guaranteed to be unique. It's possible, however unlikely, that the exact hierarchy could appear elsewhere on your page.

Here's a jsfiddle proof of concept: https://jsfiddle.net/ptc1kz0s/

I had to add the <table> and <tr> tags to make it work as a <td> tag without an enclosing <table> and <tr> is not strictly valid HTML and the CSS won't match on that.
0
 

Author Closing Comment

by:greddin
ID: 41896342
As always Russ.  Thank you for your help.  Exactly what I needed to understand.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now