Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
7
Question by Knusper · Apr 07, 2017 at 01:00 PM · webglscalingcss

Scale Unity WebGL Canvas to fit browser window

Hi dear community.

I recently updated to Unity 5.6. For WebGL a lot of things have changed since 5.4.

I wanted to know how to automatically adjust the game canvas to fill the whole browser window. I don't want to use fullscreen mode. It worked in earlier builds using some tutorials.

I tried the following in my style.css file:

 .webgl-content * {border: 0; margin: 0; padding: 0; min-width: 1024px; min-height: 768px; width: 100%; height: 100%;}
 .webgl-content {position: absolute; min-width: 1024px; min-height: 768px; width: 100%; height: 100%;}
 
 .webgl-content .logo, .progress {position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
 .webgl-content .logo {background: url('progressLogo.Light.png') no-repeat center / contain; width: 154px; height: 130px;}
 .webgl-content .progress {height: 18px; width: 141px; margin-top: 90px;}
 .webgl-content .progress .empty {background: url('progressEmpty.Light.png') no-repeat right / cover; float: right; width: 100%; height: 100%; display: inline-block;}
 .webgl-content .progress .full {background: url('progressFull.Light.png') no-repeat left / cover; float: left; width: 0%; height: 100%; display: inline-block;}
 
 .webgl-content .logo.Dark {background-image: url('progressLogo.Dark.png');}
 .webgl-content .progress.Dark .empty {background-image: url('progressEmpty.Dark.png');}
 .webgl-content .progress.Dark .full {background-image: url('progressFull.Dark.png');}
 
 .webgl-content .footer {margin-top: 5px; height: 38px; line-height: 38px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;} 
 .webgl-content .footer .webgl-logo, .title, .fullscreen {height: 100%; display: inline-block; background: transparent center no-repeat;} 
 .webgl-content .footer .webgl-logo {background-image: url('webgl-logo.png'); width: 204px; float: left;}
 .webgl-content .footer .title {margin-right: 10px; float: right;}
 .webgl-content .footer .fullscreen {background-image: url('fullscreen.png'); width: 38px; float: right;}

But it doesn't work. Have I missed something? Must I do something in my index.html? I'm using the default layout and deleted the "footer" div.

Thanks in advance!

Best,

Mischaal

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
10

Answer by perevezentsev · Sep 17, 2018 at 12:30 AM

This guy published a template for this: https://github.com/greggman/better-unity-webgl-template Works perfectly for me.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shaneK001 · Sep 21, 2018 at 04:02 PM 0
Share

This worked perfect for me.

avatar image Dominus12 · May 13, 2021 at 09:15 PM 0
Share

It worked for me in Unity 2020.3, thank you!! :D

avatar image
3

Answer by balsarxml · Aug 31, 2018 at 12:31 AM

I made an asset for this!

https://assetstore.unity.com/packages/tools/gui/responsive-webgl-template-117308

alt text

Also feel free to check out the site that I run (https://simmer.io) to see this in action.


3ab05843-63c0-420c-9483-3d59c87968bf.jpg (44.4 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hcjjeong · Mar 05, 2020 at 10:00 AM 0
Share

This one works like magic. but i have one question. how can i toggle to Fullscreen mode? thanks anyway!

avatar image saadjumani · Oct 18, 2020 at 02:11 AM 0
Share

Does not work with Unity 2019.3.10f1

avatar image
-1

Answer by nbkhanhdhgd · Nov 07, 2019 at 04:41 AM

Hi @perevezentsev

Thank you for your project.

I'm testing on mobile devices but how about canvas size? Just set default size of WebGL size (960x600)?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by alxcancado · May 05, 2017 at 11:14 PM

I'm using the Kongregate WeblGL template and I faced the same. What I did was add this to my style:

gameContainer { width: 100%; height: 100%; position: absolute; }

Basically, I replaced the style div webgl-content for div gameContainer and works fine.

PS.: have a look at the Kongs Template, then you can play around and custom it: https://github.com/kongregate/webgl-preloader

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomekkie2 · May 22, 2017 at 07:49 AM 0
Share

The template looks good. Why not to simply change this:

   <div id="webgl-content" style="width: 100%; height: %UNITY_HEIGHT%px">
     <div id="gameContainer" style="width: %UNITY_WIDTH%px; height: %UNITY_HEIGHT%px"></div>

into this:

   <div id="webgl-content" style="width: 100%; height: 100%>
     <div id="gameContainer" style="width: 100%; height: 100%"></div>

Basically the starting point should be the WebGL template from the documentation. But the templates there are not updated yet. I have only found this draft document here: https://docs.google.com/document/d/1wmNOiwa3qXeGqBSFY9IWgoO99LZOu5U3yaxIig-bGAs/edit#heading=h.86qaywgwrt22 to get a new template for 5.6

avatar image CyberMantis · Oct 30, 2017 at 10:29 AM 0
Share

Hello , I couldn't manage to make it work with the $$anonymous$$ongregate WebGL template. Do you have a more detailed explanation about how to do it?

I did that:

    <div id="webgl-content" style="width: 100%; height: 100%>
      <div id="gameContainer" style="width: 100%; height: 100%"></div>


Sorry i'm still new to coding and Unity.

Thanks

avatar image
0

Answer by reagan · Jan 08, 2019 at 06:52 PM

This method worked for me(thanks tipue on codepen):

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image reagan · Jan 08, 2019 at 06:56 PM 0
Share

didnt seem to post the code above...

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Extend WebGL Canvas to fit browser window with respect to the game's aspect ratio,How to extend extend webGL canvas to fit browser width/height with respect to game aspect ration 1 Answer

Scaling Unity WebGL Canvas causes a bad performance 0 Answers

Delaying WebGL player loading until user input 0 Answers

C# to WebGL 2 Answers

WebGL issue - Release Build triggers error, Development Build runs fine 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges