技术实践

tailwindcss 太有魅力了

完成这个响应式效果,总代码量不到50行左右,基本不用写样式,我已经深深的爱上`tailwindcss`这中编程模式

羊先生的头像
羊先生2023.10.27 · 2 分钟阅读 · 104 阅读
tailwindcss 太有魅力了封面
文章正文还需 2 分钟

我想把导航做成专业导航,类似这个网站,https://www.thosefree.com/,
我觉的他的很好,流量非常的高,按照转化率的话,一个月收入几千元不是问题
image.png

这是我目前发布的几个开源产品,https://github.com/hangjob/vue-bag-admin

这个基于nuxt编写的一个模块,可以安装即可使用,优点在于服务端渲染,解决网站seo问题,以及也有很好的辅助插件
https://github.com/hangjob/nuxt-bag-web

接触tailwindcss,太好用了,

image.png
HTML 复制代码
<template>
    <div class="px-3 py-3 rounded-[5px] bg-white mb-4 overflow-hidden">
        <div class="flex max-sm:flex-col max-md:flex-col max-lg:flex-col max-xl:flex-row max-2xl:flex-row  space-x-2">
            <div class="relative max-sm:basis-full max-md:basis-full max-lg:basis-full basis-8/12">
                <h1 class="text-[18px] font-normal">赤壁市第六小学新建项目</h1>
                <p class="text-[14px] pt-4 leading-5 text-justify line-clamp-2">赤壁市锦华工程造价咨询有限公司赤壁市锦华工程造价咨询有限公司赤壁市锦华工程造价咨询有限公司赤壁市锦华工程造价咨询有限公司赤壁市锦华工程造价咨询有限公司</p>
                <div class="pt-2 space-x-3 space-y-2 pb-8">
                    <UBadge class="bg-gray-100 text-slate-900 cursor-pointer hover:bg-green-500 hover:text-white" :ui="{ rounded: 'rounded-full' }" size="sm">
                        <svg class="icon stroke-2 mr-1" aria-hidden="true">
                            <use xlink:href="#haiwb-biaoqian"></use>
                        </svg>
                        测试
                    </UBadge>
                    <UBadge class="bg-gray-100 text-slate-900 cursor-pointer hover:bg-green-500 hover:text-white" :ui="{ rounded: 'rounded-full' }" size="sm">
                        <svg class="icon stroke-2 mr-1" aria-hidden="true">
                            <use xlink:href="#haiwb-biaoqian"></use>
                        </svg>
                        测试
                    </UBadge>
                </div>
                <div class="mt-3 flex items-center flex-row space-x-2 absolute bottom-0 left-0 w-full">
                    <div class="flex items-center flex-row flex-shrink-0">
                        <svg class="icon stroke-2 mr-1" aria-hidden="true">
                            <use xlink:href="#haiwb-naozhong"></use>
                        </svg>
                        <span class="text-[12px] text-gray-500">2023年07月16日 星期日</span>
                    </div>
                    <div class="flex items-center flex-row flex-shrink-0">
                        <svg class="icon stroke-2 mr-1" aria-hidden="true">
                            <use xlink:href="#haiwb-zuixinziyuan"></use>
                        </svg>
                        <span class="text-[12px] text-gray-500">32131</span>
                    </div>
                    <div class="flex items-center flex-row flex-shrink-0">
                        <svg class="icon stroke-2 mr-1" aria-hidden="true">
                            <use xlink:href="#haiwb-zixun"></use>
                        </svg>
                        <span class="text-[12px] text-gray-500">测试</span>
                    </div>
                    <div class="flex items-center flex-row basis-full justify-end">
                        <a class="flex items-center flex-row bg-slate-100 rounded-[5px] px-2 py-1" href="">
                            <svg class="icon stroke-2 mr-1" aria-hidden="true">
                                <use xlink:href="#haiwb-biaoqiankuozhan_wode-285"></use>
                            </svg>
                            <span class="text-[12px] text-gray-500">测试</span>
                        </a>
                    </div>
                </div>
            </div>
            <div class="max-sm:basis-full max-sm:mt-2  max-md:basis-full max-md:mt-2 max-lg:basis-full max-lg:mt-2 basis-4/12">
                <div class="thumbnail sm-thumbnail md-thumbnail lg-thumbnail h-40">
                    <nuxt-img fit="cover" class="w-full h-full object-cover" loading="lazy" src="/uploads/20230923/466ccd86b419fbd0da712aa7532bee06.jpg"></nuxt-img>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">

</script>

<style lang="less">
.thumbnail{
    clip-path: polygon(2% 0, 100% 0, 100% 100%, 10% 100%);
    border-radius: 6px;
    background-color: #ffffff;
    overflow: hidden;
}
</style>

完成这个响应式效果,总代码量不到50行左右,基本不用写样式,我已经深深的爱上tailwindcss这中编程模式