Web components problem

Size
2,499 Kb
Views
28,336

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 Previews

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;
Web components problem - Script Codes
Web components problem - Script Codes
Home Page Home
Developer Enrique Moreno Tent
Username dbugger
Uploaded August 27, 2022
Rating 3
Size 2,499 Kb
Views 28,336
Do you need developer help for Web components problem?

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!

Enrique Moreno Tent (dbugger) Script Codes
Create amazing love letters with AI!

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!