html - Div 不会缩放到图像元素调整大小
问题描述
我目前正在编写一个 Web 应用程序来平衡英雄联盟锦标赛中的团队,但是在显示缓冲区符号的 gif 时遇到问题。
这是点击提交之前的表单:
这是在等待服务器响应时点击提交后的表单:
我的问题是当我加载图像时,包含它的 div 会调整为图像的原始大小,而不是重新调整后的形式。我不确定如何使 div 高度缩放到图像。
这是我用来显示图像的 ReactJS 方法,所以它是 adisplay: 'block'
或 a display: 'none'
。
render() {
return (
<img
style={{display: this.props.display ? "block" : "none"}}
src={loadGif} alt="Loading..."
className="bufferIcon"
/>
);
}
这是 img 本身的 CSS:
.bufferIcon {
max-height: 25%;
width: auto;
}
该组件存在于 RiotDevKeyForm 组件中:
render() {
return (<div className="riotdevkeyform">
<div className="text">
Enter Riot Dev Key:
</div>
<div className="input">
<form onSubmit={this.state.isLoading ? (e) => e.preventDefault() : this.handleSubmit}>
<input readOnly={this.state.isLoading ? true : false} type="text" value={this.state.key} onChange={this.handleChange}></input>
</form>
</div>
<div className="submit">
<button
style={{display: this.state.isLoading ? "none" : "block"}}
onClick={this.handleSubmit}>
Submit
</button>
</div>
<ErrorMsg
display={this.state.errMsg.length !== 0}
errMsg={this.state.errMsg}
/>
<BufferIcon
display={this.state.isLoading}
/>
</div>);
}
它具有以下 CSS:
.riotdevkeyform {
display: grid;
grid-template-areas: none;
padding: 0 auto;
margin: 0 auto;
}
.riotdevkeyform * {
margin: 0 auto;
padding: 2px;
display: flex;
justify-content: center;
font-size: 1em;
font-family: Cambria;
font-size: 12pt;
font-weight: bolder;
width: 80%;
}
.riotdevkeyform input {
padding: 0px;
width: 90%;
}
.riotdevkeyform button {
padding: 0px;
max-width: 30%;
}
这个 RiotDevKeyForm 组件也包含在另一个组件中:
render() {
return (
<div className="App">
<header className="App-header">
</header>
<div className="form">
{this.state.form_current === FormType.RIOTDEVKEYFORM && <RiotDevKeyForm onKeyAccept={this.handleKey} />}
{this.state.form_current === FormType.GETSUMMONERSFORM && <GetSummonersForm />}
{this.state.form_current === FormType.VIEWTEAMSFORM && <ViewTeamsForm />}
</div>
<BackgroundSlider
images={[image1, image2, image3, image4, image5, image6]}
duration={8}
transition={2}
/>
</div>
);
}
它具有以下 CSS:
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
}
.form {
background-color: azure;
margin: 0 auto;
padding: 5px;
top: 50%;
transform: translateY(40vh);
min-width: 15%;
min-height: 10%;
max-width: 300px;
/*max-height: 150px;*/
opacity: 75%;
border: solid black 2px;
-webkit-animation: fadeIn 1.2s ease-in-out;
animation: fadeIn 1.2s ease-in-out;
}
/* CSS Animation */
@-webkit-keyframes fadeIn {
0% {
opacity:0;
transform: scale(0.6);
}
100% {
opacity:100%;
transform: scale(1);
}
}
@keyframes fadeIn {
0% { opacity:0; }
100% { opacity:100%; }
}
解决方案
推荐阅读
- c# - 我可以将压缩文件从一个 Zip 文件复制到另一个而不解压缩和重新压缩它吗?
- python - 为什么在函数中使用print语句时赋值语句产生值而使用return时没有值?
- scala - For循环在Scala中选择一列
- database - 尝试将数据插入/更新/删除到 informix 时,ODBC 错误没有足够的空间用于解析器堆栈
- php - 来自控制器的 Laravel 过滤器数据库
- rust - 为什么没有为包装 FnMut 的`std::cell::RefMut<'_, [..]>` 实现 DerefMut?
- c# - ExcelDataReader 不读取带有逗号的浮点数,例如“123,45”(而是读取“123.45”)
- angular - 如何根据下拉列表参数生成不同的对象并创建专用网页?
- java - 使用 JLabel 添加背景图像
- oracle - APEX ORACLE 如何从链接运行 SQL 过程