I have this material-ui container example below the text is simply sticking to the upper top of the container, how to add margin to push it down ? also how to add a margin Right/Left to the container since it is taking up the whole screen.
export default function FixedContainer() {
return (
<React.Fragment>
<CssBaseline />
<Container fixed>
<Typography
component="div"
style={{
backgroundColor: "#cfe8fc",
height: "100vh",
marginTop: "122px"
}}
>
This must have a margin top not the conatainer
</Typography>
</Container>
</React.Fragment>
);
}
To add spacing between your text and the top of the container, padding would be better to use in the styles prop, instead of margin.
style={{
backgroundColor: "#cfe8fc",
height: "100vh",
paddingTop: "122px"
}}
The maxWidth prop in the Container component can be used to assign the width to the container.
I've created a sandbox example out of your code.
Related
I have a MUI Accordion in my React project, and I would like for it to collapse when the user clicks somewhere else on the page.
I would like to do this via css, as I am doing the following via css:
.focus {
/* border: 2px solid red !important; */
background-color: white !important;
}
<Accordion>
<AccordionSummary
focusVisibleClassName='focus'
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<TextField
style={{ width: 350 }}
id="entityName"
value={entity.entityName}
onChange={(event) => {
setEntity({ ...entity, entityName: event.target.value });
}}
/>
</AccordionSummary>
<AccordionDetails sx={{ borderTop: '1px dashed black', width: 400 }}>
<Typography>
Source
</Typography>
<TextField sx={{ width: 350 }}></TextField>
<Typography>
Classification
</Typography>
<TextField sx={{ width: 350 }}></TextField>
</AccordionDetails>
</Accordion>
I appreciate your assistance.
I have searched on this requirement, and not found any results.
You can implement ClickAwayListener component to detect when a click event happens outside of its child element. And to get the current state of the expended prop you have to add onChange prop to your Accordion component, and finally make use of expanded prop to set its value (true/false). Please take a look at the code below for a better understanding. also, a working example was added as a link.
Import:
import ClickAwayListener from '#mui/material/ClickAwayListener';
And inside your function:
const [open, setOpen] = useState(false);
const handleClickAway = () => {
if(open){
setOpen(false);
}
};
return (
<ClickAwayListener onClickAway={handleClickAway}>
<Accordion expanded={open} onChange={(e,expanded)=>{setOpen(expanded)}}>
<AccordionSummary
focusVisibleClassName='focus'
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<TextField
style={{ width: 350 }}
id="entityName"
value={entity.entityName}
onChange={(event) => {
setEntity({ ...entity, entityName: event.target.value });
}}
/>
</AccordionSummary>
<AccordionDetails sx={{ borderTop: '1px dashed black', width: 400 }}>
<Typography>
Source
</Typography>
<TextField sx={{ width: 350 }}></TextField>
<Typography>
Classification
</Typography>
<TextField sx={{ width: 350 }}></TextField>
</AccordionDetails>
</Accordion>
</ClickAwayListener>
);
https://codesandbox.io/s/mui-accordion-clickoutside-kmg1eb?file=/demo.js
I'm wondering if there's a better way to set the height of a grid row in Ionic 5 than simply overriding the default styles. Including an extra style to every row that I need to have a specified height is a bit tedious, and it seems like there should be a better way.
<IonGrid style={{ height: "100%" }}>
<IonRow style={{height: "100%"}}>
<IonCol>Hi</IonCol>
<IonCol>Hi Again</IonCol>
<IonCol>Hi A third time</IonCol>
</IonRow>
</IonGrid>
There are many ways to do that, for example in the .scss file add:
ion-grid {
height: 120px;
ion-row{
height: 20px;
}
ion-col {
border: 0.3px solid #f4f4f4;
}
}
And also "extra style":
ion-row.myHeight{
height: 40px;
}
When I used the HTML attribute background: linear-gradient(angle, color-stop1, color-stop2) to add the gradient effect to an image in huawei quick app, the gradient color does not take effect, but it can apply to the text element for a quick app.
The image is opaque. Therefore, even if the gradient background is set, it cannot be seen because it is covered by the image above.
You can set the stack element as a parent of the image element, set the div element to cover the image element, and set the gradient background on the div element. (You do not need to set the gradient background on the image element.)
The code for implementation is as follows:
<template>
<!-- Only one root element is allowed in template. -->
<div class="container">
<stack>
<image src="/Common/img/compress.png" style="width: 100%; height: 300px"></image>
<div style="width: 100%; height: 300px;background: repeating-linear-gradient( rgba(255, 0, 0, .5),rgba(0, 0, 255, .5));"></div>
</stack>
<text style="background: repeating-linear-gradient( rgba(255, 0, 0, .5),rgba(0, 0, 255, .5));"> nice scene, beautiful </text>
</div>
</template>
Final Effect
For more information, please refer to:
Gradient style of the quick app
Quick app materials
I want to disable the scroll bar in the semantic page (master) and add a scroll to the list in semantic:content only, so my goal is to prevent scroll in the header of the semantic page.
enableScrolling="false" doesn't exist in sap.f.semantic.semantic page
checking the API there is no parameter for disabling thescrollbar.
I would try something like this:
limit content: if <content> doesn't exceed the full height, no scrollbar will be visible (try sap.ui.table.Table with visibleRowCount)
scroll: add scroll container (ScrollContainer) to the content
Example for scroll:
<semantic:SemanticPage
class="noScroll"
id="mySemanticPage"
headerPinnable="false"
toggleHeaderOnTitleClick="false"
preserveHeaderStateOnScroll="true"
showFooter="{/showFooter}">
<!-- Content -->
<semantic:content>
<ScrollContainer
class="myContainer"
height="100%"
width="100%"
horizontal="true"
vertical="true"
focusable="true">
css:
.noScroll .sapFDynamicPageContent {
padding: 0;
height: 100%;
}
.noScroll .sapFDynamicPageContent > div {
padding: 0;
height: 100%;
}
I am trying to modify the width and height on popover material ui but nothing ? please help thanks
open={open}
anchorEl={anchorEl}
className={{
height: '300px',
width: '250px'
}}
anchorOrigin={{
vertical: 'top',
horizontal:'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}
disableRestoreFocus
>
Use the PaperProps property of Popover:
<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
value={value}
anchorOrigin={{
vertical: 'top',
horizontal: 'center',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'center',
}}
PaperProps={{
style: { width: '100%' },
}}
The easiest way of doing that is to stretch the content inside the Popover, because it's width is calculated automatically.
<Popover>
<div
style={{
width: '300px',
height: '200px'
}}
>
Some inside content
</div>
</Popover>
And that will stretch Popover itself to desired size.
In your code you have the className equal to css, this will not work. You can either change the className to style, and it should work or you're going to have to add a const variable and hook it into the withStyle HOC. Then add the height and width to that const, and then call the class you made in that to the className.
All these examples are on the material-ui site. https://material-ui-next.com/getting-started/faq/ I've found extremely helpful.
Try to change style of this class name on your css file .MuiPaper-elevation8 like :
.MuiPaper-elevation8{
width: 300px;
height: 150px;
}