react-bootstrap form margin causing overflow - css

I just got into react-bootstrap today. I want the form to be in a div with margins on left and right side. My jsx looks like this:
const Settings = () =>{
return(
<div className="content">
<div className="box">
{/* Actual form with course info */}
<Form className="course-info">
<Form.Group as={Row} controlId="formHorizontalEmail">
<Form.Label variant="settingsLabel" column sm={3}>
Course Title
</Form.Label>
<Col sm={5}>
<Form.Control/>
</Col>
</Form.Group>
</Form>
</div>
</div>
);
}
CSS:
/* A big wrapper for everything on this page */
.content{
display: flex;
align-items: center;
justify-content: center;
}
/* The box containing the class settings */
.box {
width: 600px;
height: 600px;
border: 30px solid #A6D1DF;
margin-top:50px;
}
.center-items{
margin-top: 1em;
text-align: center;
}
/* Gives the form left/right margin and sets text color */
.course-info {
padding-left: 20px;
color: #9E7772;
}
Form.Label-settingsLabel {
font-size: 1em;
color: red;
}
And the form content overflows the right-hand side of the box, and removing the margin fixes the problem.
However, I still want that margin for styling purposes. Any suggestions? Thanks

Related

How to restrict the number of items in flexbox according to screen size

I am new to grid designing on website design
In my react project, I have a row showing 3 components. One is Leverage type dot selection, Two of them are input box, Loan amount and Loan Rate.
Right now, every things seems fine in full screen, but when I shrink it, you can see that Loan Rate is placed on the next line while Loan Amount was still on above line
But what I want is, when I shrink it, it is either like this(1), or like (2) when it is super small
In(2), basically its been achieved with my existing css, when the screen is super small
Q: How could I either showing everything in the same line or showing one line with leverage type and one line with Loan Amount and Loan Rate?
Here is my code
.setting {
display: flex;
justify-content: space-between;
margin-top: 50px;
}
There are many ways we can break flex item in flexbox layout the one I have used here is flex-direction:column, this property sets every flexitem to vertically..
#media(max-width:576px) {
.flexBox {
flex-direction: column;
/*set all flexItem to vertically*/
align-items: stretch;
/* stretch will foce to take full width*/
}
}
Meaning of media(max-width:979px) means, CSS inside of that code block will only apply to screen size lessthan or equal to 979px. Means the CSS will not affect for screensize bigger than 979px.
Speaking about below code,
.flexBox .flexItem {
flex: 1 0 calc(100%/var(--number-of-items-for-midium-screen) - var(--gap-val)*2)
}
calc(100%/var(--number-of-items-for-midium-screen) - var(--gap-val)*2) here we divide 100% width with the number of items we want per row and we minus var(--gap-val) twice because we have applied gap:10px, which applied both side of .flexItem so we minus it 2 times.
And just to make CSS more friendly I have created CSS variables for
--number-of-items-for-midium-screen <= Number of items in a row
--gap-val <= gap between flex items in a row
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--number-of-items-for-midium-screen: 2;
/*Number of items you want in medium screen(below 979px)*/
--gap-val: 10px;
/*Gap you want between flex items*/
}
.flexBox {
display: flex;
align-items: center;
gap: var(--gap-val);
margin: 10px;
}
.flexBox .flexItem {
flex: 1;
border: 2px solid #d6d6d6;
padding: 10px;
}
#media(max-width:979px) {
.flexBox {
flex-wrap: wrap;
}
.flexBox .flexItem {
flex: 1 0 calc(100%/var(--number-of-items-for-midium-screen) - var(--gap-val)*2)
}
}
#media(max-width:576px) {
.flexBox {
flex-direction: column;
/*set all flexItem to vertically*/
align-items: stretch;
/* stretch will foce to take full width*/
}
}
<div class="flexBox">
<div class="flexItem">
<p>Leverage type</p>
<label for="static">static</label>
<input type="radio" value="static" id="static" name="gp1" />
<label for="dynamic">dynamic</label>
<input type="radio" value="static" id="dynamic" name="gp1" />
</div>
<div class="flexItem">
<label for="loanRate">Loan Rate</label>
<input id="loanRate" type="text" />
</div>
<div class="flexItem">
<label for="loanAmount">Loan Amount</label>
<input id="loanAmount" type="text" />
</div>
</div>
Understanding how to break layouts in flexbox
const btn1 = document.querySelector("#btn1"),
btn3 = document.querySelector("#btn3"),
btn4 = document.querySelector("#btn4");
const flexBox = document.querySelectorAll(".flexBox")[0];
const flexItems = document.querySelectorAll(".flexBox .flexItem");
const preview = document.querySelectorAll(".preview")[0];
btn1.onclick = () => {
flexBox.style.flexDirection = "column";
preview.style.display = "block";
preview.innerHTML = `.flexBox{flex-direction:column;}`;
}
btn3.onclick = () => {
flexItems.forEach(flexItem => {
flexItem.style.flex = "1";
})
preview.style.display = "block";
preview.innerHTML = `.flexItems{flex:1;}`;
}
btn4.onclick = () => {
const numberofItems = +document.querySelector("#numberofItems").value;
if (numberofItems && numberofItems >= 1 && numberofItems <= 6) {
flexBox.style.flexFlow = "initial";
flexBox.style.flexWrap = "wrap";
flexItems.forEach(flexItem => {
flexItem.style.flex = `1 0 calc(100%/${numberofItems})`;
})
preview.style.display = "block";
preview.innerHTML = `.flex{flex-wrap:wrap;}</br>.flexItems{flex:1 0 calc(100%/${numberofItems});}`;
} else {
alert("Please enter number of items you need from 1 to 6");
}
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.flexBox {
display: flex;
}
.flexItem {
display: inline-block;
height: 100px;
}
.bg-red {
background-color: red;
}
.bg-blue {
background-color: blue;
}
.bg-green {
background-color: green;
}
/*Just for styling*/
.buttons {
margin-top: 10px;
}
.buttons button {
padding: 10px;
border: 2px solid #000;
background: #fff;
text-transform: capitalize;
margin: 10px;
}
.textInput {
display: flex;
gap: 5px;
margin: 10px;
}
.textInput input {
flex: 1 0 75%;
}
.textInput button {
padding: 5px;
margin: 0;
}
.preview {
width: 100%;
border: 2px solid #000;
display: none;
padding: 30px;
}
<div class="flexBox">
<div class="flexItem bg-red">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-blue">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-green">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-red">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-blue">
<h5>This is flex box item</h5>
</div>
<div class="flexItem bg-green">
<h5>This is flex box item</h5>
</div>
</div>
<div class="buttons">
<button id="btn1">Apply flex-direction to column</button>
<button id="btn3">set all box equal size</button>
<div class="textInput">
<input type="number" id="numberofItems" placeholder="Enter the number of items you want in a row" min="1" max="6">
<button id="btn4">set items in a row</button>
</div>
</div>
<div class="preview">
<h2>Applied css</h2>
</div>

Position element in relation to a list element

I'm trying to make a pop-up options box appear next to each one of the elements of a file list. This window show the options available for that files.
I'm using an onClick function that toggle classes between one hidden and the other visible. My problem is that the box is placed always in the same place, despite the file you click, so it seems like you are always opening the options from the first file.
The React code:
return (
<div className='file-row'>
<div className='file-row-1'>
<div className='checkbox-iconFile-container'>
<input className='checkbox-folder' type="checkbox"/>
<p id={props.id} className='file-name'><img className='resourceIcon'alt='tipo de documento' src={resourceIcon}></img>{newStr}</p>
</div>
<p className='file-date'>{date}</p>
<p className='groups-file-text'>UBIP,...</p>
</div>
<div className='div-hidden-options'>
<ModalResources></ModalResources>
<div className='moreInfo-dots-container' onClick={showFileOptions}>
<img className='moreInfo-dots' alt='Opciones' src={dots}></img>
</div>
<div id='file-options' className='div-file-options-hidden'>
<p>Modificar título</p>
<p>Modificar archivo</p>
<p>Mover recurso</p>
<p>Eliminar recurso</p>
</div>
</div>
</div>
)
The showFileOptions function :
function showFileOptions () {
let optionsDiv = document.getElementById('file-options');
optionsDiv.classList.toggle('div-file-options-show');
}
And the CSS:
.div-hidden-options {
width: 15%;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.div-file-options-hidden {
visibility: hidden;
position: absolute;
}
.div-file-options-show {
visibility: visible;
position: absolute;
margin-left: 15%;
background-color: white;
border: 1px solid #DDDDDD;
padding: 5px;
border-radius: 5px;
margin-top: -36px;
}
And an image of the position that the box takes regardless of the file we click:
And this is the desirable behaviour of the box when the second file is clicked:

Vertically aligning the button with the TextField in React Material-UI

I am using the Material-UI library for React.
I am trying to make a simple form that looks like:
However, I can't figure out how to align the button with the TextField.
I tried changing the margin-top but it increases the margin of the entire wrapper.
Below is the code sandbox for it.
Any tips on getting this fixed?
https://codesandbox.io/embed/material-demo-y5eg7?fontsize=14&hidenavigation=1&theme=dark
In your styles.css file you can add {position: relative; top: 10px} to the small-button className then adjust the top value until you are happy with the position alternatively you might be able to wrap the row in a div and use {display:flex; flex-direction:row; justify-content:center;} to align them all.
Change the below styles in styles.css
.horizontal-form { /* This is newly added style */
display: flex;
align-items: center;
}
.input-text-wrapper {
/* margin-bottom: 1.2em; */ /* comment these styles */
}
.input-text-wrapper-small {
width: 33%;
/* margin-bottom: 1.2em; */
display: inline-block;
}
.small-button {
width: 10%;
/* display: inline-flex;
align-items: center; */
}
jsx
Remove the small-button div from inside the input-text-wrapper div and Then Enclose the input-text-wrapper div and small-button div inside a newly created horizontal-form div
...
</Typography>
<div className="horizontal-form">
<div className="input-text-wrapper">
<div className="input-text-wrapper-small">
...
</div>
<div className="input-text-wrapper-small">
...
</div>
<div className="input-text-wrapper-small">
...
</div>
</div>
<div className="small-button">
<Button variant="contained" color="primary">
Add
</Button>
</div>
</div>
</CardContent>
....
Just replace this line
<div className="input-text-wrapper">
with
<div className="input-text-wrapper" style={{display:"flex", alignItems:"center"}} >
AND remove margin-bottom from your style.css
.input-text-wrapper-small {
width: 30%;
/*margin-bottom: 1.2em;*/
display: inline-block;
}

Get UIKit - Append form with email address

On UIKit, How do you create an email form with an inline text so the user can input text and the form has #example.com after it.
You can do this in bootstrap here: https://getbootstrap.com/docs/4.0/components/input-group/
But I am unable to recreate this on UiKit?
Just "borrow" the concept from bootstrap. Wrap the elements within grid, group them with the class name, and inside the group add element with the flexbox display, it will fit automatically. From what I've seen in sources - they give him 1% width - maybe there's a case for that, but anyway works with only display:flex.
Here's my proposition:
HTML
<form class="uk-grid-small" uk-grid>
<div class="uk-width-1-2#s input-group">
<input class="uk-input" type="text" placeholder="50">
<div class="input-group-append">
<div class="input-group-text">
#email
</div>
</div>
</div>
</form>
CSS
.input-group {
display: flex;
}
.input-group-append {
display:flex;
align-items:center;
}
.input-group-text {
display: flex;
align-items: center;
font-weight: 400;
height:38px;
color: #495057;
padding: 0 10px 0;
text-align: center;
white-space: nowrap;
background-color: #e9ecef;
border: 1px solid #ced4da;
border-left:none;
}
I've also made a codepen for the reference https://codepen.io/arysom/pen/QzGjyo

position in reactjs with css

everyone, I am working on Reactjs project, I want to add submit button inside the input field, but I am not able to add, can anyone help me to place submit button inside input field, thanks in advance, my demo code, expected and actual outcome is attached
Reactjs code
<div className={styles.subscribeInputContainer}>
{I18n.getComponent(
(formattedValue) =>
<input
id="subscribeInput"
required={true}
value={this.state.value}
className={styles.subscribeInput}
placeholder={formattedValue}
onKeyPress={(e) => this.onKeyPress(e)}
onChange={(e) => this.onEmailChange(e.target.value)}
/>,
'footer.your-email-address',
{},
'Enter Your email address'
)}
<p className={styles.subscribeButton} id="btnId">
<Button variant="primary" className={styles.subscribeIcon} onClick={() => this.onSubscribe()}>Button</Button>
</p>
</div>
CSS code
.inputContainer {
position: relative;
}
.subscribeIcon {
position: absolute;
right: 10px;
}
.subscribeInputContainer {
display: flex;
flex-flow: row;
flex: 1;
font-size: $fontSize-lg;
color: $color-body;
}
Actual outcome
Expected Outcome
First, don't use a p as a wrapper, use a div
When you use position: absolute you take that element out of flow, and as such its parent will not take it into account when sizing itself.
If you remove position: absolute from the .subscribeIcon and add margin-left: auto to the .subscribeButton, your button should be properly right aligned within its parent, the .subscribeInputContainer.
.subscribeInputContainer {
display: flex;
flex-flow: row;
flex: 1;
border: 1px solid gray;
padding: 5px;
}
.subscribeButton {
margin-left: auto;
}
.subscribeIcon {}
<div class='subscribeInputContainer'>
<input id="subscribeInput" required={true} value={this.state.value} className={styles.subscribeInput} placeholder={formattedValue} onKeyPress={(e) />
<div class='subscribeButton' id="btnId">
<Button variant="primary" class='subscribeIcon' onClick={()=> this.onSubscribe()}>Button</Button>
</div>
</div>

Resources