html - 输入元素超出移动屏幕宽度

标签 html css tailwind-css

我有搜索输入元素,当我在移动设备上查看它时,它超出了屏幕的宽度。我不确定为什么:

enter image description here enter image description here

<template>
 <div id="app" class="bg-gray-200 antialiased">
     <section class="flex justify-between bg-gray-800 px-4 py-3 ">
         <div class="relative">
             <input class= "bg-gray-900 text-white rounded-lg px-12 py-2
                           focus:outline-none focus:bg-white focus:text-gray-500"
                    placeholder="Search by keywords"/>
         </div>


         <button>Filters</button>
     </section>
</div>
</template>

感谢任何帮助。

enter image description here

enter image description here

enter image description here

编辑:

我试图删除设置填充的样式:

<template>
  <div id="app" class="bg-gray-200  ">
      <section class="flex justify-between bg-gray-800   ">
          <div class="  ">
              <input class= "bg-gray-900 "
                     placeholder="Search by keywords"/>
          </div>


          <button>Filters</button>
      </section>
</div>
</template>

但是没用。

我希望使用 tailwind 类来解决它,而不是求助于原始 css 解决方案。

enter image description here

enter image description here

最佳答案

仍然不清楚是什么设置了输入的宽度(可能只是用户代理/浏览器的默认值),但覆盖它会有所帮助:

.flex input { /* or put a custom class on your input, such as input-flex */
    min-width: 0;
}

body {
    width: 240px; /* demo only */
}
<link href="https://unpkg.com/tailwindcss@1.0.0/dist/tailwind.min.css" rel="stylesheet"/>

<div id="app" class="bg-gray-200 antialiased">
  <section class="flex justify-between bg-gray-800 px-4 py-3 ">
      <input class="bg-gray-900 text-white rounded-lg px-12 py-2
                           focus:outline-none focus:bg-white focus:text-gray-500" placeholder="Search by keywords" />

    <button>Filters</button>
  </section>
</div>

原来你可以使用w-full fluid width类似效果的类:

body {
    width: 240px; /* demo only */
}
<link href="https://unpkg.com/tailwindcss@1.0.0/dist/tailwind.min.css" rel="stylesheet"/>

<div id="app" class="bg-gray-200 antialiased">
  <section class="flex justify-between bg-gray-800 px-4 py-3 ">
      <input class="w-full bg-gray-900 text-white rounded-lg px-12 py-2
                           focus:outline-none focus:bg-white focus:text-gray-500" placeholder="Search by keywords" />

    <button>Filters</button>
  </section>
</div>

您可以使用 sm 修饰符定位较小的屏幕,如 sm:w-full

关于html - 输入元素超出移动屏幕宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64248303/

相关文章:

css - Firefox 文件上传框比 Chrome/IE/Safari 大 - 如何解决? - 使用尺寸(HTML)和宽度(CSS)参数

css - 纯 CSS 多堆叠位置置顶?

javascript - 在 React 组件之间使用 mui 图标

asp.net - 在 razor 页面中集成 Tailwind css cdn

reactjs - Tailwind 3.0.23 类未在故事书中实时应用

javascript - 了解 css 类如何更改/更新

html - 如何在绝对位置的顶部显示 float (z-index 不起作用)

css - 是否可以为笔画渐变设置动画?

javascript - Angular js饼图样式

javascript - Bootstrap 模式内的音频标签工作正常,但下载按钮位置超出模式