Solved

CSS help matching specific span class

Posted on 2016-11-21
2
68 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

691 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