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

Creating style alias in CSS on HTML page

我想在动态构建的 HTML 页面上有选择地停止与 < p> 命令关联的换行,并且我正在使用一种样式来执行此操作。我知道

   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>

就那样做:

<span class="stop-p-lf"><p>Some text here</p></span><p>And some here</p>

这样你就可以select你想使用哪个<p>标签CSS:

p{
    color:blue;
}
.stop-p-lf p{
    color:red;
} 

看到这个:https://jsfiddle.net/faeh5szy/