Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在react native for Styleing中计算()高度_Css_React Native_Styles_Stylesheet_Calc - Fatal编程技术网

Css 如何在react native for Styleing中计算()高度

Css 如何在react native for Styleing中计算()高度,css,react-native,styles,stylesheet,calc,Css,React Native,Styles,Stylesheet,Calc,有一个灰色正方形,用于定位4个小正方形 有一个黑色正方形,在黑色正方形的每边中心将有4个小正方形。 对于普通的web,我可以通过计算宽度来实现 但是,我应该如何在哪一个calc(100%-20)不起作用的情况下进行呢 请检查代码笔中的代码: index.html <!DOCTYPE html> <head> <title>squares in square</title> <link rel="stylesheet" hre

有一个灰色正方形,用于定位4个小正方形
有一个黑色正方形,在黑色正方形的每边中心将有4个小正方形。
对于普通的web,我可以通过计算宽度来实现
但是,我应该如何在哪一个calc(100%-20)不起作用的情况下进行呢

请检查代码笔中的代码:

index.html

<!DOCTYPE html>

<head>
    <title>squares in square</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class='container'>
        <div class='invisiblesquare'>
            <div class='bigsquare'></div>
            <div class='col1'>
                <div class="smallsquare"></div>
            </div>
            <div class='col2'>
                <div class="smallsquare"></div>
                <div class="smallsquare"></div>
            </div>
            <div class='col3'>
                <div class="smallsquare"></div>
            </div>
        </div>
    </div>
    </div>


</body>

</html>

您可以使用

import {Dimensions} from 'react-native';

const screenWidth = Dimensions.get('window').width;
const screenHeight = Dimensions.get('window').height;
然后你可以做如下计算

width: screenWidth - 20

希望这对您有所帮助。

使用WindowDimensions
屏幕大小更改时自动更新
宽度和
高度值。您可以获得应用程序窗口的宽度和高度,如下所示:

import {useWindowDimensions} from 'react-native';

const windowWidth = useWindowDimensions().width;
const windowHeight = useWindowDimensions().height;
这是一个例子


谢谢您的回复,是否有任何关于代码结构的评论,以便可以使用其他方法。@GGprogram对您的评论有点困惑。你到底想要实现什么?
import {useWindowDimensions} from 'react-native';

const windowWidth = useWindowDimensions().width;
const windowHeight = useWindowDimensions().height;