在Tailwind CSS中更改日期位置。

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

change the date location in tailwind CSS

问题

我想要在我的日期时间数据中更改位置(设计问题)这里是设计

<div class="my-6 ml-3 text-lg leading-6">
    <span class="text-black underline justify-start">{{ __('作者') }}:</span>
    {{ $post->user->name }}
    <span class="justify-end mx-52">
        <a class="text-purple-700">{{ $post->created_at->format('d/m/Y') }}</a>
    </span>
</div>
英文:

i want to change the location (design problem) in my datetime data here's the design

&lt;div class=&quot;my-6 ml-3 text-lg leading-6&quot;&gt;
     &lt;span class=&quot;text-black underline justify-start&quot;&gt;{{ __(&#39;Writter&#39;) }}&lt;/span&gt;:
       {{ $post-&gt;user-&gt;name }}
     &lt;span class=&quot;justify-end mx-52&quot;&gt;
    &lt;a class=&quot;text-purple-700&quot;&gt;{{ $post-&gt;created_at-&gt;format(&#39;d/m/Y&#39;) }}&lt;/a&gt;
     &lt;/span&gt;
&lt;/div&gt;

答案1

得分: 0

你可以考虑使用弹性布局:

<script src="https://cdn.tailwindcss.com"></script>

<div class="my-6 ml-3 text-lg leading-6 flex">
  <span>
    <span class="text-black underline">{{ __('Writter') }}</span>:
    {{ $post->user->name }}
  </span>
  <span class="ml-auto">
    <a class="text-purple-700">{{ $post->created_at->format('d/m/Y') }}</a>
  </span>
</div>

<div class="my-6 ml-3 text-lg leading-6 flex">
  <span class="mr-auto">
    <span class="text-black underline">{{ __('Writter') }}</span>:
    {{ $post->user->name }}
  </span>
  <span>
    <a class="text-purple-700">{{ $post->created_at->format('d/m/Y') }}</a>
  </span>
</div>

<div class="my-6 ml-3 text-lg leading-6 flex justify-between">
  <span>
    <span class="text-black underline">{{ __('Writter') }}</span>:
    {{ $post->user->name }}
  </span>
  <span>
    <a class="text-purple-700">{{ $post->created_at->format('d/m/Y') }}</a>
  </span>
</div>

或者,你可以将日期的 <span> 浮动到右边:

<script src="https://cdn.tailwindcss.com"></script>

<div class="my-6 ml-3 text-lg leading-6 flow-root">
  <span class="text-black underline justify-start">{{ __('Writter') }}</span>:
  {{ $post->user->name }}
  <span class="justify-end float-right">
    <a class="text-purple-700">{{ $post->created_at->format('d/m/Y') }}</a>
  </span>
</div>
英文:

You could consider using a flex layout:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;my-6 ml-3 text-lg leading-6 flex&quot;&gt;
  &lt;span&gt;
    &lt;span class=&quot;text-black underline&quot;&gt;{{ __(&#39;Writter&#39;) }}&lt;/span&gt;:
    {{ $post-&gt;user-&gt;name }}
  &lt;/span&gt;
  &lt;span class=&quot;ml-auto&quot;&gt;
    &lt;a class=&quot;text-purple-700&quot;&gt;{{ $post-&gt;created_at-&gt;format(&#39;d/m/Y&#39;) }}&lt;/a&gt;
  &lt;/span&gt;
&lt;/div&gt;

&lt;div class=&quot;my-6 ml-3 text-lg leading-6 flex&quot;&gt;
  &lt;span class=&quot;mr-auto&quot;&gt;
    &lt;span class=&quot;text-black underline&quot;&gt;{{ __(&#39;Writter&#39;) }}&lt;/span&gt;:
    {{ $post-&gt;user-&gt;name }}
  &lt;/span&gt;
  &lt;span&gt;
    &lt;a class=&quot;text-purple-700&quot;&gt;{{ $post-&gt;created_at-&gt;format(&#39;d/m/Y&#39;) }}&lt;/a&gt;
  &lt;/span&gt;
&lt;/div&gt;

&lt;div class=&quot;my-6 ml-3 text-lg leading-6 flex justify-between&quot;&gt;
  &lt;span&gt;
    &lt;span class=&quot;text-black underline&quot;&gt;{{ __(&#39;Writter&#39;) }}&lt;/span&gt;:
    {{ $post-&gt;user-&gt;name }}
  &lt;/span&gt;
  &lt;span&gt;
    &lt;a class=&quot;text-purple-700&quot;&gt;{{ $post-&gt;created_at-&gt;format(&#39;d/m/Y&#39;) }}&lt;/a&gt;
  &lt;/span&gt;
&lt;/div&gt;

<!-- end snippet -->

Or you could float the &lt;span&gt; with the date to the right:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;my-6 ml-3 text-lg leading-6 flow-root&quot;&gt;
  &lt;span class=&quot;text-black underline justify-start&quot;&gt;{{ __(&#39;Writter&#39;) }}&lt;/span&gt;:
  {{ $post-&gt;user-&gt;name }}
  &lt;span class=&quot;justify-end float-right&quot;&gt;
    &lt;a class=&quot;text-purple-700&quot;&gt;{{ $post-&gt;created_at-&gt;format(&#39;d/m/Y&#39;) }}&lt;/a&gt;
  &lt;/span&gt;
&lt;/div&gt;

<!-- end snippet -->

答案2

得分: 0

justify-startjustify-end 是仅在 flex 和 grid 容器上起作用的类,而不是它们的子元素。您应该将父级 div 设置为 flexbox 容器,并使用 justify-between(这样左侧子元素将靠左,右侧子元素将靠右)。

您还应该将帖子内容从标题中移除,并将它们都包装在一个父 div 中。

(忽略下面代码段中的 CSS,我只是复制了相关的 Tailwind 类。)

<div class="w-fit">
  <div class="flex justify-between w-full">
    <span>帖子标题</span>
    <span>05/06/2023</span>
  </div>
  <div>占位符 lorem ipsum dolor sit amet...</div>
</div>
英文:

justify-start and justify-end are classes that only work on flex and grid containers, not their children. You should make the parent div a flexbox container and put justify-between (so that the left child goes all the way to the left, and the right child goes all the way to the right).

You should also remove the post body from the header, and wrap them both in a parent div.

(Ignore the CSS in the below snippet, I've just replicated the relevant Tailwind classes.)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.flex {
display: flex;
}

.justify-between {
justify-content: space-between;
}

.w-full {
width: 100%;
}

.w-fit {
width: fit-content;
}

<!-- language: lang-html -->

&lt;div class=&quot;w-fit&quot;&gt;
&lt;div class=&quot;flex justify-between w-full&quot;/&gt;
  &lt;span&gt;Post Title&lt;/span&gt;
  &lt;span&gt;05/06/2023&lt;/span&gt;
&lt;/div&gt;
&lt;div&gt;Placeholder lorem ipsum dolor sit amet...&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月6日 00:37:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408428.html
匿名

发表评论

匿名网友

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

确定