I've built a "Buzzfeed-like" quiz app with four answer choices for each question. On mobile I'm very pleased by the layout (a 2x2 box). However, on desktop the answers are simply displaying as 4 choices horizontally across the screen. The main issue is that I'm using Angular to generate all the questions and answer choices, which makes styling a bit trickier. Any ideas on how to 'elegantly' code the html/css so it always displays the answer choices as a 2x2 box? I've attempted to use media queries, but it feels like putting a bandaid on a large wound.
Current code and images below:
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;
}
mobile view (preferred):
desktop view (wish to look like mobile view):
` tag after two boxes – Dan Aug 17 '14 at 23:21
` tag is not neccesary and appart from using tables would be the least elegant way of solving the problem. This can be solved easily with CSS. If the OP then wants to change the style again he has to change the markup and CSS instead of CSS alone. – Jon P Aug 17 '14 at 23:52