0

I have very limited knowledge of coding, html/css, but I have a problem which makes me want to learn more. Anyway, I want to change the font-size inside a <span>, nested inside the code of the page. The complete code-snippet looks like this:

<span style="font-size: 11px;">Buy</span>

I want to change that to font-size:14px;. But, since there is no class/ID, just a <span>, I don't understand how to change it. And as I said, it's deep within the document and there are at least 20 divs or some wrapped around it.

Is there a way to target that span, and maybe get the "path". I've been fiddling with Developer Tools in Chrome but I really don't see how XPath can help me?

To sum it up - how do I overwrite inline css (without a class or ID), from an external css?

Thank you.

5 Answers 5

1

Sorry if you have already tried this but !important in your css declaration will override any css declarations

Sign up to request clarification or add additional context in comments.

Comments

1

You can declare a property as final( in my word ) as below.
Try this in external:
selector {
font-size: 14px !important;
}

Comments

0

You need to have an id to change that particular span's font size. If you change for span than it will affect all spans in the document. Or if the span has a parent element you can select that

.parent span {
font-size:14;
}

update

needs to have !important to override the inline rule.

but who uses inline rules anyways. you shouldn't.

7 Comments

It won't override inline styles!
Inline styles have priority over external styles declarations, so it won't override unless you set !important. Your jsFiddle example does not include any inline styles.
Thank you! That solved it for me! (Thanks to all of you who answered and came up with ideas suggestions!)
@btevfik: This is not the example from the question, but this is and it does not work.
I did add !important, don't know if had to but it sounds like a good idea(?).
|
0

Add a class to it and then target <span class="target">Buy</span>

Adding a "new" class wont hurt

You cannot target it without a class directly.. maybe the parent div has a class then

<div class="parent">
   <span style="font-size: 11px;">Buy</span>
</div>

.parent span{
  font-size: 18px !important;
}

You will ahve to use !important to override the inline css.. also keep in mind that this will effect all span inside a div with class of parent

Comments

0
<div style="background: red;">
    The inline styles for this div should make it red.
</div>

We can fight that with this:

div[style] {
   background: yellow !important;
}

Of course just add a class to the div before [style] to change the div with class you added. example:

div.myclass[style]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.