How to stop div collapses when minimizing the screen using react bootstrap - css

I am developing a page where I am having one logo and one slogan. I need to place the logo first below that I need to place one horizontal Line and after that I need to place the slogan and below that I need to place another horizontal line. After that I need to place one button which will open the modal. At the bottom of the screen I need to keep one paragraph tag. I have brought all the above things. But the issue is when I am checking with various devices all of the styles are getting collapsed, I have tried using separate divs Rows and Columns but all results the same. Could any one help me out to sort this issue please. Thanks in advance. I have wrote the code below .
Expected Output:(Got the same output but not responsive)
LOGO
-----------------------------
SLOGAN WILL COME HERE
-----------------------------
Button
Code Starts
<div className="content">
<img
src={BackGroundImage}
alt="none"
style={{
position: "absolute",
width: "40vh",
// marginTop: "1px",
}}
/>
{/* First HR */}
<div style={{ marginTop: "13em" }}>
<hr
style={{
position: "relative",
color: "#002a54",
width: "53vh",
borderColor: "#002a54",
}}
/>
</div>
{/* First HR ends */}
{/* Content Start */}
<div style={{ marginTop: "-1em" }}>
<p style={{ fontSize: "125", color: "#002a54" }}>
INTERLOCK RELATONSHIPS TO UNLOCK VALUE
</p>
</div>
{/* Content End */}
{/* Second HR */}
<div style={{ marginTop: "-2em", position: "relative" }}>
<hr
style={{
color: "#002a54",
borderColor: "#002a54",
width: "53vh",
// marginTop: "-18px",
}}
/>
</div>
{/* Second HR ends */}
{/* Button starts */}
<div>
<Button
variant="outline-secondary"
onClick={handleShow}
style={{
background: "#D3D3D3",
color: "#002a54",
border: "2px solid #002a54",
borderRadius: "3px",
padding: "4px, 10px",
}}
>
<p
style={{
fontColor: "#002a54",
fontsize: "125",
marginBottom: "0rem",
}}
>
Contact US
</p>
</Button>
{/* Button Ends */}
</div>
<p
style={{
position: "relative",
top: "270px",
fontSize: "125",
color: "#002a54",
}}
>
UNDER CONSTRUCTION BUT OPEN FOR BUSINESS
</p>
<Modal show={show} onHide={() => setShow(false)}>
<Modal.Header closeButton>
<Modal.Title>Contact Form</Modal.Title>
</Modal.Header>
<Modal.Body>
{status && renderAlert()}
<ContactUs onSubmit={onLoginFormSubmit} />
</Modal.Body>
</Modal>
</div>
CSS:
.content {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100%;
}

Related

Layout looks correct on my phone (Android) but not friend's (iPhone)

I finished the layout of the website I'm working on, and like how it looks...
But...when my friend opens it on her iPhone, it looks like this.
I can't figure out what's causing this. If I use Chrome Developer Tools and set it to a responsive mobile format, or iPhone X, it resizes properly. Can anyone help me figure out what I'm doing wrong here?
I also had a third person look at it who told me the video isn't playing. So I'm pretty lost, not sure what I'm doing wrong since I can't reproduce the issue myself.
Here is the link if anyone wants to check.
And this is the code for the header.
import React, { useState } from "react"
import styled from "styled-components"
import { Link } from "gatsby"
import logo_image from "../../static/logo_white_trans.png"
import title_image from "../../static/title.png"
const MenuIcon = //Removed
const MenuLinks = //Removed
const Header = () => {
const [nav, showNav] = useState(false)
return (
<div id='header' style={{ height: '100%', backgroundColor: 'black', display: 'grid', gridTemplateColumns: '20% 60% 20%' }}>
<div id='logo' style={{ width: '100%' }} >
<img alt='logo' src={logo_image} style={{ maxHeight: '15vh', maxWidth: '100%', width: 'auto !important' }} />
</div>
<div id='title' style={{ position: 'relative', margin: 'auto', textAlign: 'center' }}>
<img alt='title' src={title_image} style={{ maxHeight: '15vh', maxWidth: '100%', width: 'auto !important' }} />
</div>
<div id='menu' style={{ width: '100%' }}>
<MenuIcon nav={nav} onClick={() => showNav(!nav)}>
<div />
<div />
<div />
</MenuIcon>
<MenuLinks nav={nav}>
<ul>
//Removed
</ul>
</MenuLinks>
</div>
</div >
)
}
export default Header
And here is the index code.
import React, { useState } from "react"
import Header from "./header"
import Footer from "./footer"
import "./style.css"
import VideoFile from "../../resources/vide_file.mp4"
const Index = () => {
const [nav, showNav] = useState(false)
return (
<div style={{ display: "flex", flexDirection: "column" }}>
<Header style={{ alignItems: "flex-start" }}>
</Header >
<video loop autoPlay muted style={{ preload: 'auto', height: "75vh", objectFit: "cover", display: "block", margin: "0 auto", alignItems: "stretch" }}>
<source src={VideoFile} type="video/mp4" />
</video>
<Footer style={{ alignItems: "flex-end" }}>
</Footer>
</div>
)
}
export default Index
A slight tweak to the margin property on your div id='title' element fixes the issue:
margin: '0 auto'
Remember that margin: 'auto' centers elements horizontally and vertically. I believe what's happening is Chromium is properly centering the element within the direct parent container, in this case:
<div id="header" style="height:100%;background-color:black;display:grid;grid-template-columns:20% 60% 20%"></div>
Safari instead is going a level up and centering the element on the grandparent, which is the full viewport height:
<div style="display:flex;flex-direction:column"></div>
Specifying a '0' margin above and below the element forces Safari to move the logo back to the top of the parent element.

ButtonGroup gap isn't uniform

I'll have 5 buttons in a group (labled: one, two, three, four, five) in a row. Between the buttons three and four is a larger gap than between other buttons. I'm assuming it has something to do with fractional width buttons creating larger gaps. I also tried manually doing margins. Same exact issue.
Image of the issue:
Storybook mdx:
<div style={{display: 'flex', flexDirection: "column"}}>
<div style={{paddingBottom: "15px", }}>
<Label>I'm the parent and this is the currently selected value(s) a recieved by the onChangeSelected prop: {JSON.stringify(values)}</Label>
</div>
<div style={{display: "flex", justifyContent: "center"}}>
<ButtonGroup onChangeSelected={(selectedValue: string[])=> handleOnSelect(selectedValue)} selectedValuesProp={passedValue} groupClass={args.groupClass} groupSize={args.groupSize} vertical={args.vertical} >
<Button value={ "one"}>one</Button>
<Button value={ "two"}>two</Button>
<Button value={ "three"}>three</Button>
<Button value={ "four"}>four</Button>
<Button value={ "five"}>five</Button>
</ButtonGroup>
</div>
<div style={{display: "flex", justifyContent: "center", marginTop: "15px"}}>
<Button onClick={()=> setPassedValue([])}>I clear the button group</Button>
</div>
</div>
relevant scss:
.btn-group {
#include font-defaults;
display: inline-flex;
// Force the buttons to adopt the overall group radius
border-radius: $button-group-border-radius;
overflow: hidden;
box-shadow: $button-shadow;
gap: 2px;
>.btn {
flex: 1 1 auto;
// Turn off the normal button radius and shadow that's now on the group
border-radius: 0;
box-shadow: none;
}
.btn-group-selected {
background-color: $accent-bg;
&:hover {
background-color: $accent-bg-hover;
}
&:active {
background-color: $accent-bg-active;
}
}
}
Any help would be much appreciated.

How can i set an inline style margin according to a condition?

So I have my layout from Ant design and on the profile page theres one div at the top which has user's info.
Under it, there are many divs (one for each post), essentially mapping a post array into post divs.
Problem is, ive struggled with centring them to the middle of the page but after messing around with flex, i thought i did a good job in the end. It looked perfect at first when the user has no posts underneath the profile div. The moment there's posts, the profile div goes to the left alot for some goddamn reason.
The posts are perfectly centered like i want them but my problem is with the profile div. To fix it, i did a margin-left on the it. This makes it look perfect. But not so fast. Now when theres no posts, its awfully to the right cuz it was perfectly centered before the margin-left
So is there any way i can pass in a condition to say if posts.length === 0, and set the margin-left accordingly?
Losing my head.
Layout.js code:
<Content style={{ padding: '0 50px' }}>
<Breadcrumb style={{ margin: '16px 0' }}>
<Breadcrumb.Item>Home</Breadcrumb.Item>
<Breadcrumb.Item>Network</Breadcrumb.Item>
</Breadcrumb>
<div className="site-layout-content" style={{ background: "#fff ", padding: 24, minHeight: 280, display:"flex", alignItems:"center", flexDirection: "column"}}>
{children}
</div>
</Content>
UserProfile.js code :
<div>
<div className="site-card-wrapper" style={{display: "inline-block",marginBottom:20, width: 500, marginLeft:355}}>
<Row gutter={16} type="flex" style={{justifyContent: "center", }}>
<Col span={16}>
<Card title={user.username} bordered={true} style={{border: "1px solid #cccccc",}}>
<div style={{display:"flex", justifyContent: "space-between"}}>
<CardContent>Followers: {user.followers === undefined ? "0" : user.followers.length}</CardContent>
<CardContent>Following: {user.following === undefined ? "0" : user.following.length}</CardContent>
</div>
</Card>
</Col>
</Row>
</div>
{
(userPosts.length > 0) ?
<Heading>Posts</Heading> :
<Heading>No posts yet</Heading>
}
{
userPosts.map(post => {
return <SinglePost key={post.id} post={post} />
})
}
</div>
SinglePost.js code (simplified):
<div className="site-card-wrapper" style={{marginBottom:20, width: 1200,}}>
<Row gutter={16} type="flex" style={{justifyContent: "center"}}>
<Col span={16} >
<Card title={user.username} bordered={true} style={{border: "1px solid #cccccc"}}>
<div style={{fontSize: 18, marginTop: -10, whiteSpace: "pre-line"}}>
{post.content}
</div>
<Likes>{likes} Likes</Likes>
</Card>
</Col>
</Row>
</div>
<div className="site-card-wrapper"
style={
{display: "inline-block",
marginBottom:20,
width: 500,
marginLeft:posts.length === 0 ? 0 : 355
}}>
use above conditional statement to handle run time marginLeft

How to start the second div at the end of the first div.?

<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ zIndex: 1050, backgroundColor: '#fafafb', height: '50px', position: 'fixed', width: '100%'}}>
</div>
<div style={{ position: 'relative' ,height: '250px', backgroundColor: 'green' }}>
</div>
</div>
The second inner div height is only 200px the remaining 50px is inside the first inner div but i want to start the second div at the end of the first div?
You first div is positioned fixed , that means its out of the flow. Hence the second div pushed to top.
You could set the top of the second div by the height of the first:
const Example = () => (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ zIndex: 1050, backgroundColor: '#fafafb', height: '50px', position: 'fixed', width: '100%'}}>
</div>
<div style={{ position: 'relative', top: '50px' ,height: '250px', backgroundColor: 'green' }}>
</div>
</div>
);
ReactDOM.render(<Example />, document.getElementById('root'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root" />

having a hard time getting the width of an Li parent element, child cannot inherit width?

Screenshot:
I currently have this code:
<li
style={{
border: '1px solid rgba(0, 0, 0, 0.05)',
width: '100%',
}}
key={uuidV4()}
>
<span style={{ width: 'inherit' }}> // setting it to 100% or inherit, dont change anything
<span style={{ width: '90%' }}>{`${toTitleCase(column)} `}</span>
<span style={{ width: '10%' }}>
<Button
style={{
width: '25px',
fontSize: '18px',
padding: '0',
borderRadius: '50%',
}}
color="link"
onClick={e => this.addActiveColumn(e, column)}
>
<i
style={{
borderRadius: '50%',
backgroundColor: '#ffffff',
color: '#343A40',
}}
className="fa fa-plus-circle"
aria-hidden="true"
/>
</Button>
</span>
</span>
</li>
I wanted the text to have 90% width of the li element, then the + button to have 10% so the + button will be on the rightest side properly aligned, but the result is not what I am expecting. Help?
<span> is an inline element by default, to which the width property doesn't affect. You can change it to display: inline-block or display: block'
Check this codepen to see what I mean

Resources