英文:
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
<div class="my-6 ml-3 text-lg leading-6">
<span class="text-black underline justify-start">{{ __('Writter') }}</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>
答案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 -->
<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>
<!-- end snippet -->
Or you could float the <span>
with the date to the right:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-html -->
<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>
<!-- end snippet -->
答案2
得分: 0
justify-start
和 justify-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 -->
<div class="w-fit">
<div class="flex justify-between w-full"/>
<span>Post Title</span>
<span>05/06/2023</span>
</div>
<div>Placeholder lorem ipsum dolor sit amet...</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论