【问题标题】:Flexbox alignment - two on each row and then oneFlexbox 对齐 - 每行两个,然后一个
【发布时间】:2020-11-03 12:46:55
【问题描述】:

我将添加一张我如何尝试使链接框对齐的图片:

examplepic

所以每行有两个,大小相同,然后在左最后一行有一个。我一直在尝试使用 wrap、justifycontent 和 flex,但我没有做对。有小费吗?代码如下;

return (

    <View style={styles.linkContainer}>

            <TouchableOpacity
                containerStyle={styles.linkContainerStyle}
                onPress={() =>
                    WebBrowser.openBrowserAsync(
                        "https://skatt.skatteetaten.no/web/minskatteside/?innvalg=minearbeidsgivere#/minearbeidsgivere"
                    )
                }
            >
                <View style={styles.linkContainer}>
                    <Icon name="arrow-circle-right" size={15}></Icon>
                    <Text style={{ fontWeight: "bold",fontSize: 13}}> Videregående opplæring </Text>
                </View>
            </TouchableOpacity>



            <TouchableOpacity
                containerStyle={styles.linkContainerStyle}
                onPress={() =>
                    WebBrowser.openBrowserAsync(
                        "https://skatt.skatteetaten.no/web/minskatteside/?innvalg=minearbeidsgivere#/minearbeidsgivere"
                    )
                }
            >
                <View style={styles.linkContainer}>
                    <Icon name="arrow-circle-right" size={15}></Icon>
                    <Text style={{ fontWeight: "bold",fontSize: 13}}> Lærling </Text>
                </View>
            </TouchableOpacity>




        <View style={styles.testTwo}>
            <TouchableOpacity
                containerStyle={styles.linkContainerStyle}
                onPress={() =>
                    WebBrowser.openBrowserAsync(
                        "https://skatt.skatteetaten.no/web/minskatteside/?innvalg=minearbeidsgivere#/minearbeidsgivere"
                    )
                }
            >
                <View style={styles.linkContainer}>
                    <Icon name="arrow-circle-right" size={15}></Icon>
                    <Text style={{ fontWeight: "bold",fontSize: 13}}> Høyere og anna utdanning </Text>
                </View>
            </TouchableOpacity>
        </View>



            <TouchableOpacity
                containerStyle={styles.linkContainerStyle}
                onPress={() =>
                    WebBrowser.openBrowserAsync(
                        "https://skatt.skatteetaten.no/web/minskatteside/?innvalg=minearbeidsgivere#/minearbeidsgivere"
                    )
                }
            >
                <View style={styles.linkContainer}>
                    <Icon name="arrow-circle-right" size={15}></Icon>
                    <Text style={{ fontWeight: "bold",fontSize: 13}}> Grunnskoleopplæring </Text>
                </View>
            </TouchableOpacity>




            <TouchableOpacity
                containerStyle={styles.linkContainerStyle}
                onPress={() =>
                    WebBrowser.openBrowserAsync(
                        "https://skatt.skatteetaten.no/web/minskatteside/?innvalg=minearbeidsgivere#/minearbeidsgivere"
                    )
                }
            >
                <View style={styles.linkContainer}>
                    <Icon name="arrow-circle-right" size={15}></Icon>
                    <Text style={{ fontWeight: "bold",fontSize: 13}}> Sommerkurs </Text>
                </View>
            </TouchableOpacity>
        </View>



);

}

和 CCS:

const styles = StyleSheet.create({




linkContainer:{
    flexDirection: 'column',

},


linkContainerStyle:{
    borderWidth: 1,
    borderColor: "black",
    backgroundColor: "white",
},

});

我删除了我在 CCS 中的尝试,因为此时它基本上是一团糟。如果有人对如何使图标与文本在同一行对齐有任何提示,那就太好了!。

【问题讨论】:

    标签: html css react-native flexbox


    【解决方案1】:

    这是您想要的对齐的工作示例

    .container {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-between;
      width: 300px;
    }
    
    .container .item {
      width: 48%;
    }
    <div class="container">
      <div class="item">
        item1
      </div>
      
      <div class="item">
        item2
      </div>
      
      <div class="item">
        item3
      </div>
      
      <div class="item">
        item4
      </div>
      
      <div class="item">
        item5
      </div>
    </div>

    【讨论】:

    • 很好……缩小到屏幕宽度,然后width: … 会变得不舒服。 :(
    • 是的,您应该根据自己的喜好编辑宽度,可能使用百分比
    • 这种工作但不是 100%,它在反应原生所以不能使用 px。第一行和第二行左框之间没有空格,但其余的似乎可以工作:))
    • 从未与 react 合作过,因此无法帮助您,抱歉 :) 如果您想为项目提供更多空间,您可以将 margin-bottom 添加到 .item
    • 是的,我想这并不难,现在我有了一个很好的起点。太感谢了!! :)
    猜你喜欢
    • 2017-02-06
    • 2018-06-21
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    相关资源
    最近更新 更多