Javascript 如何使用样式化的组件在标题中保持按钮的正确性?
我正试着按好那个按钮,但我不知道怎么做。有人能帮我吗?我尝试了Javascript 如何使用样式化的组件在标题中保持按钮的正确性?,javascript,css,reactjs,styled-components,Javascript,Css,Reactjs,Styled Components,我正试着按好那个按钮,但我不知道怎么做。有人能帮我吗?我尝试了position:right打开HomeButton,但没有效果。这是我的密码: Header.styles.js import styled from 'styled-components'; export const Wrapper = styled.div` display:flex; background-color: #a86332; padding: 1%; ` export const Titl
position:right
打开HomeButton
,但没有效果。这是我的密码:
Header.styles.js
import styled from 'styled-components';
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
`
export const Title = styled.h1`
color: white;
margin:0;
`
export const HomeButton = styled.button`
border:2;
margin:10px 10px 10px 0;
height: 50px;
width: 50px;
background-color:#a86000;
border-color:white;
color:white;
cursor:pointer;
transition-duration:250ms;
&:hover{
height: 70px;
width: 70px;
margin:0 0 0 0;
color:black;
background-color:white;
border-color: red;
}
`
import React from 'react'
import { HomeButton, Title, Wrapper } from './Header.styles'
const Header = () => {
return (
<Wrapper>
<Title>McKing Burger</Title>
<HomeButton >Home</HomeButton>
</Wrapper>
)
}
export default Header
Header.js
import styled from 'styled-components';
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
`
export const Title = styled.h1`
color: white;
margin:0;
`
export const HomeButton = styled.button`
border:2;
margin:10px 10px 10px 0;
height: 50px;
width: 50px;
background-color:#a86000;
border-color:white;
color:white;
cursor:pointer;
transition-duration:250ms;
&:hover{
height: 70px;
width: 70px;
margin:0 0 0 0;
color:black;
background-color:white;
border-color: red;
}
`
import React from 'react'
import { HomeButton, Title, Wrapper } from './Header.styles'
const Header = () => {
return (
<Wrapper>
<Title>McKing Burger</Title>
<HomeButton >Home</HomeButton>
</Wrapper>
)
}
export default Header
从“React”导入React
从“./Header.styles”导入{HomeButton,Title,Wrapper}
常量头=()=>{
返回(
麦金汉堡
家
)
}
导出默认标题
屏幕截图使用
调整内容:在每个项目之间留出空间
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
justify-content: space-between;
`
或者在按钮上添加
align self:flex end
。使用对齐内容:间距
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
justify-content: space-between;
`
或者将align self:flex end
添加到按钮。您可以通过将这些CSS规则应用到包装器来实现:
display: flex;
flex-direction: row;
justify-content: space-between;
您可以通过将这些CSS规则应用于包装器来实现这一点:
display: flex;
flex-direction: row;
justify-content: space-between;
你可以解决你的问题
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
justify-content: space-between;
`
你可以解决你的问题
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
justify-content: space-between;
`
像这样使用display flex:
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
display:flex;
justify-content: space-between;
`
它将同时获取标题和主页按钮并将它们分开,将标题保留在左侧,按钮保留在右侧:)使用display flex,如下所示:
export const Wrapper = styled.div`
display:flex;
background-color: #a86332;
padding: 1%;
display:flex;
justify-content: space-between;
`
它将同时获取标题和主页按钮并将它们分开,将标题保留在左侧,按钮保留在右侧:)
只需将“justify content”属性添加到包装样式中即可。:)
只需将“justify content”属性添加到包装样式中即可。:) 你可以通过几种方式来实现
首先通过证明内容:之间的空格代码>
export const Wrapper = styled.div`
display:flex;
justify-content: space-between;
`
第二到右:0
:
export const Wrapper = styled.div`
position: absolute;
top: 10px;
right:0;
`
第三,通过这种方式justify内容:flex-end代码>
export const Wrapper = styled.div`
display: flex;
justify-content: flex-end;
`
你可以通过几种方式来做
首先通过证明内容:之间的空格代码>
export const Wrapper = styled.div`
display:flex;
justify-content: space-between;
`
第二到右:0
:
export const Wrapper = styled.div`
position: absolute;
top: 10px;
right:0;
`
第三,通过这种方式justify内容:flex-end代码>
export const Wrapper = styled.div`
display: flex;
justify-content: flex-end;
`
非常感谢你!非常感谢你!非常感谢你!非常感谢你!非常感谢你!非常感谢你!非常感谢你!非常感谢你!非常感谢你!非常感谢你!