[英]bootstrap - Make Columns heights that of the width
I have a input box which takes up 6 grid units. 我有一个输入框,它占用6个网格单元。 In height, it takes up 21.981px as in figure 1
在高度上,它占据了21.981px,如图1所示
I want to be able to have it be a square like in figure 2. How can achieve this 我希望能够使其成为如图2所示的正方形。如何实现这一目标
<form class ="form-inline">
<div class="row">
<div class="form-group col-xs-6">
<input id="p1a" type='text'
style='border: solid black 1px;'
onfocus='this.blur()'
readonly='true'
size='1'
value='❓' onclick='tristate_Marks(this)' />
</div></div>
You can use CSS for this: 您可以为此使用CSS:
body { width: 200px; height: 200px; background-color: red; } .square { width: 100%; padding: calc(50% - 21px) 0; line-height: 21px; }
<input type="text" class="square" value="test" />
Although Thomas answer is correct and worked, i changed my approach to use js 尽管Thomas的答案是正确且可行的,但我改变了使用js的方法
window.onload = function () {
var width = $("#p1a").width();
console.log(width)
$("#p1a").height(width);
}
This does not resize the box on resize,but i do not need this functionality 这不会在调整大小时调整框的大小,但是我不需要此功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.