首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >针对div中类之前的文本。

针对div中类之前的文本。
EN

Stack Overflow用户
提问于 2022-04-02 12:05:24
回答 3查看 49关注 0票数 0

我有这个div

代码语言:javascript
复制
<div>
    Questions about these terms
    <ol class="alphabetical">
      <li>
        <div>If you have any questions about these terms or the Platform, you may contact us by email at
          <a href="mailto:support@example.com">support@example.como</a>.</div>
      </li>
      <li>
        <div>Our VAT number is {vat}.</div>
      </li>
    </ol>
  </div>

我还有别的div

代码语言:javascript
复制
<div>
content here...
</div>

在同一份文件中。我想特别强调一下这段文字。

代码语言:javascript
复制
**Questions about these terms**
    <ol class="alphabetical">

发生在这个类<ol class="alphabetical">之前的

这不起作用

代码语言:javascript
复制
.alphabetical::before {
 font-weight:bold !important;
}

有什么方法可以用简单的css定位文本吗?

EN

回答 3

Stack Overflow用户

发布于 2022-04-02 12:41:13

不同的方法,有些方法是

  1. 包装您想要粗体的文本i html <b></b>-tags
  2. 将您想要用粗体表示的文本包装为i html <span></span>-tags,然后使用css进行样式转换。
  3. 在父div上设置font-weight,然后在ol-element选择器上使用font-weigth: initial;
票数 3
EN

Stack Overflow用户

发布于 2022-04-02 13:18:43

不能使用该选择器访问此文本。

相反,将其包装到另一个内联元素,如spanb或其他元素,然后使用选择器获取该元素:

代码语言:javascript
复制
span.header {
  font-weight: bold;
}
代码语言:javascript
复制
<div>
    <span class="header">Questions about these terms</span>
    <ol class="alphabetical">
      <li>
        <div>If you have any questions about these terms or the Platform, you may contact us by email at
          <a href="mailto:support@example.com">support@example.como</a>.</div>
      </li>
      <li>
        <div>Our VAT number is {vat}.</div>
      </li>
    </ol>
  </div>

参见:*以前是如何工作的。

更新:

如果您想在不包装文本的情况下获得此文本,则可以使用以下内容:

代码语言:javascript
复制
<div class="container">
    Questions about these terms
    <ol class="alphabetical">
      <li>
        <div>If you have any questions about these terms or the Platform, you may contact us by email at
          <a href="mailto:support@example.com">support@example.como</a>.</div>
      </li>
      <li>
        <div>Our VAT number is {vat}.</div>
      </li>
    </ol>
  </div>
代码语言:javascript
复制
/* Selects each <div>, but only if it is the */
/* only <div> element inside its parent */
/* without container class */

div:only-of-type {
  font-weight: bold;
}
div > * {
  font-weight: initial;
}
票数 0
EN

Stack Overflow用户

发布于 2022-04-02 22:17:03

只需将文本包装在div或p(或两者都)中,并给出一个类并将其样式化。例如:

代码语言:javascript
复制
<div>
    <p class="foo">Questions about these terms </p>
    <ol class="alphabetical">
      <li>
        <div>If you have any questions about these terms or the Platform, you may contact us by email at
          <a href="mailto:support@example.com">support@example.como</a>.</div>
      </li>
      <li>
        <div>Our VAT number is {vat}.</div>
      </li>
    </ol>
  </div>

和css:

代码语言:javascript
复制
.foo {
 font-weight: bold;
} 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71717388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档