簡體   English   中英

頂級CSS選擇器未在子元素上應用格式

[英]Top CSS selector not applying formatting on children elements

我當前使用http://meyerweb.com/eric/tools/css/reset/作為我的頂級CSS。 假設我無法更改此設置。

所以我的頂級CSS級別是這樣的:

base.css

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: 100%;
  vertical-align: baseline; 
}

div .target {
  ...
}

的index.html

  <body>
   <div class="target">
      <strong>Please make me bold</strong>
      <i>Please make me italic</i>
   </div>
  </body>

由於某種原因font: inherit; 不允許將格式設置元素應用於我的內容,例如<strong><i>等。我希望可以在.target使用這些格式設置html標簽,並使用CSS的當前結構正確呈現它們。 有沒有可能編輯div p方法,使其可行?

jsFiddlehttps : //jsfiddle.net/y4c3c9cb/6/

注意:頂部選擇器( html, body, div,... )不能移動,編輯,並且必須保持在最高位置。

編輯我的.target元素內的.target元素可以是istrongb元素。

編輯2 :更改HTML

好像您的css正在設置諸如strong之類的元素來繼承字體,因此它打算繼承與p關聯的字體,該字體非粗體。

添加字體粗細:粗體表示強。

重置意味着您自己為所有這些標簽設置了規則。 由於包含strong { font: inherit; } strong { font: inherit; } ,您必須添加

strong {
  font-weight: bold;
}

斜體相同:

i {
  font-style: italic;
}

...並為重置規則中的所有其他標簽完成規則,因為否則所有內容看起來都一樣。

更新的提琴: https : //jsfiddle.net/6nuogzg4/1/

嘗試使用font-weight:bold; 更新的小提琴: https : //jsfiddle.net/y4c3c9cb/3/

不要使用這種tape蟲。 采用:

* {
 padding: 0;
 margin: 0;
 border: 0;
 vertical-align: baseline;
}

代替。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM