Retrofit Existing Site with Responsive Design [closed] - css

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Hopefully this question will not break any of the rules, even though it could probably lead to some debate. And if it reads as though I am asking for code to be written for me, I am not! I just need some advice on the best way to approach this and have read through so many suggestions on forums and have tinkered with so many different bits of code on Codepen and jsFiddle that I have seen posted that I am probably more confused now than at the start!
To being, I will try to explain what I am after in as much detail as possible....
I maintain an existing site (http://www.margate-fc.com/content/frontpage.php) and it is long overdue a redesign. As a large chunk of the traffic comes from mobile devices the current fixed layout is not suitable and I want to make the whole site responsive, while keeping the current Header<>Sidebar,Content,Sidebar<>Footer layout or at least something similar.
The Header and Footer will change slightly at various resolutions and the Navigation Bar will switch to a dropdown/off-canvas menu at a certain breakpoint but none of these will be a problem to work with.
It is the middle section (Sidebar,Content,Sidebar) that will change most between mobile and desktop and is where I need the advice. There will be three different Layouts...
All Three Columns Visible (800px and Above)
Content and Right Sidebar (adverts) visible side by side and Left Sidebar (Statistics) Off-Canvas (799px and Lower)
Content and Right Sidebar stacked and Left Sidebar Off-Canvas (probably 479px and Lower - but realistically it will be at the point where Content becomes too narrow)
Some of the other things I would like to factor in....
I am hoping to keep the two sidebars as fixed width as possible otherwise the content inside the left one could become disjointed.
I would like the entire design to be fluid down to a certain viewpoint and leave room on a wider screen for side ads.
Ideally I would like the sidebars, when visible as columns, to be of matching height and the background color to be achieved without hacks (actually choosing a bg-color not using wide borders or images).
Not a lot to ask then, eh?
I have read a lot of varied advice about each of the things I am trying to achieve and much of it is no problem and have done much of it at some point before. The trouble I am having is getting it all to work together.
Ideally I was hoping to achieve what I was after using a framework and dived in with Twitter Bootstrap. The trouble I had was that the spans were too fluid (so the sidebars went from much wider than the content they contained to too small very easily) and the gutters were too wide. I did attempt to change them, but without a degree in mathematics the results were a mess.
Also, at a certain screen-width, the sidebars were both visible, but with no content. As the screen got smaller, the content returned.
So that is where I am at the moment and I am really grateful for anyone who has read this far!
So, what is the best way to achieve what I am after? Do I try to use a framework that has more flexibility than Bootstrap or do I try to handcode it? If the latter do I start with the mobile layout and then work through the higher breakpoints, or do I start with the fullscreen (because that will be the most difficult to achieve with the equal height and coloured columns) and work downwards through the resolutions?
Or is there another way to go about this that anyone can suggest? I am open to any suggestions, preferably as CSS-based as possible but would be more than happy to use some JS if that is believed to be the best way.

I won't address everything without being able to see your code, but let me take one example:
Ideally I was hoping to achieve what I was after using a framework and dived in with Twitter Bootstrap. The trouble I had was that the spans were too fluid (so the sidebars went from much wider than the content they contained to too small very easily) and the gutters were too wide.
So I interpret this as you're fine with the base fluidity of the grid, but your sidebar divs need to behave differently. Fine, then take them out of the grid, and handle them separately.
Instead of:
<div class="container span12">
...
<div id="sidebarLeft" class="span2">...</div>
<div id="content" class="span8">...</div>
<div id="sidebarRight" class="span2">...</div>
...
</div>
try:
<div class="container span12">
...
<div class="wrapper clearfix span12">
<div id="sidebarLeft" class="sidebar">...</div>
<div id="sidebarRight" class="sidebar">...</div>
<div id="content" class="content_block">...</div>
</div>
...
</div>
Then apply your own styles to lay out just the area that needs to behave differently, eg.
.sidebar {
width: 200px;
float: left;
}
#sidebarRight {
float: right;
}
#content {
margin-left: 200px;
margin-right: 200px;
}
or something like that. Then you can use media queries to hide (display:none;) or otherwise tweak the custom portions of your layout at different sizes.

I think Bootstrap is too heavy - if you are converting a pre-existing website, using Bootstrap will only cause you more problems. What I've found is that unless you are willing to completely customize Bootstrap.css so that it is totally right for you, you'll be designing with lots of Bootstrap conventions in mind. There has been a lot of criticism of the "sameyness" of Bootstrap, and you can see this in the fact that 1000s of websites look the same (you know the Jumbotron slider, with the nav menu, Hero units and the like).
In my opinion there are a few options for you -
Use a framework such as Zurb Foundation or Groundwork CSS which are slightly less intrusive.
Handcode several different "versions" of your site using Media Queries (what I like to do is have separate content areas defined in master divs [i.e. one div will be called 'iphone' and the other will be called 'desktop' and then hide them with media queries]).
Use a fluid grid system and totally refactor your content into that grid system. A good fluid grid system (not a Framework as such) would be 960 Grid System (http://960.gs/) in my mind, or you could just use the customize feature on the Bootstrap website to whittle it down to only the elements you need.
Then of course the 3rd option would be to hide certain elements of your current website i.e. sidebar set to display:none; with Media Queries.
Media Queries
Bootstrap does recommend a good set of CSS Media queries to be starting with however. For example, using the set of queries recommended by Bootstrap, below is how I envisage your site being set out:
/* Large desktop */
#media (min-width: 1200px) {
.iphone {display:none;}
}
/* Portrait tablet to landscape and desktop */
#media (min-width: 768px) and (max-width: 979px) {
.iphone {display:none;}
}
/* Landscape phone to portrait tablet */
#media (max-width: 767px) {
.main {display:none;}
.iphone {
display:block;
top:0;
left:0;
right:0;
bottom:0;
height:100%;
width:100%;
}
}
/* Landscape phones and down */
#media (max-width: 480px) {
.main {display:none;}
/* whatever code you want to put here for landscape viewing of the website on a mobile (if you need it)*/
}

Related

Css property to scale body accordingly to screen as if it were an image

I work for a publicity agency, where my boss designs mockups in Photoshop (based on his 1920x1080 screen), and where the website final layout must look 90% like his, very close. We don't use Bootstrap (or any css framework) as he defines margins and columns himself, so Bootstrap gets more in the way than helping.
We use a mockup image for 16:9 aspect ratio, that can be opened in the browser and fits perfectly if you're viewing it on any 16:9 monitor. When we move on to actually creating the html / css page, we're unable to achieve that effect, and rely on many media queries to 'fix' each bigger or lower resolution than the one it was designed in.
Is there a way to make an element - or the whole body, to simply scale from the original design, so that we don't need to do any media queries between screens that share the same aspect ratio?
This way, we would only have three media queries: One for 16:9, one for 9:16 and one for 16:10.
Additional Info: I'm looking for something that does similar to the transform: scale property, but that one in particular doesn't work here (using it causes problems with buttons becoming unclickable in some browsers).
....Technically, yes, but in reality, it's a lot of work, and won't really save you any time. Your best bet is to go back and start using Bootstrap. At least, using the cols and rows of Bootstrap Bootstrap is a fantastic tool for building responsive websites, for people who aren't comfortable building responsive websites on their own.
I... have a lot of things to say.
First of all,
If you're working on building websites, you really, really should have two monitors attached to your computer. Personally, I prefer having one small (1280x800) and one large (1920x1080) screen, because it makes me more aware and comfortable with responsive design. But that's my personal preference, and many people prefer two large monitors. At the very least, you should also have a 1080p screen, so you can work directly on it.
To answer your question directly, this strategy is not going to work for tablets and phones, because the aspect ratio on desktop computers is "landscape", but in mobile devices the aspect ratio is "portrait". If you've ever tried to view a 1920x1080 image in mobile, you'll immediately see why this a problem.
HOWEVER. If you're looking for a way to scale the entire website based upon the body, ...the approach that comes to mind first, REM, is quite popular, and I assume you've already tried it, but... I'll clarify, just in case.
You can define everything using percent, EM or REM (h1, h2, h3, p, borders, padding, margin, height, fontsize, box-shadow etc... Everything. The phrase px should not appear in your stylesheet.) , and then scale the website with a simple series of media queries like this:
#media( min-width:1200px){
html,body{
font-size: 14px;
}
}
#media( min-width:1400px){
html,body{
font-size: 15px;
}
}
#media( min-width:1600px){
html,body{
font-size: 16px;
}
}
#media( min-width:1800px){
html,body{
font-size: 17px;
}
}
Which will cause the entire website to scale. Obviously, if you're working with a theme or framework(Like Bootstrap), you'll need to modify that framework to use REM too.
#3.The last thing that I have to say is that most websites DON'T look exactly the same on 720p screens vs 1080p screens. For example, take StackOverflow itself. This is what the current page we're looking at looks like:
div#left-sidebar {
width: 164px;
}
#sidebar {/*Right sidebar*/
float: right;
width: 300px;
}
div#mainbar {/*Center section*/
width: calc(100% - 300px - 24px);
}
#content {/*And this wrapper around it all*/
max-width: 1100px;
width: calc(100% - 164px);/*left sidebar*/
}
If you look at it, the entire website is more or less max-width:1480px. If it gets smaller than that, the sidebars stay the same size, but the middle section has width:100% and shrinks to fit the screen.
At around 1000px, StackOverflow gives up and hides the right sidebar, because there's not enough space, but it STILL doesn't change the size of any fonts or icons, ever. (On any screen size, from 1920px all the way down to tablet.)
A good designer should keep this kind of "responsive design" in mind, and give his programmers a design that can shrink cleanly, in this way.
You’re looking for vw css unit. (Not sure if you need vh as well).
Checkout this website for an intuitive understanding of how those units work: https://sparanoid.com
vw unit is relative to viewport width. So if you code everything in vw. your website will behave like an image, just what you ask for.

How to use media queries in an effective way? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Now, I understand how "breakpoints" work - when the browser window reaches a certain width, the element within the queries changes. Now, here is my question:
If I start designing a website, and start adding styles for how I want to look on a mobile device, when the design is finished and I want to expand on it, what's the effective way on doing it?
At the moment, all that I can think of is adding a queries with a higher min-width breakpoint, and then paste the CSS from the code that I already made and start making changes respectively, within the queries. I have a strong feeling that this is not the correct way of doing things, so this is why I am asking for help. Thanks!
You have the correct approach when it comes to making a design and thinking mobile first. Now what you need to do is think of how it will be when you resize it to large device widths.
There are a lot of things you can look into, many people could suggest you to look at frameworks such as Bootstrap just to understand how they use media queries to achieve many things. My advice is to use as little media queries as you can. Try to support at least two device widths: mobile/tablets and desktop. Since mobile/desktop can be interchangeable and new devices are always coming out, a consistent design is best. However you can safely support mobile/tablet/desktop if you take the time to do so properly.
Now, I will try to keep it very simple for you and introduce the most basic way to do media queries right and expand from there.
Let's begin with the most important yet simplest building block of responsive web design: a container element. This container element is to be used for the content in your website, the content is for you to choose to imagine upon, since these containers will need to expand from device width to device with accordingly.
Navigation bar example:
.navigation-bar-container {
position: relative;
width: 100%;
min-width: 320px;
max-width: 100%;
height: 100px;
}
Check the above code its so simple and straight forward, what does it do? I can imagine it will hold all the elements within a navigation bar. It can certainly be used in more than just that way, but for now all we care about its a navigation bar.
It's minimum width is 320px, because the smallest screen you need to support may be 320px wide (iPhone anyone) so there is no need to shrink your element below that.
Max width is interesting. Currently the nav bar's max width is 100% because I said it is... no, that does not make any sense. Why is it 100%? It is because I want to make it always expand to the full width of the screen, regardless of the screen width. That is it's default behavior.
Now try and think of what will happen to your navigation bar's width when you are in a different screen sizes, such as mobile devices. What will happen with the elements, will they shrink with your container? Will they even fit when the screen size is too small? Enter media queries.
Full desktop widths: approximately 769px or above... this is subject to change of course.
The max width is 100% and width 100% means it will adjust to whatever the screen size is. Default behavior doing its thing, yes!
Tablets: approximately 421px to 768px... this is subject to change of course
If your elements will not fit into all tablet sizes and make your navigation bar look weird, yes try it throw some divs and stuff in it and shrink it, then what do we do? It is time to make them fit by using the good old media queries:
#media screen and (max-width: 768px) {
.navigation-bar-container {
display: none;
}
.sliding-navbar-container {
display: block;
position: absolute;
height: 100%;
left: 0;
top: 0;
width: 320px;
}
}
Yes I did not make them fit at all. I swapped the good old navigation-bar-container width a different one. Classic example of what is good and safe when using media queries. Instead of breaking your head over how to fit these elements, spare no hesitation my friend, just swap your navigation bar for another that will work on smaller devices in there.
Note how the new navigation bar actually accounts for its width 320px, it will sit absolutely positioned to the top and left of the screen, doing a good job there. How to make it slide in and out, pop up, look neat is another question entirely! Don't ask unless you are curious... back to media queries!
However if we are speaking of an element which will change, let's say it always occupies 100 percent of your screen width, and then shrink to occupy half of the screen width for tablet/landscape phone devices only, then you may want to use a media query like so:
#media screen and (min-width: 421px) and (max-width: 768px) {
max-width: 50%;
}
Very small and simple change. Max width is interesting because it controls your inner width, which is by default set to 100%. This change will force your element to adjust to 50% of the screen width while still resizing to adjust to 100% of the new element width. It could also be a good idea to make it max-width: 50vw since it will adjust to the viewport width instead, thus making it responsive even when dealing with widely different viewports.
And so, we come to our conclusion TLDR:
Use as little media query sizes as you need, because if you need a lot then you are doing it wrong, seriously!
If you need a lot, cannot avoid it, then get to know Bootstrap, let other people worry about the media query nightmares.
Think in containers, your elements will sit and move around in them. Think of how these containers will flow from desktop to mobile and vice versa. Putting thought behind this is crucial as it is the source of your responsive behavior and should be the focus of your media queries.
Although not covered here, you can easily look at media queries and font/image examples. Responsive fonts and images are a crucial part of your content and they as such should be accounted for with media queries. Background image changes, better readability depending on the device you are on, all of that matters and can be simplified via media queries.
I put this last here because IT MATTERS A LOT use SASS/SCSS and save yourself a ton of trouble when working with media queries (and everything CSS). Look into mixins, variables, partials which you can use along media queries. You will love it if you didn't know about it and start using it now.
Need more? Fine enjoy Google's responsive web design fundamentals
Good luck!!!

Problems scaling to mobile and small screens in general

I've recently deployed my first ever website and on my wide screen 1920x1080 monitor everything looks fantastic. However, things start to get really weird on 13" laptop screens, tablets and mobiles. I've been analysing my code and a few development tools such as googles and bootstraps recommendations for mobile and I just can't quite seem to understand what it is in my code that needs fixing.
On mobile, it's possible to scroll across all the way to the right to parts of the website that shouldn't even exist, just scrolling over to white space. I've managed to remove the navbar for mobile - a start, but honestly, I feel a bit lost/overwhelmed and can't seem to find the root cause of this issue.
Here is my website: -redacted-
and -redacted- is my github repository
The problem is that your using fixed width's for the elements on your page.
E.g. for the class .container you specified a width of 970px. Try using percentages, like so:
.container {
width: 80%;
margin: 0 auto; //to center it
}
You can basically take this solution and apply it to the other issues on your page, like the header.
Also note:
You should also look into media queries, that would enable you to keep the page as it is for large screens and only change it for smaller screens, defining, e.g., a max-width:
#media screen and (max-width: 800px) {
//anything you want for screens below a width of 800px
}
EDIT:
I understand you are using Bootstrap - in that case you would need to entirely delete all statements that are overriding Bootstrap's default configurations.
Anyway, keep the upper recommendations in mind for future CSS coding.
You have set your containers width with px.
Try to change them with % or directly erase those px measures.
Bootstrap containers adjust themselves to the correct width they need.
You have this rule in your CSS, which is ruining the responsive effect the .container class from Bootstrap is supposed to have (overriding the media-query-set width it should be using, and indeed is using in other parts of the page):
.myskills .container {
width: 1500px;
position: relative;
top: 35px;
}
Setting a fixed width, in this example, being the problem.
There may be more examples of things like this on the site, so I'd advise removing all examples of this that you can find.
In general I wouldn't advocate overriding Bootstrap CSS classes without being very sure why you need to do so, particularly the structural elements like .container, .row and .col-xx-x classes.

Display nicely across desktop screen sizes

I have designed a website on my retina monitor, set at the highest resolution. On this resolution the site looks really great :p. However, when I view the site on a smaller 13" monitor, all the elements and the font are way too big and in your face.
I have done some research, and found two ways to try and show the website in a nice way across different desktop screen sizes:
Use a media query to Scale/Transform the body. However, this "feels" wrong and I can imagine this has some performance impact. Furthermore I can imagine this gives inconsistencies across screen sizes
Use ems across the board. I am not really sure what'd be the right starting point for this, but I have read that some people base everything upon their font-size. However, I would not really know how this'd work for images.
Can someone please tell me what'd the best way to make the website display nicely across desktop screen size.
p.s. The website is based on twitter bootstrap
I would suggest the second option. The way it would work is by setting the element font size in px, and using relative sizes for the containers and divs inside them.
For example
<body>
<div id="container">
<article>This is some text</article>
</div>
</body>
CSS:
html{
font-size: 32px;
}
#container{
font-size: 1.5 rem;
}
article{
font-size: 1.2 em;
}
CSS-tricks has a nice article on this - http://css-tricks.com/rems-ems/
As for image resizing, that can be done dynamically in JS based on window.width()

What am I missing about responsive web design?

My concept of "Responsive Web Design" is:
Design a web layout that stretches nicely with any width monitor or media screen.
Design a web layout that squeezes too with any width monitor or media screen.
Design a web layout that viewed nicely on any device.
Design your layout with percentage (%) rather than pixels (px).
After the common concepts I owned some concepts, now at this point, I'm confused of:
Design anything as your layout, scrolling your mouse-wheel see how it looks when stretches or squeezes in different media screen width. Just design anything, and then do CSS for different media screens/device widths. To do so, just use #media screen and (max-width: 800px) { /* do Media CSS here; */ }, and add your NEW CSS for any of the element of your layout.
(So, when you have power to do anything with the media queries, just design with ease. After completing design for computer monitor, put emphasis on the devices or small media screens and play with the CSS)
Suppose in style.css I specified width of header .somediv{ width: 100%; }, in 320px I can specify the width whatever I like to as #media screen and (max-width: 800px) { header .somediv{ width: 50%; } }.
When something is popping out from the layout, just clear the float and put the thing in stack before or after the main container.
Do responsive CSS for images with img{ max-width: 100%; }.
Now for my satisfaction and progress through the responsive world, I want you to criticize me - what am I wrong about responsive CSS if I'm thinking like the above?
Or, I'm completely OK with the concept, then why my site is breaking in 320px while not on 800px, and I can't apply different CSS for 320px solely. Why I have to specify header height in 800px where it's applicable only in 320px?
So it looks as though you are doing everything right, I can see issues with your site but only at say 640px but 320px looks fine for me.
When I first started responsive designs I found this website: http://css-tricks.com/
I opened up their CSS stylesheet and studied it and found out how they did it.
For reference sake I would advise looking at the following links on how to do responsive design:
Simple Responsive Images with CSS backgrounds - SmashingMagazine Mobile
Beginner's Guide to Responsive Web Design - TeamTreeHouse.com blog
Responsive Web Design - Learn.ShayHowe.com
Build Basic Responsive Site CSS - NetMagazine.com
With regards to getting the Media Queries I would strongly advise looking here:
Media Queries for Standard Devices
There is people I know who still use php scripts to determine the users screen resolution and then load a specific CSS stylesheet which personally I would not recommend but that is also an option.
I personally would try changing your CSS to include the following:
#media only screen
and (max-width : 320px) {
#div1 {
width:100%;
}
}
The only way I have managed to get this working though is by either copying my whole CSS over again for that specific media screen or by only specifying the certain div's to change.
Remember you can re-declare the CSS styling for a DIV or CLASS further down the stylesheet
Hope this can be of some help to you.

Resources