Css 样式化组件/反应/语义/道具和计算
您好,我有一个正常工作的菜单,我使用该属性设置其大小打开和关闭,以及移动分辨率。 但我也试着用我的内容网格做同样的事情 我的第二列没有得到值,我不知道它是否与calc有关: 代码: css: 基本上,我的红色内容应该占据网格的其余部分 但它没有发生我不知道为什么 编辑: 第一个错误是我使用了',而不是'na道具 很好,但我在传递道具时遇到了一些问题: ‘计算(87.5%+50px)’Css 样式化组件/反应/语义/道具和计算,css,reactjs,styled-components,Css,Reactjs,Styled Components,您好,我有一个正常工作的菜单,我使用该属性设置其大小打开和关闭,以及移动分辨率。 但我也试着用我的内容网格做同样的事情 我的第二列没有得到值,我不知道它是否与calc有关: 代码: css: 基本上,我的红色内容应该占据网格的其余部分 但它没有发生我不知道为什么 编辑: 第一个错误是我使用了',而不是'na道具 很好,但我在传递道具时遇到了一些问题: ‘计算(87.5%+50px)’ 代码沙盒中的最佳视图:您需要更新两个ContainerContent的宽度,除此之外,一切都很完美,请参考此示例
代码沙盒中的最佳视图:您需要更新两个ContainerContent的宽度,除此之外,一切都很完美,请参考此示例链接: App.js
import React,{useState}来自“React”;
从“语义ui react”导入{网格、按钮、图标};
导入“/style.css”;
进口{
集装箱网格,
ContainerGridColumnMenu,
集装箱内容
}来自“/样式化”;
导出默认函数App(){
const[open,setOpen]=useState(true);//用setter声明新的状态变量“open”
常量handleClick=e=>{
e、 预防默认值();
setOpen(!open);
};
返回(
{/* */}
);
}
请看这个:是的,谢谢兄弟,我使用了错误的计算kkk 87.5%+50px我把所有东西都放在了%谢谢,让我在这里分享帖子。是的,谢谢你能帮我一个按钮吗?出于某种原因,我认为当我的菜单正常打开时是语义css设置,但当我关闭按钮时,它就脱离了我的容器,我几乎放弃了使用大多数语义css
<ContainerGrid style={{background: '#eee'}}>
{/* <ContainerGridColumn mobile={2} > */}
<ContainerGridColumnMenu status={open ? '12.5%' : '50px'} mobile= {open ? '31.25%' : '12.5%'} >
<div style={{background:'#000', width:'100%', height:'100%'}}>
</div>
</ContainerGridColumnMenu>
<ContainerContent desktop={open ? '87.5%' : 'calc(87.5%+50px)'} mobile = { open ? '68.75%' : '87.5%' }>
<Button icon onClick={handleClick}>
<Icon name="align justify" />
</Button>
</ContainerContent>
</ContainerGrid>
import { Grid, Column } from 'semantic-ui-react';
import styled from 'styled-components';
import { device } from './device';
export const ContainerGrid = styled(Grid)`
background: #eee;
`;
export const ContainerGridColumnMenu = styled(Grid.Column)`
background: #e548;
width: ${props => props.status} !important;
padding: 0 !important;
height: 100vh;
@media only screen and (max-width: 767px) and (min-width: 320px) {
width: ${props => props.mobile} !important;
}
`;
export const ContainerContent = styled(Grid.Column)`
background: #e548;
width: ${props => props.desktop} !important;
padding: 0 !important;
height: 100vh;
@media only screen and (max-width: 767px) and (min-width: 320px) {
width: ${props => props.mobile} !important;
}
`;
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#root,
.App,
.ui.grid{
height: 100vh !important;
margin: 0 !important;
padding:0 !important;
}
import React, { useState } from "react";
import { Grid, Button, Icon } from "semantic-ui-react";
import "./style.css";
import {
ContainerGrid,
ContainerGridColumnMenu,
ContainerContent
} from "./styled";
export default function App() {
const [open, setOpen] = useState(true); // declare new state variable "open" with setter
const handleClick = e => {
e.preventDefault();
setOpen(!open);
};
return (
<ContainerGrid style={{ background: "#eee" }}>
{/* <ContainerGridColumn mobile={2} > */}
<ContainerGridColumnMenu
status={open ? "12.5%" : "calc(12.5% - 50px)"}
mobile={open ? "31.25%" : "12.5%"}
>
<div style={{ background: "#000", width: "100%", height: "100%" }} />
</ContainerGridColumnMenu>
<ContainerContent
desktop={open ? "87.5%" : "calc(87.5% + 50px)"}
mobile={open ? "68.75%" : "87.5%"}
>
<Button icon onClick={handleClick}>
<Icon name="align justify" />
</Button>
</ContainerContent>
</ContainerGrid>
);
}