How to display one html element over common boundary between other two html elements? - html

I want to display one HTML element (in my case it's the swap-button with a paired arrows) over the common border between the other two elements (in my case these are input boxes).
But my swap-button goes to the start of the page.
HTML
<div style={{
display: "flex",
flexFlow: "row",
justifyContent: "center",
alignItems: "center"
}}>
{/* origin input */}
<div
style={{
marginTop: this.state.marginTop,
border: "1px solid rgb(36, 2, 2)"
}}
>
<h5 style={{ color: "white" }}>ORIGIN OF SHIPMENT</h5>
<Dropdown name="origin" placeholder="ORIGIN OF SHIPMENT" />
</div>
{/* swap button */}
<div>
<h5>
<span style={{ display: "inline-block", width: "0px" }}>
</span>
</h5>
<Button
type="default"
size="small"
className={[this.state.css, "swap-button"]}
shape="circle"
onClick={this.onSwapLocation}
>
<Icon type="swap" />
</Button>
</div>
{/* destination input */}
<div style={{ marginTop: this.state.marginTop }}>
<h5 style={{ color: "white" }}>DESTINATION OF SHIPMENT</h5>
<Dropdown
name="destination"
placeholder="DESTINATION OF SHIPMENT"
/>
</div>
</div>
CSS
.swap-button {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
z-index: 100;
background-color: var(--whiteColor);
color: var(--blueColor);
}
Expected swap-button image: [2:
Actual swap-button image: :
I will appreciate your reply. thank you.
Edit01: I just want to show that swap-button over the other two input boxes. I have already written HTML and CSS. but when I use position: absolute the swap-button goes to start. I think I need some help in CSS (i.e. .swap-button class)

You have to add an extra container to the swap button and Destination of Shipment input so you can position the swap button precisely in the middle using position absolute just like you are doing.
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
.container {
display: flex;
flex-direction: row;
}
.swap-container {
position: relative;
}
button {
position: absolute;
background: #0084ff;
top: 10px;
left: -15px;
border: none;
border-radius: 5px;
padding: 3px;
font-size: 8px;
color: #fff;
}
input {
padding: 10px;
}
<div class="container">
<input type="text" value="Origin of Shipment"/>
<div class="swap-container">
<button>Swap</button>
<input type="text" value="Destination of Shipment"/>
</div>
</div>

input#addr_from {
border-right: 1px solid #cad3db;
}

Related

How to stretch an input to width of div without it having affect the size of a span element before it

To clarify I have a form with a span and an input:
<form onSubmit={e => handleSubmit(e)}>
<Box className='form_box'>
<span>
guest#website.com:: {'~ >>'}
</span>
<input value={user_input} onChange={e => handleChange(e.target.value)} />
</Box>
</form>
.form_box{
background-color: beige;
color: white;
display: flex;
align-items: center;
input{
border: none;
outline: none;
color: black;
background-color: white;
}
}
I want to make the input element stretch across the entire width of its parent 'form_box' div. When I try to use width: 100% it results in the span element that is in front of the input field to stretch across two lines, as if the text inside is to long for the container.
Clarity:
guest#website: ____ <- original
guest# __________________ <- what happens if i try to set width to 100%
website
Any help with a css solution greatly appreciated!
You could use a flexbox to make the last item in the Box expand to fill the remaining space:
<form onSubmit={(e) => handleSubmit(e)}>
<Box
className="form_box"
sx={{
display: "flex",
flexDirection: "row",
// make last item in flexbox fill remaining space
"& > :last-child": { flexGrow: 1 },
}}
>
<span>guest#website.com:: {"~ >>"}</span>
<input
value={user_input}
onChange={(e) => handleChange(e.target.value)}
/>
</Box>
</form>
or, if you wanted to keep your styles in a separate file:
.form_box {
background-color: beige;
color: white;
display: flex;
flex-direction: "row";
}
.form_box > :last-child {
flex-grow: 1;
}
input {
border: none;
outline: none;
color: black;
background-color: white;
display: flex;
flex-direction: row;
flex-grow: 1;
width: 1000;
}

Position a Div in Front of Another

I am trying to do something really simple here, I want a div with no border but a solid background color to be OVER a div with a border. This means I want the border around the second div to disappear behind the top div when they intersect. This is how the divs look as currently constructed:
Note here that I want DSP Name Settings to appear OVER the top border line. I have been using z-index but it changes essentially nothing. Here is my code as of right now. With the following CSS styles, that according to all Documentation, SHOULD be putting the title on top of the border as I would like, but isn't.
<div>
<div class="set-preferences-name-data-title">
<h5 class="set-preferences-name-data-title-text">DSP Name Settings</h5>
</div>
<div>
<div class="set-preferences-name-data">
<Form>
<Form.Group controlId="name" onChange={(event) => handleInput(event)}>
<Form.Control
type='name'
placeholder={"name"}
style={{
textAlign: 'center',
border: '1px black',
color: 'black',
}}
/>
</Form.Group>
<Form.Group controlId="shortcode" onChange={(event) => handleInput(event)}>
<Form.Control
type='shortcode'
placeholder={"shortcode"}
style={{
textAlign: 'center',
border: '1px black',
color: 'black',
}}
/>
</Form.Group>
<Form.Group>
<DropdownButton id="dropdown-basic-button" title={"TimeZone"}>
<Dropdown.Item><Button className="set-preferences-dropdown-button" variant="info" onClick={() => handleSetTimeZone('EST') } size='lg'>Eastern Standard Time</Button></Dropdown.Item>
<Dropdown.Item><Button className="set-preferences-dropdown-button" variant="info" onClick={() => handleSetTimeZone('CT') } size='lg'>Central Time</Button></Dropdown.Item>
<Dropdown.Item><Button className="set-preferences-dropdown-button" variant="info" onClick={() => handleSetTimeZone('MT') } size='lg'>Mountain Time</Button></Dropdown.Item>
<Dropdown.Item><Button className="set-preferences-dropdown-button" variant="info" onClick={() => handleSetTimeZone('PST') } size='lg'>Pacific Standard Time</Button></Dropdown.Item>
</DropdownButton>
</Form.Group>
</Form>
</div>
</div>
</div>
.set-preferences-name-data {
margin-left: 3%;
margin-right: 3%;
margin-bottom: 5%;
padding-top: 30px !important;
padding: 6px;
border: solid;
border-width: 2px;
border-color: '#E2E8F1' !important;
position: relative;
z-index: -100 !important;
}
.set-preferences-name-data-title {
position: absolute;
margin-top: 20px !important;
background-color: 'white' !important;
color: 'white';
border: solid;
border-width: 2px;
border-color: '#E2E8F1' !important;
z-index: 20 !important;
}
.set-preferences-name-data-title {
position: absolute;
background-color: 'white' !important;
padding-left: 3px;
padding-right: 3px;
z-index: 4 !important;
left: 36.8%;
top: 3%;
}
<div>
<div class="set-preferences-name-data-title">
<h5 class="set-preferences-name-data-title-text">DSP Name Settings</h5>
</div>
<div>
<div class="set-preferences-name-data">
<Form>
<Form.Group controlId="name" onChange={(event)=> handleInput(event)}> // I've commented out the first text input because it is irrelevant to the issue
</Form.Group>
<Form.Group controlId="shortcode" onChange={(event)=> handleInput(event)}> // I've commented out the second text input because it is irrelevant to the issue
</Form.Group>
<Form.Group>
<DropdownButton id="dropdown-basic-button" title={dsp.timeZone}>
// I removed the DropDown items since they're irrelevant to this issue
</DropdownButton>
</Form.Group>
</Form>
</div>
</div>
</div>
The code that's in question is only rendered if a specified condition is met, so I will also post the main return of the React Component so to make everything a little more clear...
return(
<div>
<h1 className="set-preferences-title">Set ScoreCard Preferences</h1>
<div>{renderNameSettings()}</div>
<div className="PrefHeaderBox">
<h2 className="set-preferences-header">
Here, you will be able to select at what point values for specific
ScoreCard values will be deemed 'fantastic', 'good' and 'fair'. Any time a value is
higher than a 'fair' descending value or lower than a 'fair' ascending one, this
value will be deemed 'subpar.' This will be reflected by what color the text pops up
in for both you and your drivers
</h2>
</div>
// The rest has been cut off since there is no relation to the rest of the component and the issue
Just set a background-color on the top div:
.set-preferences-name-data-title {
background-color: white;
}

How to change a svg image along with text with hover in CSS

I tried to change my svg image and text on hover and it doesn't work how I want it. I want the moment my mouse crosses over any of these 2 (svg or text) to change both.
Maybe I made a mistake in the html structure or maybe in css.
Please if you can help me, thanks in advance.
.logout-image {
mask: url("../../../assets/images/log-out.svg");
background-color: #62799D;
width: 20px;
height: 20px;
margin-right: 20px;
margin-left: 20px;
}
.logout-container {
display: flex;
flex-direction: row;
align-items: center;
padding: 8px 0px 8px 24px;
width: 100%;
height: 60px;
position: static;
left: 0px;
top: 280px;
color: #62799d;
margin-top: 35vh;
}
.logout-container:hover {
background: #0c2e6e;
color: white;
}
.logout-image:hover{
background: white;
}
<ul className="SidebarList">
{sidebarData.map((value, key) => {
return (
<li
className="row"
key={key}
onClick={() => {
window.location.pathname = value.link;
}}
>
{" "}
<div className="icon">{value.icon}</div>{" "}
<div className="title">{value.title}</div>
</li>
);
})}
{" "}
{" "}
//here is the problem
<li className='logout-container'>
<div className="logout-image"></div>
<div className="title" >Logo Out</div>
</li>
//until here
</ul>
This is how I wanted to change with hover:
target result
And this is how it is working right now:
current result
The background changes only if I cross over my svg image:
example here
Add this:
.logout-container:hover > .logout-image{
background: white;
}
It turns the image and words white when logout-container is hovered.

How do I align 2 components next to each other in React?

I've been building the UI for a chat room app in React. Everything was going fine until suddenly, it refreshes and the UI "broke". Basically, I have 2 components, a Sidebar component and a Chat component. I use flex to position them. Here is my code:
Sidebar.js
<div className="sidebar">
<Card className="sidebar_card left">
<Icon icon="mountain" iconSize={40} />
<div>
<Button icon="search" minimal fill large />
</div>
<div>
<Button icon="plus" minimal fill large />
</div>
</Card>
<Card className="sidebar_card right">
<div>
<h2 className="bp3-heading">Smart Labs</h2>
<Popover content={popupMenu}>
<Button icon="chevron-down" minimal />
</Popover>
</div>
<CreateRoom />
<Menu>
{rooms.map(room => (
<SelectRoom text={room.name} id={room.id} />
))}
</Menu>
<div></div>
<Button text="People" icon="new-person" minimal outlined />
<Menu>
<MenuItem text="Tony Quach" />
</Menu>
</Card>
</div>
Chat.js:
<div className="chat">
<Card className="chat_card">
<div className="chat_header">
<h2 className="bp3-heading">{roomDetails?.name}</h2>
<Divider />
</div>
<div className="chat_body">
{roomMessages.map(({ message, timestamp, user, userImage }) => (
<Message
message={message}
timestamp={timestamp}
user={user}
userImage={userImage}
/>
))}
</div>
<ChatInput roomName={roomDetails?.name} roomId={roomId} workspaceId={workspaceId} />
</Card>
</div>
Sidebar.css:
.sidebar {
display: flex;
flex: 0.2;
height: 100vh;
}
.sidebar_card {
border-radius: 0;
margin: 0;
}
.sidebar_card > div {
display: flex;
justify-content: space-between;
}
.left > div {
margin: 10px 0 0;
}
.right > div {
margin: 0 0 20px;
}
Chat.css:
.chat {
display: flex;
flex: 0.7;
height: 100vh;
}
.chat_card {
width: 100%;
border-radius: 0;
margin: 0;
}
.chat_header {
margin: 0 20px 0;
}
.chat_body {
margin: 20px 20px 0;
}
And in App.js I just do:
<div class="app">
<Sidebar />
<Chat />
</div>
App.css:
app {
display: flex;
}
I use Blueprint.js
I used border: 1px solid red to try to debug it, it seems that the Sidebar component, while only has a flex: 0.3 somehow takes up the whole width of the page and pushes Chat component down (so they stack on each other instead of align next to each other).
Any suggestions? Thank you.
I fixed it by adding position: absolute; left: 0 to Sidebar component and position: absolute; right: 0 to Chat component.

flexbox: No space between two vertical icons

Hello guys i've this layout:
Now this is what i tried:
reset padding and margin, in the <a href> and in the <img src...>
HTML container
<div>
<div className="percentage">
{percentage}%
<div className="buttonContainer">
<HandlePercentageButton add onClick={() => this.handlePercentage('add')} />
<HandlePercentageButton subtract onClick={() => this.handlePercentage('subtract')} />
</div>
</div>
<span className="labelBudget">Budget allocato</span>
</div>
HTML handlePercentageButton
<div>
<a href="#" onClick={onClick}>
{add ? <img src="https://image.flaticon.com/icons/svg/148/148790.svg" style={{ height: '15px' }} /> : null }
{subtract ? <img src="https://image.flaticon.com/icons/svg/148/148791.svg" style={{ height: '15px' }} /> : null}
</a>
</div>
and this is my actual css:
this is a little piece of a card and is main container has this css
.container {
display: inline-flex;
background-color: #FAFAFA;
border-radius: 10px;
padding: 10px;
border: 1px solid #E5E4E4
}
down below we have the percentge ( the big blue number )
.percentage {
display: flex;
color: #33BBFF;
font-size: 30px;
font-weight: 700;
padding-bottom: 5px;
}
How can i align the two buttons to the percentage number and have them
vertically spaceless ?
Use flex layout like this:
<Container
style={{
display: 'flex',
alignItems: 'center'
}}>
<LeftContainer>
<Percentage />
</LeftContainer>
<RightContainer
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
}}>
<Button type="inc" />
<Button type="sub" />
</RightContainer>
</Container>;