Solved

CSS help matching specific span class

Posted on 2016-11-21
2
46 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Configuring a checkbox in CSS and php 18 88
Problem to refer to value 8 50
Place text over image using CSS 6 44
Center div containing a script 6 17
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

831 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