2

在此处输入图像描述

<div
            className={classNames(
                job.isFeatured ? 'bg-yellow-200' : 'bg-white',
                'relative shadow md:rounded-sm hover:shadow-md'
            )}
        >
            <Link href={`/jobs/${encodeURIComponent(job.jobId)}`}>
                <a className="block p-4 sm:px-6">
                    <div className="flex items-center">
                        <div className="flex flex-col flex-grow md:items-center md:space-x-3 md:flex-row">
                            <h4 className="text-sm text-gray-500 uppercase truncate md:w-24">
                                {job.company_name}
                            </h4>
                            <h3 className="font-medium text-gray-700 truncate overflow-ellipsis">
                                {job.title}
                            </h3>
                        </div>
                        <div className="flex flex-col items-end flex-grow-0 flex-shrink-0 text-right md:space-x-5 md:flex-row">
                            <div className="flex items-center mb-1 text-sm text-right text-gray-600 md:mb-0">
                                <span className="text-right">
                                    {job.isRemote ? (
                                        <>
                                            <GlobeIcon
                                                className="inline-block w-4 h-4 mr-1"
                                                aria-hidden="true"
                                            />
                                            Remote
                                        </>
                                    ) : (
                                        <>
                                            <LocationMarkerIcon
                                                className="inline-block w-4 h-4 mr-1"
                                                aria-hidden="true"
                                            />
                                            {job.location.city}
                                        </>
                                    )}
                                </span>
                            </div>
                            <div className="text-sm text-right text-gray-500 md:w-24">
                                <Moment fromNow>{job.created_at}</Moment>
                            </div>
                        </div>
                    </div>
                </a>
            </Link>
        </div>

无论如何要限制容器外文本的过度跟随?

4

2 回答 2

0

你试过顺风线夹插件吗?在这种情况下,line-clamp-1 将是一个解决方案。

<p class="line-clamp-1"> {text} </p>

所以我建议你在h3 className(职称部分)中将“truncate overflow-ellipsis”更改为“line-clamp-1”

下面是一个有效的测试代码。

<div className="w-432px bg-yellow-200 relative shadow md:rounded-sm hover:shadow-md">
  <Link href="/">
    <a className="block p-4 sm:px-6">
      <div className="flex items-center">
        <div className="flex-1  flex flex-col md:items-center md:space-x-3 md:flex-row">
          <h4 className="text-sm text-gray-500 uppercase truncate md:w-24">
            company name, company name, company name
          </h4>
          /* here */
          <h3 className="font-medium text-gray-700 line-clamp-1">
            job title job title job title job title job title
          </h3>
          /* */
        </div>
        <div className="ml-4 flex-none flex flex-col items-end text-right md:space-x-5 md:flex-row">
          <div className="flex items-center mb-1 text-sm text-right text-gray-600 md:mb-0">
            <span className="text-right">
              <GlobeIcon
                className="inline-block w-4 h-4 mr-1"
                aria-hidden="true"
              />
              Remote
            </span>
          </div>
          <div className="text-sm text-right text-gray-500 md:w-24">
            4 minutes ago
          </div>
        </div>
      </div>
    </a>
  </Link>
</div>
于 2022-02-16T06:47:15.013 回答
0

这是顺风 css 的快速解决方案,您可以使用内置truncate

<div class="p-3 shadow-md w-full m-5 border border-gray-200 truncate">
    This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text This is a long text 
</div>
于 2022-02-16T06:52:10.293 回答