reactjs - 屏幕宽度变化时内容对齐方式不同(React、Bootstrap)
问题描述
我正在使用引导程序来帮助调整我的内容并使其具有响应性。我已经想出了如何使它全部与中心对齐,但是当我将其调整为较小的宽度时,它开始向左对齐。即使屏幕宽度随引导程序发生变化,如何使其与中心对齐?我是使用 React 的 Bootstrap 新手,但我想用它来节省 CSS 样式的时间。
return (
<Container>
<Row className='justify-content-md-center'>
<Col md='auto'>
<img
className='img'
src='https://angel.co/images/recruit/Flashlight.png'
alt='flashlight'
/>
</Col>
</Row>
<Row className='justify-content-md-center'>
<Col md='auto'>
<p className='heading'>There are no jobs posted</p>
</Col>
</Row>
<Row className='justify-content-md-center'>
<Col md='auto'>
<p className='paragraph'>
Your next best candidate is waiting for you. We have thousands of
applicants looking for a new journey. Post a job now to get access.
</p>
</Col>
</Row>
<Row className='justify-content-md-center'>
<Col md='auto'>
<a href='default.asp' target='_blank' onClick={form}>
<p className='link'>Post a job</p>
</a>
</Col>
</Row>
</Container>
)
解决方案
移动设备在 Bootstrap 中具有最高优先级。当您设置时,它会为(xs --> sm --> md --> lg --> xl --> xxl)<Col md='auto'>
之后的那些断点应用布局,因此尺寸不会得到样式。此外,您应该使用而不是集中所有屏幕尺寸的所有内容。md
xs
sm
justify-content-center
justify-content-md-center
这是您的组件的正确实现:https ://codesandbox.io/s/react-bootstrap-demo-forked-2sdi2?file=/src/App.js
推荐阅读
- c++ - 如何将类成员函数的返回类型设置为私有结构的对象
- javascript - 如何在反应中停止我的列表的这种奇怪的输出
- spring - spring boot 以接口为 bean 实现
- c++ - 如何创建具有独特形状的自定义、即时、箭头形工具提示?
- javascript - 通过 pactjs 发送时不接受 aww4 凭据
- javascript - Django:给 Stripe ACH 存款验证错误的最佳方法
- python - python html解析器不返回链接
- javascript - Javascript - 将 .onkeypress 输入推送到数组
- javascript - 从javascript更新html中的表
- php - 如何修复在 wordpress 中调用未定义函数 get_woocommerce_currency()?