内容比iOS上的屏幕宽
我正在使用屏幕键盘创建一个像应用这样的Wordle。在桌面上开发并使用开发工具模拟移动屏幕时,它看起来不错。但是,当我在iPhone(Safari和Chrome)上查看网站时,键盘太宽了,被切断了。
我检查了Chrome的Android设备,再次看起来还不错。
我正在Svelte中开发,这是我的相关代码:
<script lang="ts">
import Key from './Key.svelte';
const lets = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'];
</script>
<div class="keyboard">
{#each lets as row, i}
{#if i === 2}
<div class="row"
<Key letter="enter" />
{#each row as letter}
<Key {letter} />
{/each}
<Key letter="del" />
</div>
{:else}
<div class="row">
{#each row as letter}
<Key {letter} />
{/each}
</div>
{/if}
{/each}
</div>
<style>
.keyboard {
display: flex;
flex-direction: column;
gap: 6px;
margin: 0 8px;
height: 200px;
max-width: 100vw;
}
.row {
display: flex;
justify-content: center;
gap: 6px;
max-width: 100vw;
touch-action: manipulation;
margin: 0 auto 8px;
}
</style>
这是Key.Svelte:
<script lang="ts">
export let letter: string;
</script>
<button>{letter}</button>
<style>
button {
background-color: rgb(152, 152, 152);
display: flex;
justify-content: center;
align-items: center;
color: white;
border-radius: 4px;
height: 58px;
cursor: pointer;
border: none;
font-family: 'Nanum Pen Script', cursive;
font-size: 22px;
text-transform: uppercase;
user-select: none;
}
</style>
I'm creating a Wordle like app with an on-screen keyboard. When developing on desktop and using dev tools to simulate a mobile screen, it looks fine. But when I view the site on my iPhone (Safari and Chrome), the keyboard is too wide and is cut off.
I checked on an android device in Chrome and, again, it looks fine.
I'm developing in Svelte, here is my relevant code:
<script lang="ts">
import Key from './Key.svelte';
const lets = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'];
</script>
<div class="keyboard">
{#each lets as row, i}
{#if i === 2}
<div class="row"
<Key letter="enter" />
{#each row as letter}
<Key {letter} />
{/each}
<Key letter="del" />
</div>
{:else}
<div class="row">
{#each row as letter}
<Key {letter} />
{/each}
</div>
{/if}
{/each}
</div>
<style>
.keyboard {
display: flex;
flex-direction: column;
gap: 6px;
margin: 0 8px;
height: 200px;
max-width: 100vw;
}
.row {
display: flex;
justify-content: center;
gap: 6px;
max-width: 100vw;
touch-action: manipulation;
margin: 0 auto 8px;
}
</style>
And here is Key.svelte:
<script lang="ts">
export let letter: string;
</script>
<button>{letter}</button>
<style>
button {
background-color: rgb(152, 152, 152);
display: flex;
justify-content: center;
align-items: center;
color: white;
border-radius: 4px;
height: 58px;
cursor: pointer;
border: none;
font-family: 'Nanum Pen Script', cursive;
font-size: 22px;
text-transform: uppercase;
user-select: none;
}
</style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用默认步骤实例化新的Svelte项目时:
应在
public/index.html
中向您提供模板。您可以在线找到此模板在这里。该模板将用于生成index.html
放置在构建目录中的文件。模板的内容如下:
您的问题的关键在这里是行
&lt; meta name ='viewport'content ='width = device-width,onirows-cale = 1'&gt;
将根据您的设备正确扩展显示/视口。请注意,
favicon.png
和global.css
导入也由默认安装提供,而build> build> build/bundle.css
和build/bundle.js
应与您的lollup.config.js
(位于项目root)结合使用。有关更多详细信息,您可以检查整个默认模板项目在这里。
When you instantiate a new Svelte project using the default steps:
a template should be provided to you in
public/index.html
. You can find this template online here. This template will be used to generate theindex.html
file placed into your build directory.The content of the template is the following:
Key for your issue here is the line
<meta name='viewport' content='width=device-width,initial-scale=1'>
which will properly scale the display/viewport according to your device.Note that the
favicon.png
andglobal.css
imports are also provided by the default install, while thebuild/bundle.css
andbuild/bundle.js
should be set in conjunction with yourrollup.config.js
(located at the project root).For more details, you can inspect the whole default template project here.