html - 在 HTML 页面的 CSS 中创建样式别名

标签 html css tags

我想在动态构建的 HTML 页面上有选择地停止与

命令关联的换行,并且我正在使用一种样式来执行此操作。这个我知道

   p {
   display: inline
    }

可以这样做,但我不想在整个页面中不断添加此标记。

有没有一种方法可以创建 p 标签的别名,或者以某种方式创建另一个将调用该样式的标签。

例如(我知道这段代码行不通),比如

  <style type="text/css">
  stop-p-lf {
     p {
       display: inline
     }
  }
  </style>

然后在我的 HTML 中我只使用这样的标签..

  <stop-p-lf>the next p tag will not line feed <p> 
   but the one after this</stop-p-lf> <p> will

我希望使用这些标签来提高可读性并减少整个 html 的编码量。

有没有办法做到这一点?

最佳答案

您不能创建自己的标签,但可以使用 CSS 类来创建。例如:

.stop-p-lf p { display: inline; }

然后在 HTML 中:

<div class="stop-p-lf"><p>This will be inline</p></div><p>And this don't</p>

关于html - 在 HTML 页面的 CSS 中创建样式别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147553/

相关文章:

javascript - 更改元素的 className 会导致使用 $(className).each() 无法找到它

javascript - jQuery 主详细信息选择列表不起作用

javascript - 根据下拉列表中的选择更新文本字段(Angular JS)

javascript - 使用 CSS3 隐藏元素

javascript - 单击 href 后禁用关闭下拉菜单

javascript - 更改部分不透明度onclick?

javascript - 如何将 css 文本格式添加到 javascript 推送错误?

tags - 热门话题 : 1-word terms vs composed terms

html - HTML 中 "> or "/> 的区别

azure - az 标签更新错误 : (MissingSubscription) The request did not have a subscription or a valid tenant level resource provider