11

Outline property is in CSS, but I tried to use outline property in react-native.

I encountered the following message while using outline property with react-native.

error:outline property is not a valid style property

Anyone know the property instead of outline property of css in react-native without install another package.

Thanks for your cooperation.

Martin54
  • 1,349
  • 2
  • 13
  • 34
Author
  • 425
  • 1
  • 4
  • 16
  • Did you mean borders: https://facebook.github.io/react-native/docs/view-style-props ?? – retr0 Nov 29 '18 at 05:21
  • 1
    https://github.com/necolas/react-native-web/issues/48 – Sahil Dhir Nov 29 '18 at 05:26
  • 4
    No I means outline. In css,there are properties such as padding,border,margin,outline.but in react-native,outline is not a valid property. – Author Nov 29 '18 at 05:52
  • possible reply – Dako Junior Jan 21 '20 at 03:03
  • The difference between outline and border is that outline overlays on top of the element, while border adds extra thickness (depending on the border width) and therefore will alter the height/width of the element you apply it to. Outline is perfect for debugging purposes, quickly identifying and color coding elements based on their component type for example. – Adonis K. Kakoulidis Dec 19 '22 at 16:36

4 Answers4

3

In React Native we cannot give it by using outline: "red 2px solid" instead we need to break it into individual styles. Think of it as we are styling it through a javascript object.

const styles = StyleSheet.create({
  button: {
    paddingHorizontal: 10,
    paddingVertical: 5,
    backgroundColor: "#e7622e",
    borderColor: "#fcfdfb",
    borderWidth: 2,
    outlineColor: "#523009",
    outlineStyle: "solid",
    outlineWidth: 4,
  },
  title: {
    color: "white",
  },
});

outlineColor: "#523009", outlineStyle: "solid", outlineWidth: 4 are the property name that it understands.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Amit Mondal
  • 329
  • 3
  • 10
0
 
     searchInput: {
                width: "25rem",
                padding: 6,
                outlineColor: "green",
                outlineStyle: "solid",
                outlineWidth: 4,
                borderRadius:10,
                color:"#fff",
              }

we are dividing outline property into color, style & width

  • 4
    Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Nov 09 '22 at 00:32
0

can do something like below

 if (Platform.OS === 'web') (inputStyle as any).outline = "none"
-2
style={{
        height: 40,
        width: "95%",
        borderRadius: 20,
        backgroundColor: this.state.boxColor,
        marginHorizontal: 10,
        fontFamily: ConstantFontFamily.defaultFont,
        fontWeight: "bold",
        paddingLeft: 35,
        minWidth:
            Dimensions.get("window").width >= 1100 ? 630 : 393,
        outline: "none"
    }}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103