Tuesday, 24 July 2018

Did you know that style and script tags can be set to display: block?

The other night, Amit Patel mentioned that you can set script tags in HTML to display: block with CSS and then edit that code inline with the contentEditable attribute. This means that you can then see it all update live in the browser as you type. Shortly after, Marius Gundersen replied that you can do this with the style tag as well.

All of this is such a weird concept to me that I just had to make a demo to see if it worked:

See the Pen contentEditable <style&rt; tags by Robin Rendle (@robinrendle) on CodePen.

And it does, as strange as that might be! All you need to do is add the contentEditable attribute to the style tag and make sure it’s set to display: block like so:

<p>content goes here</p>

<style contenteditable>
  p {
    color: black;
  }
</style>
style {
  display: block;
}

Why would we want to do this? Well, I’m not entirely sure. But it is certainly a neat demo. This also reminds me of the ever-so bizarre and brilliant demo Jake Albaugh made a while back, which just happens to be one of my favorite pens of all time:

See the Pen pen#PwLXXP by Jake Albaugh (@jakealbaugh) on CodePen.

The post Did you know that style and script tags can be set to display: block? appeared first on CSS-Tricks.



from CSS-Tricks https://ift.tt/2OaH6ES
via IFTTT

No comments:

Post a Comment

Passkeys: What the Heck and Why?

These things called  passkeys  sure are making the rounds these days. They were a main attraction at  W3C TPAC 2022 , gained support in  Saf...