如何使用 Styled Components 覆盖第三方默认样式
How to override third party default styles using Styled Components
我目前正在使用来自 react-video-js-player 的 VideoPlayer,我正在尝试覆盖默认 height/width 样式以使视频继承父 height/width.
因为 VideoPlayer 只是 VideoJS 的 React 包装器。我假设样式和 class 名称是相同的。
我试过这样做:
import VideoPlayer from "react-video-js-player"
export const VideoJS = styled(VideoPlayer)`
position: relative;
height: 100%;
`
在道具中将高度和宽度设置为 100% 不起作用
<VideoPlayer
controls="true"
height={"100%}
width={"100%"}
src="examplevideo"
/>
.
父容器设置为 100% 宽度和高度。
有什么想法吗?
我会做这样的事情,首先检查浏览器中的视频播放器元素以了解它的包装器是什么,假设它是一个 div。你可以这样做:
export const VideoPlayerWrapper= styled.div`
>div{
//this will target the videoPlayerwrapper
position: relative;
height: 100%;
}
`
我目前正在使用来自 react-video-js-player 的 VideoPlayer,我正在尝试覆盖默认 height/width 样式以使视频继承父 height/width.
因为 VideoPlayer 只是 VideoJS 的 React 包装器。我假设样式和 class 名称是相同的。 我试过这样做:
import VideoPlayer from "react-video-js-player"
export const VideoJS = styled(VideoPlayer)`
position: relative;
height: 100%;
`
在道具中将高度和宽度设置为 100% 不起作用
<VideoPlayer
controls="true"
height={"100%}
width={"100%"}
src="examplevideo"
/>
.
父容器设置为 100% 宽度和高度。 有什么想法吗?
我会做这样的事情,首先检查浏览器中的视频播放器元素以了解它的包装器是什么,假设它是一个 div。你可以这样做:
export const VideoPlayerWrapper= styled.div`
>div{
//this will target the videoPlayerwrapper
position: relative;
height: 100%;
}
`