문제

I have an article page that I am making small CSS changes, such as margin and font size, to. My code has to be able to be supported by Internet Explorer 8 and above. The problem is, I am using some CSS selectors that IE8 does not support. How do I write my CSS code without using the :not selector?

HTML for sample article page

<div class="entry">
  <h3 class="social-title>Share This Article </h3> 
  <div class="social-content>
    <table>
      <td><a href="twitter.com"><img class="" src="twitter.png"><span class="">Twitter</span></a></td>
      <td><a href="facebook.com"><img class="" src="facebook.png"><span class="">Twitter</span></a></td>
    </table>
  </div>

<!-- The article would start here -->
  <p class="category_row"><h1 class="category-title>Lifestyle</h1></p>
  <p style="margin: 0in 0in 0.0001pt; line-height: 13.5pt; vertical-align: baseline;"><a href="example.com/article.html"><img alt="" style="float: left;" src="example.jpg"></a>Article goes starts here...</p>
  <p style="margin: 0in 0in 0.0001pt; line-height: 13.5pt; vertical-align: baseline;">Second paragraph</p>
  Third paragraph
</div>

CSS I am using

.entry p:not(.category_row) {
font-size: 14px;
line-height:22px;
}

img (margin: 10px)

So far example, if I wanted to add margin to the image that is in the article section, how would I write the CSS code so that it only affects the image in the article section and not the images in the <div class="social-content">? Without using :not?

Also how would I write CSS code to change the font-size of the article to a font size of 14px and line height of 22px? Without affecting everything else above (not in the article section) ?

Sorry if this is confusing, but I will clarify more if need be!

도움이 되었습니까?

해결책

You will need to be more verbose if you want to support older browsers. The joy of the newer syntaxes is we are able to be more pithy, but if you have IE 8 in your supported list of browsers, you'll need to start with styling more general selectors and then overriding those styles in more precise selectors.

.entry p {
   font-size: 14px;
   line-height:22px;
}

.entry p.category_row {
  font-size: XXpx;
  line-height:XXpx;
}

I don't know where your article section begins from your markup. Figure out what is the most logical container for image would be, and then constrain your selector with it. Note article is an HTML5 element, so you would be remiss not to use it:

<article>
  <img ... />
</article>

And article images would be styled with this simple selector: article img { ... }

If you want to use article with IE 8, be sure to include this: https://code.google.com/p/html5shiv/

다른 팁

Why don't you wrap the actual content in it's own div?

<p class="category-row">....</p>
<div class="post-content"><!--- maybe use article tag here -->
   <p>First paragraph....</p>
   <p>Second Paragraph</p>
</div>

Then you can just reference the p's like

.entry .post-content p {
     ....
}

Also, "category row" doesn't look like it should be a paragraph? If it is a "row" a div or a span would be more appropriate. If it contains nothing but the h1 you might as well scrap it and leave the h1 be there without a wrapper.

If you use the article tag (or any of the other new html5 semantic tags) include html5shiv, as Chris said in his answer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top