In 'Semantic UI React', I want to remove the vertical padding between stacked rows.
Why this inline styling doesn't succeed: style={{ padding: '0rem 0rem !important' }} ?
import React from 'react';
import { Grid, Segment } from 'semantic-ui-react';
function Footer() {
return (
<Grid textAlign="center" stackable>
<Grid.Row
divided
style={{ padding: '0rem 0rem !important' }}
>
<Grid.Column width="two">text_01</Grid.Column>
<Grid.Column width="two">text_02</Grid.Column>
</Grid.Row>
</Grid>
);
}
export default Footer;
(I want the two text elements to be in the middle of the page. On wide screen: next to each other. On small screen: stacked above each other. In both cases, they shouldn't be too far apart from each other, hence no padding. And each text element shouldn't spread over several lines.)
The only solution I found is to edit semantic-ui-css/semantic.css, replacing padding: 1rem 1rem !important (see below) with padding: 0rem 0rem !important. Then importing that CSS file instead of the usual semantic.min.css.
Is this actually an acceptable way of doing?
.ui.stackable.grid > .row > .wide.column,
.ui.stackable.grid > .wide.column,
.ui.stackable.grid > .column.grid > .column,
.ui.stackable.grid > .column.row > .column,
.ui.stackable.grid > .row > .column,
.ui.stackable.grid > .column:not(.row),
.ui.grid > .stackable.stackable.row > .column {
width: 100% !important;
margin: 0em 0em !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
padding: 1rem 1rem !important;
}
NB as I've never used Gulp, I don't want to build a custom theme just for this issue.
Answer to myself:
ReactJS "mostly" doesn't support the !important tag within inline styles. Don't use !important inside React inline styles!
probably, learning how to create a custom theme with Gulp would be the way to go.
instead of modifying semantic-ui-css/semantic.css, better create a css file specific to the component you're targetting. In practice:
create myComponent.css in same folder as MyComponent.js, and write your new CSS rules there.
add import ./myComponent.css inside MyComponent.js.
inspect the page with Chrome Developper Tools (for example) and check at the top of the Styles tab which CSS rules currently have highest specificity. The new rule need be more specific. To solve the question, we can add a noPadding class (!important is required to bypass the !important that's already in the existing less-specific rule):
.ui.stackable.grid > .row > .column.wide.noPadding {
padding: 0 !important;
}
inside MyComponent.js, add the corresponding class:
<Grid.Column
width="two"
className="noPadding">
text_01
</Grid.Column>
while creating the new css rules, beware CSS specificity, especially:
context doesn't impact specificity: even if MyComponent is nested within BigComponent.js, this doesn't give higher specificity to MyComponent.
child selector (>) doesn't increase specificity. The number of selectors does impact specificity. See:
CSS: Child selector higher precedence than class selecctor?
for questions regarding semantic-ui-react, best meet the community in their gitter chat room:
https://gitter.im/Semantic-Org/Semantic-UI-React
There's also this https://www.npmjs.com/package/react-with-important-style which looks promising.
See below I have basically replaced Grid.Column (which is notoriously hard to remove the padding) with my Wrapped var which calls withImportantStyle.
var Wrapped = withImportantStyle("div");
var columnStyle = {
padding: "0 !important"
};
var segmentStyleButtons = {
color:"red"
};
return (
<Grid stackable columns={2} reversed="mobile">
<Wrapped className="column" style={columnStyle}>
<Segment>
<List>
<List.Item as='a'>Reset Password</List.Item>
<List.Item as='a'>Resend Confirmation Link</List.Item>
</List>
</Segment>
</Wrapped>
<Wrapped style={columnStyle}>
<Segment style={{ ...segmentStyleButtons, textAlign: "right" }}>
<Button.Group>
<Button primary>Login</Button>
<Button.Or />
<Button secondary>Register</Button>
</Button.Group>
</Segment>
</Wrapped>
</Grid>
);
Related
<Button component={Link} variant="text" to={link.path} sx={{ color: "#fff",'&:hover':{transform: 'translateY(-0.25em);'}}}>{link.label}</Button>
This is what I have tried so far with no sucsess
Is it possible to have &:hover in sx or do I have to create a style class in MUI?
Yes, you can use pseudo-selectors in the sx prop
Per MUI documentation
Superset of CSS
As part of the prop, you can use any regular CSS too: child or pseudo-selectors, media queries, raw CSS values, etc. Here are a few examples:
Using pseudo selectors:
<Box
sx={{
// some styles
":hover": {
boxShadow: 6,
},
}}
>
I'm building a login Component in React, and trying to add the brand image. When I do this, I'm getting a huge amount of white space underneath it.
I've been working on this for a bit now, and I've discovered that, when I look in the dev tools, I can make headway by modifying this mysterious div that seems to be created by Material-UI, the front-end framework I'm using.
When I look into this in the dev tools, I find that there's a div with the attribute padding-top: calc(100%) which, when modified to something like padding-top: calc(30%), reduces the size of this whitespace underneath the image.
I've also tried some of the basic layout solutions suggested in many of the answers to similar questions here on SO, but none of them make a difference. It seems that this padding issue is at the heart of the problem.
The Problem
Because I don't know what's creating this div, I'm not able to override the padding to work towards a solution. I've tried modifying paddingTop and padding with the !important tag in the styling of both the image, and the parent element of the image.
Code Sample
<Paper variant='outlined' style={{ width: '380px' }}>
<Box m={4}>
<Image
src='../static/images/TextLogo.svg'
imageStyle={{
height: 'auto',
width: '100%',
}}
/>
</Box>
...
Stack
"#material-ui/core": "^4.0.0-alpha.8",
"material-ui-image": "^3.2.3",
"next": "^8.1.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
Thanks. I'd appreciate your help!
The <div> with the padding-top and other styles is coming from the Image component that you are using from material-ui-image.
Below is the overall structure rendered by that Image component:
<div
style={styles.root}
onClick={onClick}
>
{image.src && <img
{...image}
style={styles.image}
onLoad={this.handleLoadImage}
onError={this.handleImageError}
/>}
<div style={styles.iconContainer}>
{!disableSpinner && !this.state.imageLoaded && !this.state.imageError && loading}
{!disableError && this.state.imageError && errorIcon}
</div>
</div>
padding-top is part of the styles in styles.root.
styles.root:
const styles = {
root: {
backgroundColor: color,
paddingTop: `calc(1 / ${aspectRatio} * 100%)`,
position: 'relative',
...style
},
When padding-top is a percentage, it is a percentage of the width, so it is important to control the width of the container in order to have predictable behavior.
You can modify the padding-top by either explicitly overriding it via the style prop or by specifying the appropriate value in the aspectRatio prop. By default, this Image component is assuming square images (aspectRatio: 1).
Here is a working example demonstrating both ways of controlling padding-top:
import React from "react";
import Image from "material-ui-image";
import Box from "#material-ui/core/Box";
export default function App() {
return (
<>
<Box m={4} width={200}>
<Image
aspectRatio={1.5}
src="https://www.publicdomainpictures.net/pictures/10000/velka/black-monkey-11280155875i3QV.jpg"
/>
Something under image 1
</Box>
<Box m={4} width={200}>
<Image
style={{
paddingTop: "calc(66.7%)"
}}
src="https://www.publicdomainpictures.net/pictures/10000/velka/black-monkey-11280155875i3QV.jpg"
/>
Something under image 2
</Box>
</>
);
}
Slightly related answer (with regard to the use of padding-top): A good way to handle #material-ui Skeleton scaling within a variable height grid row?
I am new to React and react-bootstrap. I have a Row component and would like spacing between the top of the screen and also between the individual row elements. I am currently just editing its CSS but heard that it may be bad to mess with the CSS of frameworks?
const Styles = styled.div`
.background {
background: url(${backgroundImage}) no-repeat fixed bottom;
background-size: cover;
height: 100vh;
position: relative;
}
#row {
position: relative;
top: 200px;
}
`;
class Signup extends React.Component {
render() {
return (
<Styles>
<div className="background">
<Container>
<Row id="row" className="justify-content-md-center">
<ExtraInfo />
<SignupForm />
</Row>
</Container>
</div>
</Styles>
);
}
}
export default Signup;
Use Form.Group in React-Bootstrap. It adds 15px padding on columns to separate the content of the columns.
I'm not saying this is the best solution, but I have just created a CSS class that sets a margin attribute to 5px and then applied it to the Row element where I need it. This works for me, but I'm welcome to better answers.
For space at the top and bottom of the screen, what I have done is create a "spacer" component which I import and use to create space between elements.
I know what you mean about messing with the CSS though and this method might be a bit "hacky".
Example JSX:
<>
<p><strong>My Categories</strong></p>
{
catList.map((cat,i) => (
<Row key={i} className="add-space">
<Col><strong>Category {i+1}</strong></Col>
<Col>{cat}</Col>
<Col><Button onClick={() => removeCategory(cat)}>Remove</Button></Col>
</Row>
))
}
</>
Example CSS:
.add-space {
margin: 4px;
}
Example Spacer:
const Spacer = props => {
return (
<div style={{height:props.height}}></div>
);
}
export default Spacer;
Use:
<Spacer height="1rem" />
I am using reactjs-popup and it displays its content. But I am unable to set its width. It is not taking effect for some reason. What am I doing wrong?
I have tried width:'50%' and width:'50px'. But it always displays the popup in a very wide huge rectangle. If I resize the whole browser only then the popup reduces in size.
<Popup style={{width:'50%'}}
open={true}
closeOnDocumentClick
keepTooltipInside=".tooltipBoundary"
>
<div className="modal" style={{display:'flex', background: 'radial-gradient(#cde6f9, #6191bf)'}}>
<a className="close">
×
</a>
<div style={{alignitems: 'center', justifycontent: 'center'}}>
<h4>Enter Project Name : </h4>
<input style={{alignitems: 'center', justifycontent: 'center'}} type="text" name="fname"></input><br/><br/>
<button style={{alignitems: 'center', justifycontent: 'center'}} >Create</button>
</div>
</div>
</Popup>
Assuming that the Popup component comes from an external package, try to read the documentation for more styling options.
You can probably also view the component in node_modules/[package_name] folder. Try giving it a className there or style it using the style property.
Finally, you can try wrapping the popup with another element and capture the style using css.
Something like that:
.popup-wrapper {
width: 100%;
}
.popup-wrapper > * {
width: 50%;
}
You can certainly globally update the content styles as other posts here imply. But if you want to set the style for a specific popup...
If you inspect the <Popup HTML, you will see there are two divs. One has a class defined with popup-content and a second named popup-overlay. You can overwrite the styles here using the contentStyle and overlayStyle attributes of any given <Popup.
For example if you want to change the width of the content:
<Popup
...set other attributes here as needed
contentStyle={{ width: '100%' }}
>
Show this content
</Popup>
Wrap the popup in div and give it a class like modalWrapper.
You can target the main popup container div by using this css.
.modalWrapper > div > div {
width: 484px !important;
padding: 24px !important;
border-radius: 10px;
}
import React, { Component } from 'react';
import { Menu, Icon } from 'antd';
import { Link } from 'react-router-dom';
const Sidebar = () => (
<div style={{ width: '164px', padding: '20px 0px' }}>
<Menu
style={{ width: '164px' }}
defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
mode="inline"
>
<Menu.Item key="1">
<Icon type="home" />
<Link to='/'><span style={{ color: 'rgb(199, 143, 95)' }}>Home</span></Link>
</Menu.Item>
<Menu.Item key="2">
<Icon type="tags" />
<Link to='/tags'><span style={{ color: 'rgb(199, 143, 95)' }}>Tags</span></Link>
</Menu.Item>
<Menu.Item key="3">
<Icon type="team" />
<Link to='/users'><span style={{ color: 'rgb(199, 143, 95)', backgroundColor: 'yellow' }}>Users</span></Link>
</Menu.Item>
</Menu>
</div>
);
export default Sidebar;
I used antd as a ui framework. Since Link component hides the texts in the span elements i want to change the color of span elements but adding color prop doesn't have any effect.
I don't fully understand your question, but if you want to have the write "Tags" (which is also a link) written in red, you might try one these two ways:
<Link to='/tags'><span style={{ color: 'red !important' }}>Tags</span></Link>
This way, you are saying that your CSS rules should override already existing ones. Though, you should try to avoid using the !important keyword, unless extreme cases;
<Link to='/tags' class='myLink'><span>Tags</span></Link> This way, first you give a class to the link you want in red, then you need to write some a CSS rule:
a.myLink:link, a.myLink:visited, a.myLink:hover, a.myLink:active {
color: red;
}
Of course, whit this rule you will the red link anytime (if you click it, if you are hover it,..) You can customize that by dividing the CSS rules.