我在我的UI中有一个名为的元素,它始终垂直和水平居中于我的UI。我还有一个输入框,称为,我希望它始终位于下方。
在UI中,用户可以更改的大小(宽度和高度),我希望无论大小如何,都位于下方。
目前,正在显示在上方,无论大小如何。
在我的render函数中:
在我的 CSS 文件中:
在UI中,用户可以更改的大小(宽度和高度),我希望无论大小如何,都位于下方。
目前,正在显示在上方,无论大小如何。
在我的render函数中:
<div className="left-side">
<SkyElement />
<PencilInput />
</div>
< p > PencilInput
的 HTML:
<div className='pencil-input-holder'>
<div className='pencil-svg' />
<input className='pencil-input' onChange={this.handleChange} value={this.state.title} />
</div>
在我的 CSS 文件中:
@mixin absolute-center {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.left-side {
background: linear-gradient(180deg, #000000 0%, #205F8A 45.56%, #8852BB 100%);
position: relative;
.element {
@include absolute-center;
transform: scale(1.3);
transform-origin: center center;
}
}
.pencil-input-holder {
border-bottom: 4px dashed rgba(255, 255, 255, 0.3);
width: 50%;
margin: 0 auto;
.pencil-svg {
background: url('../images/pencil.svg') center center no-repeat;
width: 27px;
height: 39px;
display: inline-block;
position: relative;
top: 60px;
left: 20px;
}
}
input.pencil-input {
position: relative;
font-family: 'GT America Compressed Regular';
text-align: center;
font-size: 59px;
color: rgba(255, 255, 255, 0.5);
background: transparent;
left: 50%;
transform: translateX(-50%);
border: none;
&:focus { outline: none; }
}
希望能得到任何帮助。谢谢!
编辑:添加了SkyElement
的render()
代码块
除了下面的代码和上面的.left-side .element
代码之外,这就是SkyElement
的全部CSS。
render() {
const { connectDragSource, isDragging, hideSourceOnDrag, transformElement, top, left } = this.props;
// hide on drag in slot view
if (isDragging && hideSourceOnDrag) {
return null;
}
const halfSize = this.props.size / 2;
const transform = transformElement ? `translate(-50%, -50%)` : '';
const style = {
width: `${this.props.size}px`,
height: `${this.props.size}px`,
borderRadius: '50%',
background: this.radialGradient(),
opacity: isDragging ? 0.2 : this.props.opacity,
boxShadow: this.boxShadow(),
transform,
transition: 'background 0.2s',
position: 'relative',
top,
left,
};
return connectDragSource(
<div onClick={this.editElement} className='element' style={style}>
{
this.props.labelPosition
? <ElementLabel title={this.props.title} position={this.props.labelPosition } />
: null
}
</div>
);
}
<SkyElement />
和<PencilInput />
元素有些相互关联,至少在视觉上是这样的 - 因为您总是希望输入位于 SkyElement 下方。这正确吗? - Brett DeWoodyPencilInput
放在SkyElement
里面,它会占用SkyElement
的宽度,而我不希望这样,因为输入值可能比SkyElement
更宽。 - Zack Shapiro