?
Solved

CSS help matching specific span class

Posted on 2016-11-21
2
Medium Priority
?
73 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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 elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

771 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