【发布时间】:2016-10-14 06:11:37
【问题描述】:
我在我的项目中使用 Bootstrap 并尝试从 Bootstrap col 制作一个正方形,但它不起作用,并且它的宽度大小和高度大小总是不同的差距,例如 94.11px 和 94px。
我想让比例为 1:1 宽度:高度。但没用
HTML
<div class="content_image col-xs-3 squarethis"></div>
<div class="content_description col-xs-9 followheight"></div>
JavaScript
var st = $('.squarethis').width();
$('.squarethis').css({'height':st+'px'});
$('.followheight').css({'height':st+'px'});
有人知道吗?
var st = $('.squarethis').width();
$('.squarethis').css({'height':st+'px'});
$('.followheight').css({'height':st+'px'});
.squarethis{
width:30%;
float:left;
background:#ccc;}
.followheight{
width:70%;
float:left;
background:#999;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="squarethis">asd</div>
<div class="followheight">asd</div>
下图
【问题讨论】:
-
究竟是什么“不起作用”?
-
它的宽度和高度尺寸之间存在差距,例如 94.11 像素和 62 像素。 @Rayon
-
你能分享一个例子/小提琴吗?
-
@Rayon 我不能总是显示“消息”:“未捕获的 ReferenceError:$ 未定义”,当我把它放在 JsFiddle 中时
-
在使用时包含
jQuery库;)
标签: javascript html twitter-bootstrap css height