Align IconButton with Text in a line - css

I need to put IconButtons together with plain text in one single text. However, it didn't show as I expected. Here is what I did:
JS(ReactJS):
<div>
<span>
<h3>Title</h3>
<IconButton className="editBtn" size="small">
<EditIcon style={{ fontSize: 25 }} />
</IconButton>
<IconButton className="deleteBtn" size="small">
<DeleteIcon style={{ fontSize: 25 }} />
</IconButton>
</span>
<p>Article</p>
</div>
CSS:
.deleteBtn {
padding: 3vw !important;
color: #e71f1f !important;
width: 5vh;
border: black;
}
.editBtn {
padding: 3vw !important;
color: #4ddd40 !important;
width: 5vh;
border: black;
}

It's tough to troubleshoot without access to the components and context but this code example might help give some cues for a direction to consider.
.deleteBtn {
padding: 32px;
color: #e71f1f;
border: black;
}
.editBtn {
padding: 32px;
color: #4ddd40;
border: black;
}
.inline {
display: inline-block;
}
<div>
<h3>Title</h3>
<button className="editBtn" size="small">
Edit
<span>icon</span>
</button>
<button className="deleteBtn" size="small">
Delete
<span>icon</span>
</button>
<span>Article</span>
</div>
<br/>
<br/>
<div>
<h3 class="inline">Title</h3>
<button className="editBtn" size="small">
Edit
<span>icon</span>
</button>
<button className="deleteBtn" size="small">
Delete
<span>icon</span>
</button>
<span>Article</span>
</div>

It just looks like there's no way to put buttons and header in the same line. Instead, I worked around by using tag.
<div>
<span>
<strong>Title</strong>
<IconButton className="editBtn" size="small">
<EditIcon style={{ fontSize: 25 }}/>
</IconButton>
<IconButton className="deleteBtn" size="small">
<DeleteIcon style={{ fontSize: 25 }}/>
</IconButton>
</span>
<p>Article</p>
</div>

Related

How do I make a button span across 2 columns?

I'm working on a calculator app, and there are very specific things that I want for it. I want the colors of the buttons to vary and I want the "0" button to span across the two front columns so that the buttons beside it will be the same size as the rest. I think that just looks better. I have tried many things and none of them worked. I created my own button component and here is all the code that I think is necessary to show:
This is my App.js file
return (
<div className='App'>
<div className='calculator'>
<ResultBar />
<div className='row'>
<Button color="#625C5D" symbol="Clear" />
<Button color="#625C5D" symbol="+/-" />
<Button color="#625C5D" symbol="%" />
<Button color="#B04929" symbol="/" />
</div>
<div className='row'>
<Button symbol="7" />
<Button symbol="8" />
<Button symbol="9" />
<Button color="#B04929" symbol="x" />
</div>
<div className='row'>
<Button symbol="4" />
<Button symbol="5" />
<Button symbol="6" />
<Button color="#B04929" symbol="-" />
</div>
<div className='row'>
<Button symbol="1" />
<Button symbol="2" />
<Button symbol="3" />
<Button color="#B04929" symbol="+" />
</div>
<div className='row'>
<Button style={{columnSpan: 2}} symbol="0"/>
<Button symbol="." />
<Button color="#B04929" symbol="=" />
</div>
{/* <div className='display'>
{result ? <span>({result})</span> : '0'}
</div> */}
{/* <div className='keyboard'>
</div> */}
</div>
</div>
);
This is my button component
import "./Button.css";
const Button = ({ symbol, color }) => {
return (
<div style={{ backgroundColor: color }} className="button-styles">
{symbol}
</div>
);
}
export default Button;
And here's the css for the button
.button-styles {
height: 4em;
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(229, 143, 82);
color: white;
font-size: 24px;
flex: 1;
margin: 4px;
border-radius: 16px;
}
At first I tried making a classname called button-span-two and added the line
grid-column: span 2;
Then I tried adding a property like symbol and color in the button component to add to the styles that would represent the number of columns to span. I tried using both gridColumn and columnSpan for this. Then I tried making a separate component with its own css file called ButtonSpan that would basically be the same as my button component but with a grid-column property set to 1/3. None of these worked. The calculator stayed the same with each try.

Center component vertically and horizontally in 'Antd' library not working

I have a weird issue where I can't center a Row vertically in my screen.
The Card I have is perfectally centered horizontally but not vertically. How can I do that ?
I used the Row component which has align='middle' to align vertically but it isn't working
Here is my implementation:
<Row align='middle' justify='center'>
<Col span={18}>
<Card>
{/* <img className='login-logo' src={logo} alt='logo' /> */}
<Text size='30px' type='BOLD'>
QIFF DASHBOARD
</Text>
<Form name='login' onFinish={formik.handleSubmit}>
<Form.Item>
<Input
id='email'
name='email'
label='Email'
placeholder='Email'
type='email'
autoComplete='new-email'
onBlur={formik.handleBlur}
onChange={formik.handleChange}
value={formik.values.email}
/>
{formik.errors.email ? <Text>{formik.errors.email}</Text> : null}
</Form.Item>
<Form.Item>
<Input
id='password'
name='password'
placeholder='Password'
type='password'
autoComplete='new-password'
onBlur={formik.handleBlur}
onChange={formik.handleChange}
value={formik.values.password}
/>
{formik.errors.password ? <Text>{formik.errors.password}</Text> : null}
</Form.Item>
<div className='submit-button'>
<Button
htmlType='submit'
onClick={formik.handleSubmit}
style={{ width: '100%', backgroundColor: '#f85940', color: 'white' }}
>
Sign in
</Button>
</div>
</Form>
</Card>
</Col>
</Row>
<Row align='middle' justify='center'></Row>
Presumably, the Row tag does not set the attribute display:flex
So justify='center' is invalid
The following solutions can be used:
1、Child element (Need to be centered vertically)
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
2、 <Row style="display:flex"></Row>

React-bootstrap how to horizontally center an element only taking account of it's parent

Hello, I am using react-bootstrap library. I want to center the search bar and button on the navbar. But while centering, it's also taking into account the sibling element (logo) and leaning towards the right of the page. I don't want to solve this by applying brute force minus margin-left if possible. I'm confused with these justify-content stuff. Thanks in advance.
<Navbar style={{ backgroundColor: "#D3D3D3" }}>
<Nav className="d-flex justify-content-start">
<NavbarBrand href="/">
<img src={logo} alt="pokedex-logo" style={{ width: 250, marginLeft: 20 }} />
</NavbarBrand>
</Nav>
<Nav className="d-flex flex-grow-1 justify-content-center">
<Form className="d-inline-flex">
<FormControl
type="search"
placeholder="Type pokemon name"
value={search}
onChange={e => setSearch(e.target.value)}
/>
<Button
style={{ backgroundColor: "#ffe031", color: "#396bba" }}
onClick={() => history.push(`/pokemon/${search}`)}
>
<strong>Search</strong>
</Button>
</Form>
</Nav>
</Navbar>
Try it like this:
<Navbar style={{ backgroundColor: "#D3D3D3", display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'start' }}>
<NavbarBrand href="/">
<img src={logo} alt="pokedex-logo" style={{ width: 250 }} />
</NavbarBrand>
<Form className="" style={{ margin: 'auto' }}>
<FormControl type="search" placeholder="Type pokemon name" value={search} onChange={e => setSearch(e.target.value)}/>
<Button style={{ backgroundColor: "#ffe031", color: "#396bba" }} onClick={() => history.push(`/pokemon/${search}`)}>
<strong>Search</strong>
</Button>
</Form>
</Navbar>
Here, the Navbar has display flex and the flex direction is row so the logo along with the 2 search elements (text field and search button) will be shown in a row. Then alignItems:'center' centers these 3 elements vertically in the Navbar and the justifyContent: 'start' moves the 3 elements to the start of the Navbar horizontally.
After this, to make the 2 elements of search come in the center, margin:'auto' is used in the Form.
And here's another way: (if the above code doesn't correctly align the search elements in center)
<Navbar style={{ position: 'relative', display: 'flex', backgroundColor: "#D3D3D3" }}>
<NavbarBrand href="/" style={{float: 'left'}}>
<img src={logo} alt="pokedex-logo" style={{ width: 250 }} />
</NavbarBrand>
<Form style={{ float: 'none', position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}>
<FormControl type="search" placeholder="Type pokemon name" value={search} onChange={e => setSearch(e.target.value)} />
<Button style={{ backgroundColor: "#ffe031", color: "#396bba" }} onClick={() => history.push(`/pokemon/${search}`)}>
<strong>Search</strong>
</Button>
</Form>
</Navbar>
In this code, the CSS properties of position and float are used. float: 'left' moves the logo to the left and the search elements have float: 'none'. The search elements use the position property to align to the center of the Navbar which has position: 'relative'.

Dropdown menu pops below whole site instead of under button

I'm developing a simple website using Angular 5 and Angular Materials. My site has one dropdown menu that is above whole content of my site, used to set sorting criteria. The problem is, when I try to open it, the menu opens itself all the way at the bottom of my site. What could be the cause of it?
Here is .html used for this site:
<mat-card >
<mat-card-header id="game-list-menu">
<div id="game-list-menu-left">
<button mat-button [matMenuTriggerFor]="sortMenu">Sort by: {{sortBy}}</button>
<mat-menu #sortMenu="matMenu">
<div id="game-list-menu-sort">
<button mat-menu-item (click)="changeSort(1)">Name</button>
<button mat-menu-item (click)="changeSort(2)">Platform</button>
<button mat-menu-item (click)="changeSort(3)">Rating</button>
</div>
</mat-menu>
</div>
<div id="game-list-menu-title">Game List</div>
<div id="game-list-menu-right">
<form #searchForm="ngForm" (ngSubmit)="search(searchForm.value)">
<mat-form-field>
<input matInput [(ngModel)]="searchGame.name"
required name="name" #name>
</mat-form-field>
<button mat-raised-button color="primary" type="submit"
[disabled]="!searchForm.form.valid">Search</button>
<button mat-raised-button color="primary" (click)="searchForm.reset(); showAll()">
<span>Show all</span>
</button>
</form>
</div>
</mat-card-header>
<mat-card-content id="game-list-container">
<mat-card class="game-list-item" *ngFor="let game of games">
<mat-card-header>
<mat-card-title>{{game.name}}</mat-card-title>
<mat-card-subtitle>{{game.platform}}</mat-card-subtitle>
</mat-card-header>
<img mat-card-image src="{{game.gameCoverPath}}" alt="{{game.name}} cover">
<mat-card-content>
<p>Rating:</p>
<span *ngFor="let goldstar of getIterator(game.rating)">
<img src="https://dl.dropbox.com/s/ngxkbxyy8hmpbaw/Star_gold.png?dl=0" height="20px" width="20px"/>
</span>
<span *ngFor="let greystar of getIterator(5 - game.rating)">
<img src="https://dl.dropbox.com/s/pnuorfnn75xib3o/Star_grey.png?dl=0" height="20px" width="20px"/>
</span>
<p></p>
</mat-card-content>
<mat-card-actions>
<button mat-button [routerLink]="['/game-details', game.id]">Details</button>
<button mat-button>Edit</button>
</mat-card-actions>
</mat-card>
</mat-card-content>
<mat-card-actions id="container_actions">
<button mat-fab color="primary" [routerLink]="['/game-add']">+</button>
</mat-card-actions>
</mat-card>
Here is CSS used for this site:
.game-list-item {
max-width: 300px;
padding: 25px;
margin: 10px;
display: inline-block;
}
#container_actions {
text-align: right;
padding: 25px;
}
.game-list-item mat-card-title {
font-size: 24px;
font-weight: bold;
}
.game-list-item mat-card-subtitle {
font-size: 18px;
}
.game-list-item mat-card-header {
display: inline;
}
.game-list-item .mat-card-content {
padding: 15px 0 0 0;
}
.game-list-item mat-card-actions {
text-align: right;
}
#game-list-menu {
}
#game-list-menu div {
display: inline;
padding: 20px;
width: 33%;
}
#game-list-menu-left {
text-align: left;
}
#game-list-menu-title {
}
#game-list-menu-right {
text-align: right;
}
#game-list-menu-sort {
}
Here is styles.scss file used for whole project:
#import url("https://fonts.googleapis.com/css?family=Karla");
* {
font-family: 'Karla', serif;
}
h1 {
width: auto;
text-align: center;
font-size: 50px;
}
mat-card-header {
width: auto;
text-align: center;
font-size: 35px;
}
Add this to your style.css
#import '~#angular/material/prebuilt-themes/deeppurple-amber.css';

React/HTML5: How to avoid details tag from being wrapped to next row after openning it?

Hello and thank you for your time!
I am learning how to use flex and React.
I am facing a curious situation. Currently there is a detail component which aim is to open/close controls:
<details className="spaced-column" style={{
backgroundColor: "green",
flexWrap: "nowrap"
}}>
<summary>Controles</summary>
<div>
<Dropdown options={this.options} onChange={this._onSelect}
placeholder="Select an option"/>
</div>
<div className="row">
<label><input type="checkbox" id="chbox1" value="1"/>Option 1</label>
<label><input type="checkbox" id="chbox2" value="2"/>Option 2</label>
</div>
<div className="row">
<label><input type="checkbox" id="chbox3" value="3"/>Option 3</label>
<label><input type="checkbox" id="chbox4" value="4"/>Option 4</label>
</div>
<div className="column-right-aligned">
<Button incrementValue={1} onClickFunction={this.incrementCounter}/>
<Button incrementValue={5} onClickFunction={this.incrementCounter}/>
<Button incrementValue={10} onClickFunction={this.incrementCounter}/>
<Button incrementValue={100} onClickFunction={this.incrementCounter}/>
<Result counter={this.state.counter}/>
</div>
</details>
Also, spaced-column class is:
.spaced-column {
display: flex;
flex-direction: column;
justify-content: space-between;
}
The need is to keep the component in the same row
Currently when we open the details flow to the next row. 😲
When window is at maximum size, details are the green div on the right:
When details are opened they still in the same row:
When we resize, the controls either close or opened flow to the next row:
I have read for further details: https://developer.mozilla.org/es/docs/Web/CSS/flex-wrap
https://www.w3schools.com/tags/tag_details.asp
https://www.w3schools.com/html/html5_new_elements.asp
So then I tried, as you saw on the photos and code, to use:
style{{flexWrap:"nowrap"}}
I susspect that it could be related to gray and yellow divs (which are canvas) and have their size using the viewport as:
.imgPreview {
text-align: center;
margin: 5px 15px;
height: 80vh;
width: 40vw;
border-left: 1px solid #000000;
border-right: 1px solid #000000;
border-top: 5px solid #000000;
border-bottom: 5px solid #000000;
}
Would you mind to help me to solve this question? I would appreciate an explanation more than the solution itself!
I have found a solution but I do not understand it well, it was just pure try and error: 😖😖😖
The full code of the two canvas and details:
<main>
<header>
<h3>Suba una imagen desde el ordenador, para mostrarla:</h3>
</header>
<article className="multi-line-no-spaced-row">
<section className="multi-line-row">
< section className="spaced-column" style={{
backgroundColor: 'gray',
}}>
<ImageUpload onChange={this.setFileFromUrl} file={this.state.file}
upload={this.state.upload}/>
</section>
<section className="spaced-column" style={{
backgroundColor: 'yellow',
}}>
<ImageUpload onChange={this.setFileFromUrl} file={this.state.file}
upload={this.state.upload}/>
</section>
</section>
<details className="spaced-column" style={{
backgroundColor: "green",
flexWrap: "nowrap"
}}>
<summary>Controles</summary>
<div>
<Dropdown options={this.options} onChange={this._onSelect}
placeholder="Select an option"/>
</div>
<div className="row">
<label><input type="checkbox" id="chbox1" value="1"/>Option 1</label>
<label><input type="checkbox" id="chbox2" value="2"/>Option 2</label>
</div>
<div className="row">
<label><input type="checkbox" id="chbox3" value="3"/>Option 3</label>
<label><input type="checkbox" id="chbox4" value="4"/>Option 4</label>
</div>
<div className="column-right-aligned">
<Button incrementValue={1} onClickFunction={this.incrementCounter}/>
<Button incrementValue={5} onClickFunction={this.incrementCounter}/>
<Button incrementValue={10} onClickFunction={this.incrementCounter}/>
<Button incrementValue={100} onClickFunction={this.incrementCounter}/>
<Result counter={this.state.counter}/>
</div>
</details>
Also the CSS classes:
.multi-line-row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.multi-line-no-spaced-row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.spaced-column {
display: flex;
flex-direction: column;
justify-content: space-between;
}
So then, as you would imagine I just changed flex-wrap: nowrap; to both rows:
.multi-line-row {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.multi-line-no-spaced-row {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
Also I do not like how detail's children look cramped:
How could we expand the detail's width to full size, to make it ocuppy al the width after opening it?

Resources