Web components problem
How do I make an web components problem?
This is my problem: I want that all the paragraphs shown within my component are black. But if the elements taken in the insertion nodes have styles from the parent page, they will propagate inside my component. How can I avoid this?. What is a web components problem? How do you make a web components problem? This script and codes were developed by Enrique Moreno Tent on 27 August 2022, Saturday.
Web components problem - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Web components problem</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ p{ font-size: 20px; font-family: Arial; text-transform: uppercase;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <template> <style> h1{ font-family: sans-serif; margin: 0 0 20px 0; } /* This is how you style the element containing the Shadow DOM */ @host{ *{ background-color: gray; margin: 20px; padding: 20px; border: 3px solid brown; } } /* This is how you style the content injected */ ::-webkit-distributed(p){ color: orange; } /* This is the non-vendor selector */ ::content{ color: green; } /* This should be working... */ ::content p{ color: black; } </style> <h1>Styling the content injected in a Web Component</h1> <!-- I want to make sure that paragraphs here are black --> <content></content>
</template>
<div class="host"> <p>This text will be green if the ::content selector is supported in your browser.</p> <p>It will be orange if supports vendor-specific selectors</p> <p>it will be black otherwise</p>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Web components problem - Script Codes CSS Codes
p{ font-size: 20px; font-family: Arial; text-transform: uppercase;
}
Web components problem - Script Codes JS Codes
// shim layer
HTMLElement.prototype.createShadowRoot = HTMLElement.prototype.createShadowRoot || HTMLElement.prototype.webkitCreateShadowRoot;
var root = document.querySelector(".host").createShadowRoot();
root.appendChild( document.querySelector("template").content.cloneNode(true) );
root.resetStyleInheritance = true;
root.applyAuthorStyles = false;
Developer | Enrique Moreno Tent |
Username | dbugger |
Uploaded | August 27, 2022 |
Rating | 3 |
Size | 2,499 Kb |
Views | 28,336 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Enrique Moreno Tent | 1,963 Kb |
Gradients in CSS3 | 3,084 Kb |
Flexbox examples | 2,648 Kb |
Animated percentage indicator with Snap.svg | 2,542 Kb |
Google Maps API v3 - Basic Map | 2,191 Kb |
International clocks | 2,091 Kb |
Video for everybody | 2,394 Kb |
Emotion filter | 2,325 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Default Input, Textareas, Submits, and Buttons in iOS | Demersdesigns | 2,334 Kb |
Faux column absolute wrapper | Yurimorini | 1,823 Kb |
A cube | KyleDavidE | 18,627 Kb |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
Hmmm... | Rk007 | 4,848 Kb |
FCC - Tribute Page | Cmwebby | 0 Kb |
Animate a paper plane along an SVG path, looking ahead | PotatoDie | 3,734 Kb |
Svg animation draw | SzymonDziewonski | 5,545 Kb |
Marching Squares Visualized | Sakri | 7,074 Kb |
Hamburger Menu Animation | Salmanraza | 2,580 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!