【发布时间】:2014-08-17 22:54:26
【问题描述】:
我已经构建了一个“类似 Buzzfeed”的测验应用,每个问题都有四个答案选项。在移动设备上,我对布局(2x2 盒子)感到非常满意。 但是,在桌面上,答案只是在屏幕上水平显示为 4 个选项。 主要问题是我使用 Angular 来生成所有问题和答案选择,这使得样式有点棘手。 关于如何“优雅地”对 html/css 进行编码以便它始终将答案选择显示为 2x2 框的任何想法?我尝试使用媒体查询,但感觉就像在大伤口上贴了创可贴。
当前代码和图片如下:
HTML:
<div class="jumbotron text-center" ng-hide="quizComplete">
<h3>{{ questions[number].ask }}</h3>
<div class="row">
<div ng-repeat="answer in questions[number].answers" class="choice">
<div ng-click="recordChoice(answer.points)">
<span class="centerer"></span>
<span class="centered">{{ answer.choice }}</span>
</div>
</div>
</div>
</div>
CSS:
.choice {
position: relative;
display: inline-block;
width: 128px;
height: 128px;
margin: 8px;
background: rgba(183,222,237,1);
background: -moz-linear-gradient(45deg, rgba(183,222,237,1) 0%, rgba(33,180,226,1) 49%, rgba(113,206,239,1) 92%, rgba(183,222,237,1) 100%);
background: -webkit-gradient(left bottom, right top, color-stop(0%, rgba(183,222,237,1)), color-stop(49%, rgba(33,180,226,1)), color-stop(92%, rgba(113,206,239,1)), color-stop(100%, rgba(183,222,237,1)));
background: -webkit-linear-gradient(45deg, rgba(183,222,237,1) 0%, rgba(33,180,226,1) 49%, rgba(113,206,239,1) 92%, rgba(183,222,237,1) 100%);
background: -o-linear-gradient(45deg, rgba(183,222,237,1) 0%, rgba(33,180,226,1) 49%, rgba(113,206,239,1) 92%, rgba(183,222,237,1) 100%);
background: -ms-linear-gradient(45deg, rgba(183,222,237,1) 0%, rgba(33,180,226,1) 49%, rgba(113,206,239,1) 92%, rgba(183,222,237,1) 100%);
background: linear-gradient(45deg, rgba(183,222,237,1) 0%, rgba(33,180,226,1) 49%, rgba(113,206,239,1) 92%, rgba(183,222,237,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b7deed', endColorstr='#b7deed', GradientType=1 );
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
cursor: pointer;
cursor: hand;
}
.choice div {
position: absolute;
background: transparent;
width: 100%;
height: 100%;
padding: 5px;
top: 0;
left: 0;
text-decoration: none; /* No underlines on the link */
z-index: 10; /* Places the link above everything else in the div */
}
.centerer {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.centered {
display: inline-block;
vertical-align: middle;
color: white;
}
移动视图(首选):
桌面视图(希望看起来像移动视图):
【问题讨论】:
-
使用
@media查询? -
您的演示确实没有说明问题是什么,但@media 不是创可贴的解决方案。 :-)
-
抱歉没有更清楚。我通过添加屏幕截图编辑了上面的帖子。无论屏幕尺寸如何,我的目标都是 2X2 布局。
-
在两个框后使用
<br>标签 -
以后请删除与问题无关的代码。您的渐变属性只是无意义的混乱,会分散实际问题的注意力。