html - Most 'elegant' way to make 2x2 box of divs -


i've built "buzzfeed-like" quiz app 4 answer choices each question. on mobile i'm pleased layout (a 2x2 box). however, on desktop answers displaying 4 choices horizontally across screen. main issue i'm using angular generate questions , answer choices, makes styling bit trickier. ideas on how 'elegantly' code html/css displays answer choices 2x2 box? i've attempted use media queries, feels putting bandaid on large wound.

current code , 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 link */     z-index: 10; /* places link above else in div */ }  .centerer {     display: inline-block;     height: 100%;     vertical-align: middle; }  .centered {     display: inline-block;     vertical-align: middle;     color: white; } 

mobile view (preferred): mobile view

desktop view (wish mobile view): desktop view

the simplest solution markup have set width of row. selections 128px total margin of 16px set width of row double that, , maybe little more allow approximately 4px of whitespace added between inline(-block) elements.

.row {      width:300px; } 

demo

i wouldn't elegant solution, simplest fix without refactoring code. experiment float:left instead of inline block .choice:nth-child(odd){clear:both} every other element start on new row.

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -