简体   繁体   English

HTML/ Tailwind CSS:我怎样才能让这个轮子在这个画布上居中

[英]HTML/ Tailwind CSS : How can i center this wheel on this canvas

I'm working on this website that displays a variety of spectrums using canvases.我正在这个网站上工作,该网站使用画布显示各种光谱。 Right now i'm putting a spinning wheel to warn the user when the canvas is loading.现在我正在放置一个旋转轮以在加载画布时警告用户。 The div named "loading" is the spinning wheel.名为“加载”的 div 是纺车。 I'm using Tailwind CSS to position the wheel correctly.我正在使用 Tailwind CSS 来正确定位轮子。 But i'm still new in it.但我还是新手。

 <!-- Tailwind --> <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> <!-- Body --> <div class="flex flex-row justify-center my-4"> <div class="relative w-1/2 flex flex-col mr-1"> <div class="w-full flex flex-row"> <button class="w-1/2 py-1 bg-green-600 text-xl text-gray-100 font-medium transition-colors hover:text-gray-900 focus:outline-none" id="button-spectrum" type="button"> Spectrum </button> <button class="w-1/2 py-1 bg-gray-100 text-xl font-medium transition-colors hover:text-green-600 focus:outline-none" id="button-normalized-spectrum" type="button"> Normalized spectrum </button> </div> <canvas aria-label="Spectrum graphics" class=" relative border border-green-600 bg-white z-1" id="chart-spectrum" role="graphics-document"></canvas> <canvas aria-label="Normalized spectrum graphics" class="relative border border-green-600 bg-white" id="chart-normalized-spectrum" role="graphics-document" style="display: none; !important"></canvas> <div id="loading" class=" absolute bottom-20 right-20 w-12 h-14 z-2 "> <img src="{% static 'polluxwebapp/images/spinningwheel.gif' %}" alt="Loading" /> </div>

Keep in mind the canvas is on the left (you can see the spinning wheel bottom right and this is roughly on the center of the page :请记住,画布在左侧(您可以在右下方看到纺车,这大致位于页面的中心:

请记住画布在左侧(您可以在右下角看到纺车,这大致位于页面的中心

So how can i make it that it is centered to this canvas ?那么我怎样才能使它以这个画布为中心呢? Any help is much appreciated任何帮助深表感谢

Just remove all the classes of spinner and simple add top-1/2 left-1/2 .只需删除所有spinner类并简单地添加top-1/2 left-1/2 1/2 means 50% from the top and left which is center . 1/2表示从顶部到左侧的50% ,即center

Below is code, view in full page screen.下面是代码,全屏查看。

 <!-- Welcome to Tailwind Play, the official Tailwind CSS playground! Everything here works just like it does when you're running Tailwind locally with a real build pipeline. You can customize your config file, use features like `@apply`, or even add third-party plugins. Feel free to play with this example if you're just learning, or trash it and start from scratch if you know enough to be dangerous. Have fun! --> <!-- Tailwind --> <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> <!-- Body --> <div class="flex flex-row justify-center my-4"> <div class="relative w-1/2 flex flex-col mr-1"> <div class="w-full flex flex-row"> <button class="w-1/2 py-1 bg-green-600 text-xl text-gray-100 font-medium transition-colors hover:text-gray-900 focus:outline-none" id="button-spectrum" type="button"> Spectrum </button> <button class="w-1/2 py-1 bg-gray-100 text-xl font-medium transition-colors hover:text-green-600 focus:outline-none" id="button-normalized-spectrum" type="button"> Normalized spectrum </button> </div> <canvas aria-label="Spectrum graphics" class=" relative border border-green-600 bg-white z-1" id="chart-spectrum" role="graphics-document"></canvas> <canvas aria-label="Normalized spectrum graphics" class="relative border border-green-600 bg-white" id="chart-normalized-spectrum" role="graphics-document" style="display: none; !important"></canvas> <div id="loading" class="absolute top-1/2 left-1/2"> <img src="http://commondatastorage.googleapis.com/codeskulptor-assets/week5-triangle.png" alt="Loading" /> </div>

You can set the value as per different screens also.您也可以根据不同的屏幕设置值。

I had added an image ofd triangle instead of spinner.我添加了一个三角形而不是微调器的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM