1

I am wanting to do selectively stop the line feeds associated with the < p> command on a dynamically built HTML page and am using a style to do this. I know that

   p {
   display: inline
    }

can do this, but I do not want to continually add this tag throughout the page.

Is there a method where I can create an alias of the p tag, or somehow create another tag that will invoke the style.

For instance (and I know that this code won't work), something like

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

then in my HTML I just use the tag like this..

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

I'm hoping to use these tags to ease readability and to reduce the amount of coding throughout the html.

Is there a way of doing this?

2 Answers 2

1

You cannot create your own tags but you can do it using CSS classess. For example:

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

Then in HTML:

<div class="stop-p-lf"><p>This will be inline</p></div><p>And this don't</p>
Sign up to request clarification or add additional context in comments.

4 Comments

Strictly speaking you can create elements with javascript, so that's not entirely correctly. document.createElement('x-foo'), then instantiate it and add it to the DOM, and indeed the element outlined above is entirely valid. However, obviously it's better to use a class in this instance.
@ToddMoore in HTML you can also create elements in almost the same way but it's not valid with W3C.
That's not correct, you can't just create an element in static HTML, you are right it would not be valid. However, it's entirely valid to create elements dynamically via javascript, particularly now with the WebComponent specification. My point was it's not correct to say you cannot create your own tags. It gives the impression that the DOM is fixed and inflexible when it is not.
This seems the simplest solution... also considered templates and the webcomponent function
0

Just do it like that :

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

This way you can select which <p> tag you want to using CSS :

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

See this : https://jsfiddle.net/faeh5szy/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.