I want to display a border when I hover box1.
When I hover, the border is displayed, but for a moment, a black border is displayed.
Also, when I hover, the layout shifts to the bottom.
If anyone knows how to fix this, please let me know.
codesandbox
import "./styles.css";
import styled from "styled-components";
const Box = styled.div`
padding: 9px 18px;
cursor: pointer;
display: inline-block;
color: #222426;
&:hover {
border: solid #e2e6ea 1px;
transition: all 0.2s cubic-bezier(0.08, 0.52, 0.52, 1);
}
span {
cursor: pointer;
font-weight: bold;
font-size: 20px;
line-height: 20px;
color: #222426;
}
`;
const App = () => {
return (
<>
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
<Box>
<span>box1</span>
</Box>
<div>
<span>aaaaaaa</span>
</div>
<div style={{ width: "full", height: "100px", background: "red" }}></div>
</>
);
};
export default App;
In CSS, you can set box-sizing: border-box;
Then set your span's height then it won't shift to the bottom.
The alternative way is making a white border, and change its color when hover.
I found you have "transition: all 0.2s cubic-bezier(0.08, 0.52, 0.52, 1);" This actually causes the black border flicked for a second. If you remove it, the black border will be gone. However, I am not sure what effect do you want to achieve here.
If you add a border with the same background colour and same thickness inside the div i.e border: solid #fff 1px;
The div will not push other component downward anymore.
Related
I have seen that similar posts already exist... the solutions posted there did not work for me tho. Sorry for asking again.
In my gatsby project I want a solid border and border-radius on an image. On Chrome it looks as expected but on mobile devices and Safari the image just does not get the rounded corners and overflows the border. How can I fix this?
.imgContainer {
border: solid 1px #0784b5;
border-radius: 10px;
overflow: hidden;
}
.img {
position: relative;
border-radius: 10px;
top: 0;
left: 0;
}
<div className={styles.imgContainer}>
<GatsbyImage className={styles.img}
image={data.file.childImageSharp.gatsbyImageData}
alt="portrait"
/>
</div>
Thanks in advance!!
The gatsby-image package is now deprecated
You can use: https://www.gatsbyjs.com/plugins/gatsby-plugin-image/
Ex:
import { StaticImage } from 'gatsby-plugin-image';
const IndexPage = () => (
<StaticImage
src="../images/test_image.jpg"
alt=""
imgStyle={{ borderRadius: '20%' }}
/>
);
I have the following react component:
import "./App.css";
function App() {
return (
<div className="App">
<div className="TopBar">
<div style={{ color: "green" }}>Rooms</div>
<div>Chats</div>
<div>User</div>
</div>
</div>
);
}
export default App;
However, the TopBar class in App.css:
.TopBar {
display: flex;
flex-direction: row;
border-width: 1;
border-color: gray;
}
seems to not be applied. The divs are showing in a column rather than a row. The border isn't showing either. How to fix this?
For the border to render, you may need to first indicate the border style in your CSS. For example: border-style: solid or border: 1px solid gray.
Otherwise, your code should work. Here is a working sandbox using your code. https://codesandbox.io/s/react-component-styling-oy9m2
I am currently having an issue trying to render a white apple pay button in a react app. Here is the html
<div style={{width: "100%", height: "auto", backgroundColor: 'white'}} className="apple-pay-button-with-text apple-pay-button-white-with-text">
<span class="text">Buy with</span>
<span class="logo"></span>
</div>
And then the css
.apple-pay-button-with-text {
cursor: pointer;
display: inline-block;
margin-top: 15px;
margin-bottom: 15px;
-webkit-appearance: -apple-pay-button;
-apple-pay-button-type: buy;
-apple-pay-button-style: white;
}
.apple-pay-button-with-text > * {
display: none;
}
.apple-pay-button-black-with-text {
-apple-pay-button-style: black;
}
.apple-pay-button-white-with-line-with-text {
-apple-pay-button-style: white-outline;
}
.apple-pay-button-white-with-text {
-apple-pay-button-style: white;
}
The issue I am running into is that once this is rendered in browser, white gets converted into it's hex value, which -apple-pay-button-style does not recognize so it renders a black apple pay button. I can use white-outline and that obviously doesn't get converted, but it is not the desired style. Is there anyway to prevent the name white from being converted into it's hex value?
I have vue project.
Every time some elements on the page disappear because of v-if the rest of the page is slightly rearranged. I want it to happen smoothly.
All elements have :key attribute.
Example:
I have centred 2 boxes in one row. When one is gone, the second one is still centred, so changes position.
image
How to handle this?
EDIT 1
I tried:
<div>
<CompoentA :key=345 class="one-line" v-show="showComponentA" />
<transition name="moving">
<CompoentB class="one-line" :key=123 />
</transition>
</div>
.one-line { display: inline-table; }
.moving-move { transition: transform 1s; }
v-if will remove the element from the DOM, so you can't animate your disappearing components.
You should use v-show instead if you want to animate them (they will stay hidden in the DOM).
I think that you need "from" and "to" values to create this animation. When you remove the elemnt from DOM, the other elements will be placed based on a "inline" position, so there is no value reference to create a transition.
There is a similar problem here, where a transition with height:0 and height: auto
How can I transition height: 0; to height: auto; using CSS?
I made a sample to solve this using a width (bigger than content) and width 0 with opacity 0 to hide the inner content. To run this sample, simple click in items, it will be "removed" (opacity:0 and width: 0) and the transition works because there is a initial width set (80px).
new Vue({
el: "#app",
data: () => ({
// yes, there is better ways, but let make this sample "simple"
letters: ['a', 'b', 'c', 'd'],
visible: {
a: true,
b: true,
c: true,
d: true,
}
})
})
#app {
/* decoration, you can remove */
width: 100%;
text-align: center;
background-color: #f4f4f4;
}
.moving {
/* margin and padding 0
because the width content will be set to 0
if this element has a margin, when removed the margin still display the "space"
*/
padding: 0;
margin: 0;
font-size: 0; /* remove white space in DOM element */
display: inline-block;
opacity: 1;
transition: width linear .2s;
/* decoration, you can remove */
width: 80px;
border: 1px dotted #ccc;
cursor: pointer;
}
.moving-content {
font-size: 18px; /* restore font size */
display: inline-block;
/* decoration, you can remove */
background-color: #2af;
color: white;
padding: 20px;
box-sizing: border-box;
}
.moving.hidden {
width: 0px;
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div v-for="letter in letters"
:key="letter"
:class="{ moving: true, hidden: !visible[letter] }" #click="visible[letter] = false">
<span class="moving-content">
{{ letter }}
</span>
</div>
</div>
References:
https://stackoverflow.com/a/40785144/1724128
https://stackoverflow.com/a/53127208/1724128
I want to get the image and text in the same div I have tried using float left and display inline-block but of no use I cant get the mistake where I am doing.
I am getting the output as follows
I used styled components in reactjs.
These are the styled components I have used
export const BannerContainer = styled.div`
width: 1280px
height: 448px
margin: auto
`
export const BannerImageContainer = styled.div
height:448px
width:640px
float: left
export const BannerImage = styled.img
padding:96px 96px 96px 96px
margin-left:128px
export const BannerTextContainer = styled.div
height:448px
width:512px
margin-right:128px
float: left
export const BannerHeaderText = styled.h1
width: 352px
height: 64px
padding-top:40px
font-family: Nunito
font-size: 28px
font-weight: 600
line-height: 1.14
text-align: center
export const BannerParagraphContainer = styled.p
width: 389px
height: 72px
opacity: 0.38
font-family: Nunito
font-size: 16px
line-height: 1.5
text-align: center
color: #000000
export const SeeAllProductsButton = styled.button
width: 160px
height: 32px
background-color: #7C6ECC
color: #FFFFFF
border: 0px
margin: 32px 112px
This is the code for rendering it
<BannerContainer>
<BannerImageContainer>
<BannerImage src={bannerImage} />
</BannerImageContainer>
<BannerTextContainer>
<BannerHeaderText>
Solving the most common problems in marketing
</BannerHeaderText>
<BannerParagraphContainer>
Exquisite codially mr happiness of neglected distrusts.
Boisterous impossible unaffected he me everything.
</BannerParagraphContainer>
<SeeAllProductsButton>See All Products</SeeAllProductsButton>
</BannerTextContainer>
</BannerContainer>
Try using FlexBox!
Very simple implementation to get you going:
<div style={{display: 'flex'}}>
<div style={{flex: '1'}}>
<BannerImageContainer>
<BannerImage src={bannerImage} />
</BannerImageContainer>
</div>
<div style={{flex: '1'}}>
<BannerTextContainer>
<BannerHeaderText>
Solving the most common problems in marketing
</BannerHeaderText>
<BannerParagraphContainer>
Exquisite codially mr happiness of neglected distrusts.
Boisterous impossible unaffected he me everything.
</BannerParagraphContainer>
<SeeAllProductsButton>See All Products</SeeAllProductsButton>
</BannerTextContainer>
</div>
</div>
Just to add a bit more info, this is a really popular css component (not specific to React) for aligning things properly. Just googling 'flexbox' will give you a lot of info, but some specific links are here and here