0

I had a requirement to put 2 image within a band on a page and then make it responsive to various screen sizes. So below a and b would represent these images and the band in red. The gap between a and b needed to remain proportional tho a and b were of slightly different width as A was a circular logo and b was a rectangular logo.

enter image description here

So I got it to work by moving through various screen size and manually adjusted the css according to what I saw using media queries as below:

<html>
<head>
<title>Welcome</title>
    <meta name="description" content="T">
    <meta name="keywords" content="">

    <meta name="author" content="">

    <meta http-equiv="cleartype" content="on">
    <!-- Responsive and mobile friendly stuff -->
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
    <style type="text/css">
    
    html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
    
html,body {
    color:#ffffff;
    margin:0px;
    padding:0px;
    background: url('images/bg-1366.jpg') no-repeat center center fixed;
    -webkit-background-size: cover; /* For WebKit*/
    -moz-background-size: cover;    /* Mozilla*/
    -o-background-size: cover;      /* Opera*/
    background-size: cover;         /* Generic*/
}
#band{
    position: relative;
    top:27.5%;
    height:30%;
    width:100%;
    max-width: 100%; 
    border:3px solid #ffffff;
    border-right-style:none;
    border-left-style:none;
    margin:0px;
    align:center;
    padding:0px;
    background-color: #000000;
    -webkit-background-size: cover; /* For WebKit*/
    -moz-background-size: cover;    /* Mozilla*/
    -o-background-size: cover;      /* Opera*/
    background-size: cover;         /* Generic*/
}
#holistic {
    float:right;
    max-width: 80%; 
    max-height: 80%;
}

#spa {
    float:left;
    max-width: 90%; 
    max-height: 90%;
}
#off {
    float:left;
    max-width: 1%; 
    max-height: 1%;
}


    </style>
    <link rel="stylesheet" href="css/col.css" media="all">
    <link rel="stylesheet" href="css/3acols.css" media="all">
 <link rel="stylesheet" href="css/media.css" media="all">
</head>    


<body>

    <div id="band">
    <div id="wrapper">
        <div class="section group">
                <div class="col span_1_of_2">
                <img id="holistic" src="Ehlogo.png">
                </div>
                <div class="col coloff span_3_of_2">
                <img id="off" src="images/off.png">
                </div>
                <div class="col span_1_of_2">

                <img id="spa" src="ESlogo.png">
                </div>
            </div>
            </div>
    </div>
</body>
</html>

    @charset "utf-8";
    @media only screen and (min-width : 320px) and (max-width : 480px) {
     .col{
         text-align:center;
         }
        #holistic {
            float: none;
            max-width: 95%; 
            max-height: 95%;
        }
        #spa {
                float:right;
            max-width: 95%; 
            max-height: 95%;
            margin-top:7.5%;
            margin-right:10%;
        }
            #band {
            top:12.5%;
            height:30%; 
        }
    }
    @media only screen and (min-width : 480px) and (max-width : 640px) and (max-height : 960px){
     .col{
         text-align:center;
         width:640px;
            max-width: 100%; 
            max-height: 100%;
         }
        #holistic {
            float: none;
            max-width: 85%; 
            max-height: 85%;
        }
        #spa {
            float:right;
            max-width: 85%; 
            max-height: 85%;
            margin-top:7.5%;
            margin-right:10%;
        }
            #band {
            top:12.5%;
            height:30%; 
        }
    }
    @media only screen and (max-width : 480px) and (max-height : 800px){
     .col{
         text-align:center;
         }
        #holistic {
            float: none;
            max-width: 95%; 
            max-height: 95%;
        }
        #spa {
            float:none;
            max-width: 95%; 
            max-height: 95%;
            margin-right:10%;
        }
    }
    @media only screen and (min-width : 640px) and (max-width : 768px) and (max-height : 1280px){
     .col{
         text-align:center;
         width:768px;
            max-width: 100%; 
            max-height: 100%;
         }
        #holistic {
            float: none;
            max-width: 100%; 
            max-height: 100%;
        }
        #spa {
            float:none;
            max-width: 100%; 
            max-height: 100%;
            margin-top:3.5%;
            margin-right:3%;
        }
        #band {
            top:12.5%;
            height:25%; 
        }
    }
    @media only screen and (min-width: 1024px) and (max-width: 1280px) {
    
        body{
            background: url('images/bg-1280.jpg') no-repeat center center fixed;
        }
        #holistic {
            position:relative;
            top:-5px;
            left:10px;
            max-width: 90%; 
            max-height: 90%;
        
        }
        .coloff {
            width:75px;
        }
        #spa {
            float:right;
            margin-top:2%;
            margin-right:15%;
            max-width: 85%; 
            max-height: 85%;
        }
    }
    @media only screen and (min-width: 1250px) and (max-width: 1366px) and (min-height: 1024px) {
    
        body{
            background: url('images/bg-1280.jpg') no-repeat center center fixed;
        }
        #holistic {
            max-width: 90%; 
            max-height: 90%;
        
        }
        .coloff {
            width:75px;
        }
        #spa {
            float:right;
            margin-top:2%;
            margin-right:15%;
            max-width: 85%; 
            max-height: 85%;
        }
                #band {
            top:25%;
            height:32.5%;   
        }
    }
    @media only screen and (min-width: 1280px) and (max-width: 1366px) and (max-height: 799px){
        body{
            background: url('images/bg-1366.jpg') no-repeat center center fixed;
        }
        #holistic {
                position:relative;
            top:-16px;
            max-width: 100%; 
            max-height: 100%;
        }
        #spa {
            max-width: 90%; 
            max-height: 90%;
        }
            .coloff {
            width:165px;
        }
            #band {
            top:25%;
            height:32.5%;   
        }
    }
    @media only screen and (min-width: 1200px) and (max-width: 1279px) and (max-height: 799px){
        body{
            background: url('images/bg-1366.jpg') no-repeat center center fixed;
        }
        #holistic {
            max-width: 95%; 
            max-height: 90%;
        }
        #spa {
            float:left;
            max-width: 85%; 
            max-height: 85%;
        }
            .coloff {
            width:175px;
        }
        #band {
            top:25%;
            height:32.5%;   
        }
    }
    @media only screen and (min-width: 1580px) and (max-width: 1920px){
        body{
            background: url('images/bg-1366.jpg') no-repeat center center fixed;
        }
        #holistic {
            max-width: 90%; 
            max-height: 90%;
        }
        #spa {
            float:left;
            max-width: 90%; 
            max-height: 90%;
        }
            .coloff {
            width:180px;
        }
        #band {
            top:25%;
            height:28.5%;   
        }
    }
    @media only screen and (min-width: 1920px) and (max-width: 2400px){
        body{
            background: url('images/bg-1366.jpg') no-repeat center center fixed;
        }
        #holistic {
            position:relative;
            top:-10px;
            max-width: 90%; 
            max-height: 90%;
        }
        #spa {
            margin-top:0.5%;
            float:left;
            max-width: 86%; 
            max-height: 86%;
        }
            .coloff {
            width:200px;
        }
        #band {
            top:25%;
            height:30%; 
        }
    }

/*  SECTIONS  ============================================================================= */

.section {
    clear: both;
    padding: 0px;
    margin: 0px;
}

/*  GROUPING  ============================================================================= */


.group:before,
.group:after {
    content:"";
    display:table;
}
.group:after {
    clear:both;
}
.group {
    zoom:1; /* For IE 6/7 (trigger hasLayout) */
}

/*  GRID COLUMN SETUP   ==================================================================== */

.col {
    display: block;
    float:left;
    margin: 1% 0 1% 1.6%;
}

.col:first-child { margin-left: 0; } /* all browsers except IE6 and lower */


/*  REMOVE MARGINS AS ALL GO FULL WIDTH AT 480 PIXELS */

@media only screen and (max-width: 480px) {
    .col { 
        margin: 1% 0 1% 0%;
    }
}

/*  GRID OF TWO   ============================================================================= */


.span_2_of_2 {
    width: 100%;
}
.span_3_of_2 {
    width: 10%;
}
.span_1_of_2 {
    width: 40.2%;
}

/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span_2_of_2 {
        width: 100%; 
    }
    .span_1_of_2 {
        width: 100%; 
    }
}

My problem is that this was a total pain. It was a lot of guessing and entering % values / saving the file / reloading the browser to see how it looked / adjusting again and so on. Gah!

So I'm looking for a way to use math or a framework or some workflow algorithm to speed this up and take all the guess work out of it. My method was purely amateur hour but so far I cant find a better way to go at it when using percentages and media queries. This took me far too long.

4

1 回答 1

1

Go mobile first! There's a reason it's the mantra. It's so much easier to write your css to make it look good at the smaller screen size, then override for the larger size.

Start with your snap point fairly small, after you get your styling how you like it, resize your browser and let your eye decide where the snap point should be. Let the content dictate the style.

于 2013-09-27T05:42:47.203 回答