Tailwind将文本左对齐但在div中居中。

huangapple go评论50阅读模式
英文:

Tailwind align text left but centered in div

问题

<div class="px-10 pb-20 md:text-center"> <!-- TAILWIND -->
<div class="px-10 pb-20 md:items-center"> <!-- TAILWIND -->
<div class="px-10 pb-20 md:max-w-2xl md:inline-block md:text-left"> <!-- TAILWIND -->
<div class="px-10 pb-20 place-content-center"> <!-- TAILWIND -->
<div class="px-10 pb-20 max-w-md mx-auto"> <!-- TAILWIND -->
<div class="px-10 pb-20 mx-auto md:text-left max-w-md md:max-w-non"> <!-- TAILWIND -->
英文:

I'm starting out with Tailwind and Rails to build a blog page.

I have left-aligned my text on all screen sizes (sm-xl). However, on screensizes >md I want the text to be left-alight and positioned in the center of the page. (Not md:text-center as this center-aligns the text.)

application.html.erb code:

&lt;body class=&quot;mx-auto&quot;&gt; **TAILWIND**
&lt;div&gt;
  &lt;%= render &#39;shared/navbar&#39; %&gt;
  &lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
  &lt;p class=&quot;alert&quot;&gt;&lt;%= alert %&gt;&lt;/p&gt;
    &lt;div class=&quot;px-10 pb-20 md:max-w-2xl &quot;&gt; **TAILWIND**
     &lt;%= yield %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;%= render &#39;shared/footer&#39; %&gt;

</body>
</html>

This is how the page renders on small screens:

Tailwind将文本左对齐但在div中居中。

This is how the page renders on large screens:
Tailwind将文本左对齐但在div中居中。

I have tried these combinations and none have worked:

  • div class="px-10 pb-20 md:text-center"
  • div class="px-10 pb-20 md:items-center"
  • div class="px-10 pb-20 md:max-w-2xl md:inline-block md:text-left"
  • div class="px-10 pb-20 place-content-center"
  • div class="px-10 pb-20 max-w-md mx-auto"
  • div class="px-10 pb-20 mx-auto md:text-left max-w-md md:max-w-non"

Thanks in advance.

答案1

得分: 1

在它们周围加一个flex包装器,并在其上应用md:justify-center。

英文:

Put a flex wrapper around them and apply md:justify-center on it.

huangapple
  • 本文由 发表于 2023年4月11日 12:25:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定