Padding in Sass making Material UI icon disappear - reactjs

I am creating an image slider in React. I'm using Material UI arrow icons as the left and right buttons.
Everything is working fine until I try and add padding.
Before adding the padding, I can see two white circles with my arrows. As soon as I add the padding, the white circles get bigger but the arrows inside disappear.
return (
<div className="container">
<div
className="slider"
style={{ transform: `translateX(-${currentSlide * 100}vw)` }}
>
<img src={images[0]} alt="" />
<img src={images[1]} alt="" />
<img src={images[2]} alt="" />
<img src={images[3]} alt="" />
</div>
<div className="arrows">
<KeyboardArrowLeftOutlinedIcon className="arrow" onClick={prevSlide} />
<KeyboardArrowRightOutlinedIcon className="arrow" onClick={nextSlide} />
</div>
</div>
)
And this is the sass file:
.container {
width: 100vw;
height: 60vh;
overflow: hidden;
position: relative;
.slider {
width: 400vw;
height: 100%;
display: flex;
transition: all 1s ease;
img {
width: 100vw;
height: 100%;
object-fit: cover;
}
}
.arrows {
position: absolute;
height: 100%;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
gap: 80%;
top: 0;
.arrow {
cursor: pointer;
background-color: white;
border-radius: 2em;
padding: 1em;
}
}
}

It seems that a possible solution could be wrap the arrow icons with div, and style the wrapper.
Minimized demo of below example on: stackblitz (without functionality, and uses plain CSS)
Example:
<div className="arrows">
<div className="arrow">
<KeyboardArrowLeftOutlinedIcon />
</div>
<div className="arrow">
<KeyboardArrowRightOutlinedIcon />
</div>
</div>
Also some changes in Sass would be needed to match it, such as:
.arrows {
position: absolute;
inset: 0;
display: flex;
justify-content: space-between;
align-items: center;
.arrow {
cursor: pointer;
background-color: white;
border-radius: 2em;
margin: 0.75em;
padding: 0.5em;
display: flex;
justify-content: center;
align-items: center;
}
}

Related

Fit items in a div evenly and without space in react app

So, I was doing a react project "Amazon Clone". But I was struck here, I want to have mexican and american pizza in same row with no space left and both of them occupy same width. Please dont recommend to do width:50%, because in the consecutive rows I have 3 items in that row where each one occupies 33% of width. How do I do this?
Home.js
</div>
<div className="home_row">
<Product title="Mexican Pizza" rating={3} image="https://m.media-amazon.com/images/I/61ZjaqqnocS._AC_SY200_.jpg" price="100"/>
<Product title="Mexican Pizza" rating={2} image="https://m.media-amazon.com/images/I/51ZBqKhH4nL._AC_SY200_.jpg" price="60"/>
<Product title="Mexican Pizza" rating={4}image="https://m.media-amazon.com/images/I/71Zf9uUp+GL._AC_SY200_.jpg" price="60"/>
</div>
<div className="home_row">
<Product title="Yonex Nanoray" rating={3}image="https://images-eu.ssl-images-amazon.com/images/I/71WtW9tk4ZL._AC_UL160_SR160,160_.jpg" price="60"/>
</div>
</div>
Home.css
body{
background-color: #eaeded;
}
.homebanner{
width: 100%;
}
.home{
margin-left: auto!important;
margin-right: auto;
max-width: 100%;
}
.home_row{
display: flex;
flex-wrap:row wrap;
justify-content: center;
width: 100%;
margin: auto;
z-index: 1;
margin-left: auto;
margin-right: auto;
}
Product.js
{title}
${price}
</div>
<div className="product_rating">
{Array((rating)).fill().map((_,i)=>(
<p>⭐</p>)
)}
</div>
<img src={image} alt="" />
<Button className='addbtn' variant="contained">Add to Cart</Button>
</div>
Product.css
.product {
display: flex;
flex-direction: column;
background-color: white;
z-index: 1;
align-items: center;
margin: 10px;
padding: 30px;
border: 5px solid white;
}
.product_info {
width: 100%;
}
.product>img {
max-height: 200px;
object-fit: contain;
margin-bottom: 15px;
}
.product_rating {
margin-top: -25px;
margin-bottom: 20px;
display: flex;
align-items: center;
}
.addbtn {
background-color: #ffc73b !important;
color: black !important;
font-family: 'Amazon Ember', sans-serif;
}
.addbtn:hover {
background-color: #ffc73b !important;
color: black !important;
}

Structuring Sidebar in React

Relatively new to React, and am wanting to recreate the design below
enter image description here
I have the base formatting down, but as you will notice, there are lines separating the logo blocks, from the login and signup blocks, with the signup and login buttons pushed to the bottom.
Below is my current code
CSS:
width: 100vw;
height: 100vh;
}
body {
margin: 0;
padding: 0;
}
.Sidebar {
height: 100%;
width: 20%;
background-color: white;
border-right: 1px solid #F0F4FB;
padding-left: 15px;
box-sizing: border-box;
}
.SidebarList {
height: auto;
width: 100%;
padding-left: 15px;
font-size: 18px;
border: 2px #FD954E;
box-sizing: border-box
}
.SidebarList .row {
width: 100%;
height: 50px;
background-color: white;
list-style-type: none;
margin: 0%;
padding-bottom: 15px;
display: flex;
color: #A7ACB6;
justify-content: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
}
.SidebarList .row:hover {
cursor: pointer;
background-color: #E7E7E7 ;
}
.SidebarList #active {
background-color: white;
color: #FD954E
}
.SidebarList .Login {
background-color: white;
color: #FD954E;
width: 279px;
height: 39px;
right: 1596px;
top: 958px;
border: 1px solid #FD954E;
box-sizing: border-box;
border-radius: 19.5px;
}
.SidebarList .SignUp {
width: 279px;
height: 39px;
right: 1596px;
top: 1011px;
background: #FD954E;
border-radius: 19.5px;
border: none;
}
.row #icon {
flex: 30%;
display: grid;
place-items: center;
transform: scale(1.2)
}
.row #title {
flex: 70%;
}
.Logo {
padding-left: 25px;
padding-top: 25px;
padding-bottom: 30px;
border-bottom: 1px solid #F0F4FB;
width: 55%;
}
Sidebar.js
import React from "react";
import "../App.css";
import { SidebarData } from './SidebarData'
import Logo from './Logo.svg'
function Sidebar() {
return (
<div className="Sidebar">
<div>
<img src = {Logo} alt='Logo’ className=‘Logo’ />
</div>
<ul className="SidebarList">
{SidebarData.map((val, key) => {
return (
<li
key={key}
className="row"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="icon">{val.icon}</div> <div id="title">{val.title}</div>
</li>
);
})}
</ul>
<div className= "SidebarList">
<button className="Login">
Login
</button>
</div>
<div className= "SidebarList">
<button className="SignUp">
Sign Up
</button>
</div>
</div>
);
}
export default Sidebar;
How should I structure my code in order to acheive my desired result? Ex: with the logo at the top with the seperator, the list of navigation elements, and then the login and signup buttons at the bottom with the seperator?
Currently, my sidebar looks as follows, with the seperator not full width between the logo and navigation elements, and the buttons extending beyond the sidebar.
enter image description here
It would be easier to simplify the problem with just HTML and CSS as that's much easier to troubleshoot. Part of your problem is that you are defining the width of the sidebar as a percentage of the screen width but elements within the sidebar are defined with a width in pixels. When the browser window is too small, your buttons will appear outside the full width of the sidebar. You could either code all your values as percentages or in pixels. Alternatively, you could use a mix and just set a min-width for the sidebar so that you don't end up with elements out of place.
The reason that your line break is not the full width of your sidebar is because you are defining it with the border-bottom property of the logo. Your logo is not 100% the width of the sidebar so your line break will only be the width of the logo. A better solution would be to define a div that is set to width: 100%. This way, you will have more control.
Here is a simplified solution to your sidebar problem using pixels to define the widths.
HTML:
<div class="sidebar">
<div class="header">
<div class="logo">Logo</div>
</div>
<div class="line-break" />
<div class="content">
<ul class="nav">
<li>Home</li>
<li>Blog</li>
</ul>
</div>
<div class="line-break" />
<div class="footer">
<button class="login">Login</button>
<button class="sign-up">Sign up</button>
</div>
</div>
CSS:
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.sidebar {
width: 300px;
height: 100%;
border-right: 1px solid grey;
}
.line-break {
height: 1px;
width: 100%;
background-color: grey;
}
.header .logo {
height: 40px;
width: 200px;
background-color: grey;
margin: 20px;
}
ul.nav {
list-style-type: none;
padding: 20px 0 0 40px;
}
ul.nav li {
margin-bottom: 14px;
}
ul.nav li:last-child {
margin-bottom: 0;
}
.footer {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 0;
}
.footer button {
padding: 6px 0;
width: 80%;
margin-bottom: 14px;
}
.footer button:last-child {
margin-bottom: 0;
}
And here is a link to a CodePen
where you can see this in action.

React Router Link in image extends beyond image?

The Link for my image extends beyond the image itself:
There is a blank space between the edge of the image and the next element, which is a Tabs from Material UI I called TradingTabs.
This is what my code looks like:
import { Link } from "react-router-dom";
...
<div className="header">
<div className="header-left">
<Link to="/">
<img
className="header-logo"
src={logo}
alt=""
/>
</Link>
<TradingTabs />
</div>
<div className="header-middle">
...
.header{
display: flex;
width: 100%;
align-items: center;
height: 60px;
justify-content: space-between;
position: sticky;
top: 0;
z-index: 100;
background-color: white;
border-bottom: 1px solid lightgray;
}
.header-left{
margin-left: 2%;
display: flex;
width: 500px;
align-items: center;
}
.header-logo{
width: 30%;
}
How can I fix it so the Link only wraps the actual size of the image?

CSS 3rd div height based on 1st

I'm trying to find a right solution for stacking different height divs. Tried grid, flex and lastly inline-block.
From what i understand 3rd div(button) is attatched to the bottom of a 2nd div(image). I'm trying to make so it would be attatched to the bottom of a 1st div(text).
Button is being drawn as 3rd div is because button has to go under an image when window size gets too small. Can you even achive this with inline-block?
My current code:
https://jsfiddle.net/mep2x67L/16/
#container {
padding-top: 50px;
padding-bottom: 50px;
display: inline-block;
position: relative;
width: 100%;
height: 100%;
}
#desccription {
width: calc(50% - 20px);
margin-left: 20px;
display: inline-block;
vertical-align: top;
}
#desccription_Container {
margin: 0 auto;
justify-content: left;
text-align: left;
max-width: 560px;
margin-right: 10px;
}
#half_img {
width: 100%;
}
#img_container {
width: 49%;
display: inline-block;
}
.btnWrap {
display: inline-block;
width: 355px;
vertical-align: top;
text-align: center;
}
#normal_text {
font-size: 36px;
line-height: 42px;
color: #F1ECE3;
}
#btnWrap {
display: inline-block;
width: 355px;
vertical-align: top;
text-align: center;
}
<div id="container">
<div id="desccription">
<div id="desccription_Container">
<div id="normal_text"> hello hello </div>
</div>
</div>
<div id="img_container">
<img id="half_img" src="https://wallpapercave.com/wp/6K44j5E.jpg">
</div>
<div id="btnWrap">
<button type="button">Button!</button>
</div>
</div>
All you need to do is float your image div right - below I have commented the line I added. I have also added a clear fix and changed the width of the button wrap so it works on smaller screen sizes.
#container {
padding-top: 50px;
padding-bottom: 50px;
position: relative;
width: 100%;
height: 100%;
}
#container:after { /* clear fix */
content: '';
display: block;
height: 0;
overflow: hidden;
clear: both;
}
#desccription {
width: calc(50% - 20px);
margin-left: 20px;
display: inline-block;
vertical-align: top;
}
#desccription_Container {
margin: 0 auto;
justify-content: left;
text-align: left;
max-width: 560px;
margin-right: 10px;
}
#half_img {
width: 100%;
}
#img_container {
width: 49%;
display: inline-block;
float:right; /* add this */
}
#normal_text {
font-size: 36px;
line-height: 42px;
color: #F1ECE3;
}
#btnWrap {
width: calc(50% - 20px); /* I would make this the same size as desccription */
vertical-align: top;
text-align: center;
}
<div id="container">
<div id="desccription">
<div id="desccription_Container">
<div id="normal_text"> hello hello </div>
</div>
</div>
<div id="img_container">
<img id="half_img" src="https://wallpapercave.com/wp/6K44j5E.jpg">
</div>
<div id="btnWrap">
<button type="button">Button!</button>
</div>
</div>
You can use Grid - it's super easy, and you can control the position and grid layout with just media queries, etc. And it requires much less CSS when you learn how to use grid properly.
To learn about flexbox, I'd recommend this source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Similarly, to learn CSS grids, there is: https://css-tricks.com/snippets/css/complete-guide-grid/
It'll take about a day of your time, and you'll get a great grasp of how grids and flexbox work, helping you create better designs in the future.
For the current example, see the fiddle with CSS-grids:
https://jsfiddle.net/5u69aaun/
#container {
padding-top: 50px;
padding-bottom: 50px;
display: grid;
grid-template-rows: auto 1fr;
grid-template-columns: 1fr 1fr;
width: 100%;
height: 100%;
}
#description{
padding-left: 20px;
padding-right: 10px;
grid-row: 1;
grid-column: 1;
text-align: left;
}
#description_Container{
max-width: 560px;
}
#half_img {
width: 100%;
}
#img_container {
grid-row: 1 / 3;
grid-column: 2;
}
.btnWrap{
grid-row: 2;
grid-column: 1;
}
#normal_text{
font-size: 36px;
line-height: 42px;
color: red;
}
#btnWrap{
text-align: center;
}
<div id="container">
<div id="description">
<div id="description_Container">
<div id="normal_text"> hello hello </div>
</div>
</div>
<div id="img_container">
<img id="half_img" src="https://wallpapercave.com/wp/6K44j5E.jpg" >
</div>
<div id="btnWrap">
<button type="button">Button!</button>
</div>
</div>

How to set image and paragraph in the middle in table row / Material UI

I made a table using material UI. I added images and paragraph in the same row. The problem is that both of them do not align in the same height.
They should be shown in the middle of row.
Current view is like below.
The height of Logo of master card and 'Master card' do not match..
Here is my code for table.
<TableRow className="tableRow">
<TableRowColumn className="tableOne">{this.props.payment=="PayPal"?
<div className="failSample"> <img src={Fail} alt="Fail" className="Fail"/></div> : <div className="checkSample"><img src={Check} alt="Check" className="Check"/></div> }</TableRowColumn>
<TableRowColumn className="tableTwo">{this.props.date}
</TableRowColumn>
<TableRowColumn className="tableThree">{this.props.payment=="Visa" ? <div><div className="visaSample"><img src={Visa} alt="Visa" className="Visa"/></div> </div>: (this.props.payment=="PayPal" ? <div className="paypalSample"><img src={Paypal} alt="Paypal" className="Master"/></div> : <div className="masterSample"> <img src={Master} alt="Master" className="Master"/></div>)}
{this.props.payment}</TableRowColumn>
<TableRowColumn className="tableFour">{this.props.narrative}</TableRowColumn>
<TableRowColumn className="tableFive">{this.props.amount}</TableRowColumn>
<TableRowColumn className="tableSix"><div className="dotmenuSample"><img src={Dotmenu} alt="Dotmenu" className="Dotmenu" onClick={this.handleTouchTap} /> </div></TableRowColumn>
CSS
.Master, .Visa, .Paypal {
height: auto;
width: 100%;
float: left;
}
.visaSample {
padding-top: 40px;
height: 20px;
width: 20px;
display: table-cell;
}
.masterSample {
padding-top: 20px;
height: 30px;
width: 30px;
}
.paypalSample {
padding-top: 20px;
height: 30px;
width: 20px;
}
Try using flexbox will solve your problem
.flex-container {
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.flex-container > div {
margin: 0 10px;
text-align: center;
}
<div class="flex-container">
<div>img</div>
<div>text</div>
</div>
Try this inside your <TableRowColumn

Resources