html - React 响应式和动态视频网格

标签 html css reactjs next.js tailwind-css

大家好我正在做一个元素,我想要一个自动填充屏幕空间的动态 div 网格,就像 google meet 为 session 参与者所做的那样。我正在努力实现我正在使用 tailwind css 和 nextjs,但无法弄清楚如何制作像 google meet 这样的网格。

return (
            <div className="flex flex-row h-full w-full">
                <div className="relative flex h-full w-full pb-16 ">
                    <FooterMeeting
                        isMessagesOpen={isMessagesOpen}
                        toggleMessages={() => {
                            setisMessagesOpen(!isMessagesOpen)
                        }}
                        audioPermession={audioPermession}
                        cameraPermession={cameraPermession}
                        toggleVideo={toggleVideo}
                        toggleAudio={toggleAudio}
                    />
                    <div className="flex w-full h-full p-2">
                        <div className="grid w-full grid-flow-col grid-cols-2 grid-rows-2 md:grid-cols-3 md:grid-rows-3 xl:grid-cols-4 xl:grid-rows-3 gap-2 justify-start overflow-x-scroll scrollDiv">
                            <VideoView />
                            <VideoView />
                            <VideoView />
                            <VideoView />
                        </div>
                    </div>
                </div>
                <MessagesSidebar isMessagesOpen={isMessagesOpen} closeMessages={() => { setisMessagesOpen(false) }} />
            </div>
        )

上面是带有 VideoView 的 grid div 的 jsx

const VideoView = (props) => {
    //refs
    const mainDiv = useRef();

    //state
    const [divHeight, setdivHeight] = useState(0)

    //lifecycle
    useLayoutEffect(() => {
        if (mainDiv.current) {
            setdivHeight(mainDiv.current.offsetWidth / 2)
        }
        return () => {

        };
    }, [])
    //methods

    //views
    return (
        <div ref={mainDiv} style={{ height: divHeight }} className=" relative flex w-full h-auto bg-gray-300 dark:bg-appColor-appLight rounded-xl justify-center items-center">
            <video className=" h-auto max-w-full rounded-xl overflow-hidden flipVideo object-cover" />
        </div>
    )
}

上面是VideoView组件

这里是当前问题的截图 enter image description here

能帮上忙就太好了!

最佳答案

你想调整这部分代码:

   <div className="grid w-full grid-flow-col grid-cols-2 grid-rows-2 md:grid-cols-3 md:grid-rows-3 xl:grid-cols-4 xl:grid-rows-3 gap-2 justify-start overflow-x-scroll scrollDiv">
           <VideoView />
           <VideoView />
           <VideoView />
           <VideoView />
   </div>

                     

只需更改类名

className="grid grid-cols-2 gap-0"

这将创建 2 X 2 系统。如果你有 6 ,就会变成 3X2。但是如果你想要更多的控制,你可以写在一个 css 文件中。

className="container"

组件.css

.container{
    // specify how many cols you want
    @apply grid gap-0 grid-cols-3
    
  // ' >* ' means target all of the children 
  // we are able to use '&' with postcss-nesting plugin
   &>*{
    @apply overflow-hidden;
    height:300px;
    max-height:500px;
  // or specify the height based on screen size 
  // sm-md-lg-x1-2x1
    @screen lg{
      height:400px}
    }
}

关于html - React 响应式和动态视频网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68058234/

相关文章:

javascript - 在用 html 填写表单时,如何为无效值制作自定义 css 代码?

php - 在核心 php 元素中动态地从 LTR 到 RTL

javascript - 使用快速服务器在 React 应用程序中热重载

html - 使用@font-face 无法正确显示自定义字体

.net - c#编码转换?

javascript - 替换 jQuery 选定的单元格范围?

html - 假列在窗口时神秘地停止工作

html - 下划线/边框间距 - 设置特定宽度

javascript - 为什么向下滚动导航栏不改变颜色?

javascript - 通过 CSS 模块生成的类名以一种奇怪的方式生成