I’am trying to create a button using css and html assets but nothing appears on my screen. I’m totally confused. How can i use my html and css so i can see the result on my screen?
Here’s a project sample of using HTML and CSS to create UI: https://developer.playcanvas.com/en/tutorials/htmlcss-ui/
Or are you talking about within the context of the editor?
I have css and html, i create two assets in my .js like this: MusicButton.attributes.add(‘cssAsset’, {
type: ‘asset’,
assetType:‘css’,
title: ‘CSS Asset’
});
MusicButton.attributes.add(‘htmlAsset’, {
type: ‘asset’,
assetType:‘html’,
title: ‘HTML Asset’
});
MusicButton.prototype.initialize = function() {
// Add the CSS
var style = pc.createStyle(this.cssAsset.resource);
document.head.appendChild(style);
// Add the HTML
var html = this.htmlAsset.resource;
};
And then match them
Judging from the code you have posted, you haven’t added the HTML to the document.of the webpage.
I added this:
// Add the HTML
var div = document.createElement(‘div’);
div.innerHTML = this.htmlAsset.resource;
document.body.appendChild(div);
i don’t get any errors but the button still doesn’t appear.
Can you share the project please? It’s a bit difficult to see what’s wrong without the context of the project.
Thank you for your help!I can see my button now.