View Full Version : Resolved looking for advice on mobile friendly layout for my website
james438
06-22-2015, 06:04 PM
http://www.animeviews.com/
I'm not really looking forward to this, but I am looking to make my website more mobile friendly. My thought is that I should remove both sidebars and the right column where my wordpress posts are located. Also should I be looking at two or more different mobile layouts for my site considering the different phone and tablet resolutions out there?
molendijk
06-22-2015, 09:01 PM
Try to play with this:
<!doctype html>
<html >
<head>
<title>James438</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {font-family: verdana; font-size: 14px; padding: 2%; padding-top: 0; background: green; margin-top: -2px}
.responsive_div {display: table-cell; margin-bottom: 0; padding-right: 40px; text-align: top}
img {width: 80%; max-width: 400px; }
#middle {min-width: 70%; background: #F2DD99; padding: 20px; border-radius: 10px}
#right {padding-left: 30px; }
@media screen and (max-width: 899px)
{
.responsive_div {display: block; margin-bottom: 17px; padding-right: 0; }
img {width: 50%; margin-left: 25%}
#right {padding-left: 0}
}
</style>
</head>
<body>
<div style="position: relative;
background-image: url(http://www.animeviews.com/images/pops/iria4.jpg); height:192px; width: 70%; background-repeat:repeat; margin-left: 15%; ">
</div>
<div class="responsive_div" >
<div style="color: silver; font-weight: bold">SITE NAVIGATION</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
<br>
<img src="http://www.rtvnoord.nl/content/groningeninbeeld/pics/winsum/groot/groot_20040425_Ezinge_museum_Wierdenland_VVV.jpg" alt="" ><br>
Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
<div class="responsive_div" id="middle">
<div style="text-align:center;font-size:32px;">New and Recently Updated</div>
<hr><b><a href="http://www.animeviews.com/news_maincontent.php?ID=386">Texas Supreme Court rules same sex couple may divorce</a></b>
<br>
<br>Posted and updated a news post with a timeline with links to rulings.
<br>
<br>This case has been pending appeal to the Texas Supreme Court for over two years and we have been awaiting a ruling nearly two years after that. *At issue is whether a trial court in that state where same sex marriages are not recognized may grant a divorce to a same sex couple who originally married in another state where same sex marriage is recognized. *<a href="http://www.animeviews.com/article_maincontent.php?ID=255">Submitted 6/22/15</a> <br><HR>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
<br>
<div style="text-align: center">
<img src="https://www.kaartje2go.nl/kaarten/vrienden-voor-het-leven-7/img/vrienden-voor-het-leven-7.jpg" alt="">
</div>
<br>
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
<div class="responsive_div" id="right" style="padding-right:0; ">
<div style="color: silver; font-weight: bold">DAILY BIBLE QUOTE</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
<br>
<img src="http://wierdenland.nl/plinius.jpg" alt="" >
<br>
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
</body>
</html>
I don't think you need different layouts for phone and tablet
james438
06-22-2015, 10:12 PM
That is very helpful. I am starting almost from scratch in learning how to make a website mobile, etc. friendly. Your code looks to have taken me most of the way there.
Thanks again :)
I think my next big decision will be trying to figure out which mobile friendly DD menu will work best with my site.
Beverleyh
06-23-2015, 09:29 AM
To maintain some artistic control over your banner, you might want to check out
#2: http://fofwebdesign.co.uk/template/_testing/scale-img/target-ratio-resize.htm and
#3: http://fofwebdesign.co.uk/template/_testing/scale-img/fluid-ratio-resize.htm
from this blog (http://www.dynamicdrive.com/forums/entry.php?293-3-Ways-to-Resize-Scale-Web-Images-in-Responsive-Design)
Assuming that your banner markup is this; <div class="banner"></div>...
I had a play here and this CSS from #2 looks good at a variety of sizes;
.banner {
max-width: 1251px; /* actual img width */
max-height: 192px; /* actual img height */
*height: 192px; /* actual img height - IE7 */
background-image: url(http://www.animeviews.com/images/pops/iria4.jpg);
background-size: cover;
background-position: 0 50%;
}
.banner:after {
content: " ";
display: block;
width: 100%;
padding-top: 33.333%; /* 3:1 ratio */
}
And so does this from #3;
.banner {
max-width: 1251px; /* actual img width */
*height: 192px; /* actual img height - IE7 */
background-image: url(http://www.animeviews.com/images/pops/iria4.jpg);
background-size: cover;
background-position: 0 50%;
}
.banner:after {
content: " ";
display: block;
width: 100%;
padding-top: 11.777%; /* slope */
height: 44.669px; /* start height */
}
The difference between them is that #3 scales down completely smoothly, while #2 just loses width until the 3:1 ratio is reached, and then it scales smoothly.
You can play around with the aspect ratio in #2 to achieve different effects, and also change the padding-top and height values in #3 using the calculator at the bottom of the page: http://fofwebdesign.co.uk/template/_testing/scale-img/fluid-ratio-resize.htm
molendijk
06-23-2015, 03:38 PM
I think my next big decision will be trying to figure out which mobile friendly DD menu will work best with my site.
Of course there's nothings against keeping the menu you already have, try this code:
<!doctype html>
<html >
<head>
<title>James438</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {font-family: verdana; font-size: 14px; padding: 1%; padding-left:5px; padding-top: 0; background: green; }
.responsive_div {display: table-cell; margin-bottom: 0; padding-right: 40px; vertical-align: top; min-width: 180px; }
img {width: 100%; max-width: 400px; min-width: 170px; display: block; margin: auto; margin-top: 20px; margin-bottom: 20px}
#middle {min-width: 70%; padding:0; border-radius: 0px}
#right {padding-left: 30px; min-width: 140px}
@media screen and (max-width: 899px)
{
.responsive_div {display: block; margin-bottom: 17px; padding: 35%; padding-top: 10px; padding-bottom: 10px}
img {width: 50%; max-width: 300px; min-width: 50px}
#right {padding-left: 0}
}
</style>
</head>
<body>
<img id="banner" src="http://www.animeviews.com/images/pops/iria4.jpg" alt="">
<div class="responsive_div" >
<div style="background: white; padding: 10px; border-radius: 5px; width: 100%; margin-auto; ">
<span style="background: gray; color: white; width: 100%; display: block"> ▼ Site Navigation</span><br>
<a href="javascript: void(0)" style="color: black">Main</a><br>
<a href="javascript: void(0)" style="color: black">About</a><br>
<a href="javascript: void(0)" style="color: black">Search</a><br>
<a href="javascript: void(0)" style="color: black">Articles</a>
</div>
<br>
<div style="background: white; padding: 10px; border-radius: 5px; width: 100%; margin: auto; ">
<span style="background: gray; color: white; width: 100%; display: block"> ▼ Anime + Manga</span><br>
<a href="javascript: void(0)" style="color: black">Anime Reviews</a><br>
<a href="javascript: void(0)" style="color: black">Anime Characters</a><br>
<a href="javascript: void(0)" style="color: black">Gallery</a><br>
<a href="javascript: void(0)" style="color: black">Screenshots</a><br>
<a href="javascript: void(0)" style="color: black">Manga Reviews</a>
</div>
<br>
<div style="background: white; padding: 10px; border-radius: 5px; width: 100%; margin: auto">
<span style="background: gray; color: white; width: 100%; display: block"> ▼ Misc</span><br>
<a href="javascript: void(0)" style="color: black">News</a><br>
<a href="javascript: void(0)" style="color: black">Links to Webcomics</a><br>
<a href="javascript: void(0)" style="color: black">Bible Quotes</a><br>
<a href="javascript: void(0)" style="color: black">Member Control Panel</a>
</div>
<br>
<div style="background: white; padding: 10px; border-radius: 5px; width: 100%; margin: auto">
<span style="background: gray; color: white; width: 100%; display: block"> ▼ Forum etc.</span><br>
<a href="javascript: void(0)" style="color: black">Forums</a><br>
<a href="javascript: void(0)" style="color: black">Older Musings</a><br>
<a href="javascript: void(0)" style="color: black">Wordpress</a>
</div>
<br>
</div>
<div class="responsive_div" id="middle">
<div style="padding: 20px; padding-top: 10px; background: #F2DD99">
<div style="text-align:center;font-size:32px;">New and Recently Updated</div>
<hr><b><a href="http://www.animeviews.com/news_maincontent.php?ID=386">Texas Supreme Court rules same sex couple may divorce</a></b>
<br>
<br>Posted and updated a news post with a timeline with links to rulings.
<br>
<br>This case has been pending appeal to the Texas Supreme Court for over two years and we have been awaiting a ruling nearly two years after that. *At issue is whether a trial court in that state where same sex marriages are not recognized may grant a divorce to a same sex couple who originally married in another state where same sex marriage is recognized. *<a href="http://www.animeviews.com/article_maincontent.php?ID=255">Submitted 6/22/15</a> <br><HR>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
<img src="https://www.kaartje2go.nl/kaarten/vrienden-voor-het-leven-7/img/vrienden-voor-het-leven-7.jpg" alt="" >
<br>
<div style="padding-left:20%; padding-right: 20%">
<img src="https://www.kaartje2go.nl/kaarten/vrienden-voor-het-leven-7/img/vrienden-voor-het-leven-7.jpg" alt="" style="float: left; width: 40%">
<img src="https://www.kaartje2go.nl/kaarten/vrienden-voor-het-leven-7/img/vrienden-voor-het-leven-7.jpg" alt="" style="float: right; width: 40%">
</div>
<div style="clear: both"> </div>
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
</div>
<div class="responsive_div" id="right" style="padding-right:0; ">
<div style="color: silver; font-weight: bold">DAILY BIBLE QUOTE</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
<img src="http://wierdenland.nl/plinius.jpg" alt="" >
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
<script>
//Put this script at the end of the body section
function position_banner()
{
if(window.innerWidth>899)
{
document.getElementById('banner').style.margin=0;
document.getElementById('banner').style.marginLeft=document.getElementById('middle').offsetLeft+'px';
document.getElementById('banner').style.minWidth=document.getElementById('middle').clientWidth+'px'
}
else if(window.innerWidth<=899)
{
document.getElementById('banner').style.margin='auto';
document.getElementById('banner').style.display='block';
document.getElementById('banner').style.minWidth='100%';
document.getElementById('banner').style.minHeight='70px';
}
}
position_banner();
window.onresize=function(){position_banner()};
</script>
</body>
</html>
james438
06-23-2015, 05:33 PM
To maintain some artistic control over your banner, you might want to check out
#2: http://fofwebdesign.co.uk/template/_testing/scale-img/target-ratio-resize.htm and
#3: http://fofwebdesign.co.uk/template/_testing/scale-img/fluid-ratio-resize.htm
from this blog (http://www.dynamicdrive.com/forums/entry.php?293-3-Ways-to-Resize-Scale-Web-Images-in-Responsive-Design)
Thanks for those links and code. I was actually thinking of revising how it resizes.
Of course there's nothings against keeping the menu you already have, try this code:
Interesting. I probably will keep the menu and just tweak it a bit using your code.
james438
07-04-2015, 12:01 AM
I've been working on my demo page (http://www.animeviews.com/test2.php) a little each day. I've incorporated both of your suggestions into the layout. I have yet to refine it and clean up the code, but the basic layout is about right.
Just a few questions:
I have two columns below which have not been added yet.
For the mobile friendly version should they not be there, should only one be displayed, or should both be displayed with one above the other?
Are there any thoughts on the font size? Too small?
Are the links on the left too close to each other vertically?
Is the banner maybe too big in the mobile version or about right?
Beverleyh
07-04-2015, 05:51 AM
I'm currently on my iPhone so I guess that makes for convenient feedback ;)
Is point 1 part of point 2? They feel like two parts of the same question so I'll take it that they are for now.
1/2) I would say that it depends on content. There tends to be two schools of thought when it comes to displaying content on mobile; The first is to only show the most important stuff and hide the rest, and the second is to not make mobile users feel like poor relatives and give them everything (no penalties for using a small screen). The second way encourages you to reevaluate content, including rewriting copy more concisely so that you're still saying everything you need to without losing meaning. Prioritise the key parts by putting it at the top, etc. I go with the second approach normally, unless there is content that just wouldn't be useful, or that doesn't "work" on mobile. For example, I'm working on a responsive school rebuild at the mo, which has a secondary, and much used "utilities" menu bar. The utilities behind the links are mostly to internal desktop-size resources that don't work on mobile, so it makes sense to hide this menu from mobile users. What I find useful is using a hide/show JavaScript reveal to collapse content at small sizes - that way you're still giving mobile users access to everything, but it's on their terms. Here's a script that demonstrates this behaviour (see the block of text at the bottom that collapses to a few lines when the screen gets narrow http://fofwebdesign.co.uk/template/_testing/read-more-js.htm
3) The font-size looks fine for mobile to me. General rule of thumb nowadays is to not drop below the equiv of 14px on body copy, for accessibility and comfort. You might want to increase line-height though - again, a general rule for vertical rhythm in typography, is a line-height of 1.5 to 1.75 (no unit). There are online calculators that will calculate this for you, taking in to consideration the type-face and characters-per-line (amongst other things), but sometimes you just have to go with what *feels* right.
4) See comments on line-height above.
5) The banner looks very boxy/square on mobile - quite deep, and I can only see the 'A' and 2/3 of the 'n' on an iPhone 5S. It could afford to be half the height/depth I think (or whatever height allows me to see all the title text).
Hope that helps
james438
07-04-2015, 06:51 AM
Yeah, that was a typo earlier. I didn't proof read what I wrote as carefully as I could have.
Thank you for the tips! All of these are quite useful as I am quite new to optimizing a site to be mobile friendly. The link you post*ed is a good example on how to compact text with "Read More" buttons. I'll have to think on it a bit more before I decide on the direction I want to take with those two columns.
molendijk
07-04-2015, 01:14 PM
James, the banner is a little bit too narrow with a large screen, and too wide on mobile. Try the following:
- give the banner width: 70%, which is also the width for #middle;
- to @media screen and (max-width: 899px) add width: 100px for the banner
james438
07-06-2015, 05:41 AM
molendijk, I didn't have as much time to implement your code over the weekend. It is independence day over here which unfortunately means endless fireworks. I mean fireworks are great and celebrating Independence Day is great too, but in my neighborhood that means 24 hours of day of loud booms for several days (so far about four) with a dog you are trying to comfort. Sigh :(
I was a bit confused at first because the banner was already set at 70% then I looked at it in Firefox and saw what you meant. Firefox seems to treat min-width differently than other browsers. I didn't look into it too much; just removed min-width for now. I don't think I want to make the banner more narrow in the mobile version so much as I want to shrink it or just replace it.
Beverlyh, I like your suggestion of increasing the width of the banner to the width of the screen or close to it in the mobile version. The problem is that the title becomes too cropped, so I think it needs to be resized somehow instead.
Beverleyh
07-06-2015, 09:18 AM
I think it needs to be resized somehow instead
ta-dah!!!!! http://fofwebdesign.co.uk/template/_testing/test/anime-views.htm
As a starting point at least - shrink your browser window to see the effects - both exhibit different behaviours so play around and see if you can work with them.
james438
07-06-2015, 04:04 PM
I like them both! It is hard to decide between the two, but I think I like the second better. I'm not sure why, but I am having trouble getting them to render correctly when I integrate them into my demo page.
Beverleyh
07-06-2015, 04:48 PM
I am having trouble getting them to render correctly when I integrate them into my demo page
Looking at your CSS, you have the following rules defined, which you later need to nullify in your 899px media query;
.banner { height:192px; margin-left:17%; width: 66%; ...
So, you'd auto the width and height and zero the margin-left (returning them to their default values), and also add the :after pseudo element CSS;
@media screen and (max-width: 899px) {
.banner {
width: auto;
height: auto;
margin-left: 0;
}
.banner:after {
content: " ";
display: block;
width: 100%;
padding-top: 33.333%; /* 3:1 final ratio */
}
...
}
This part can be deleted;
.banner {content:" "; display:block; width:100%; padding-top:0;width:100px;/* 3:1 ratio */
margin-left:0%;
}That's a mish-mash of stuff from .banner and the .banner:after pseudo element ;)
james438
07-06-2015, 05:51 PM
Works great! I'm enjoying the new functionality of my banner :)
The after pseudo element is new to me. How does it operate in this example? What does padding-top: 33.333%; do here?
molendijk, I misread my code earlier. The banner was set to 66%, not 70%.
I'm going to work on some smaller layout issues with the middle content next.
Beverleyh
07-06-2015, 06:52 PM
The padding-top is giving the div height. If you think that the div is an empty element (there's nothing inside) so it would naturally want to collapse in on itself to zero. Except we don't want it to do that because of the background-image, so we need to give it height. The obvious thought would be to set a height property:value; pairing, which is easy in a fixed layout, but not so much in responsive design. You can't do it with % (doesn't work) and if you set it in px, the height is fixed and wouldnt resize nice and proportionally along with the width. Now the funny thing is that internal padding scales proportionally to width - even top and bottom padding, which seems strange because you'd think it would more likely scale with the height of an element, but it doesn't. Weird, but that's another story. So if you set a vertical padding on the element (either directly or as a pseudo element) you're indirectly giving it a relative height. And 33.33% is the ratio of the final image - you can change that for different sizing effects.
Depending on the circumstances, you can also set vertical padding on the div with the background-image itself. I used a pseudo element for some reason that currently is illuding me and I can't test the difference as I'm on iPhone. Most likely I dismissed it due to scaling behaviour, or maybe I wanted to present CSS methods that more closely related to each other in my blog entry http://www.dynamicdrive.com/forums/entry.php?293-3-Ways-to-Resize-Scale-Web-Images-in-Responsive-Design Not sure. I'll have to double check in the morning.
There is another relative unit to play with too - you can set the height of the div using vw units, but the scaling with those is a bit janky (seem to scale on a steeper path than what would be desirable).
james438
07-06-2015, 08:26 PM
Interesting. Thanks for the explanation :)
I use the Opera a great deal. One cool thing that Opera can do is when you inspect the element on a page there is a small icon in the top left menu that will allow you to select the device you want to use to view the page. For example, I chose iPhone 5 so that I can see what the page or website would look like if I had an iPhone 5. There are several others that I can choose from.
james438
07-10-2015, 08:46 PM
I have updated my main page which was the most difficult and important page. I am now moving on to the rest of the site.
Thanks for all of your help molendijk and Beverlyh :)
james438
07-12-2015, 04:25 AM
Is display:table-cell; the best thing to use here for a mobile friendly website? I'm more used to using floats, but I can learn to use display:table-cell; if that is what I need. In particular I am looking at article stubs that I have such as
http://www.animeviews.com/test2.php?ID=286
where the article div expands to the height of the right side div as opposed to collapsing to the height of the content within.
Is mobile friendly the correct terminology or responsive website better?
molendijk
07-12-2015, 10:25 AM
In my experience, the easiest way to make grid systems is a combination of table-cell and min-width for the columns, where the percent value for min-width equals 100/number-of-columns and where table-cell becomes block as soon as the screen gets too narrow. Here (http://mesdomaines.nu/eendracht/div_table/div_table4.html)'s an example (view source).
I guess 'responsive' and 'mobile friendly' mean approx. the same here, but see http://www.atomic74.com/click/responsive-vs-mobile-friendly-websites-whats-the-difference.
Beverleyh
07-12-2015, 12:39 PM
Here is a great round-up of the most common (floats, block) and emerging (flexbox) methods for responsive grid layouts http://www.sitepoint.com/easy-responsive-css-grid-layouts/ pros and cons are listed so this article makes it quite easy to decide what's best in what situation.
Until flexbox gets better support, I would still tend to stick with floated block-level divs, with box-sizing:border-box; to allow padding blocks without adding to their widths. Occasionally I use table-cells but it depends on content.
table-cell has its merits (equal height columns and vertical-alignment) but you should be aware of the specs and how they work in order to manipulate them effectively. To get table-cell divs behaving predictably as far as width settings are concerned, they also need a wrapper set to display:table; width:100%;. Without it, a width setting has no effect and the table-cells will collapse, only being as wide as their content needs them to be (and 3 adjacent table-cells, each set to 33% width or min-width, will not occupy equal space).
One thing I can't stress enough is to let your content dictate layout. Use a media query breakpoint only when your content needs it.
molendijk
07-12-2015, 01:07 PM
... table-cell has its merits (equal height columns and vertical-alignment) but you should be aware of the specs and how they work in order to manipulate them effectively. To get table-cell divs behaving predictably as far as width settings are concerned, they also need a wrapper set to display:table; width:100%;. Without it, a width setting has no effect and the table-cell will collapse, only being as wide as its content needs it to be (e.g. 3 adjacent table-cells, each set to 33%, will not occupy equal space).
Are you sure, Beverleyh? In the demo I referred to in my last post, there's no such wrapper. Yet, the cells have equal horizontal space.
Beverleyh
07-12-2015, 02:09 PM
Are you sure, Beverleyh?Yes, I'm completely sure that a parent wrapper with display:table; width:100%; is needed in order for child display:table-cell; elements to respect width settings.
See the specs for further info http://www.w3.org/TR/CSS2/tables.html#fixed-table-layout
In the demo I referred to in my last post, there's no such wrapper. Yet, the cells have equal horizontal space.No, unfortunately they don't have equal horizontal space. They are as wide as their content needs them to be (the images are creating width). Take the images out and the columns will collapse equally.
molendijk
07-12-2015, 02:35 PM
I removed the images. The columns continue to have equal horizontal space. Demo here (http://mesdomaines.nu/tablecell.html).
Code:
<!doctype html>
<html >
<head>
<title>Divs next to each other</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {font-family: verdana; font-size: 14px; padding: 10%; padding-top: 10px}
.responsive_div {display: table-cell; min-width: 33.333%; margin-bottom: 0; padding-left: 10px; padding-right: 40px; border: 1px solid black}
@media screen and (max-width: 899px)
{
.responsive_div {display: block; margin-bottom: 17px; padding-right: 0; border:0}
}
</style>
</head>
<body>
<h2 style="text-align: center">Responsive; 3 columns</h2>
<br>
<div class="responsive_div" style="border-right:0">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
<br>
<br>
Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
<div class="responsive_div" style="border-right: 0">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
<br>
<br>
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
<div class="responsive_div" >
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
<br>
<br>
Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
</body>
</html>
molendijk
07-12-2015, 02:58 PM
To see what I mean, you could also go to http://www.w3schools.com/cssref/tryit.asp?filename=trycss_display_inline. Replace
p {display: inline;} with
p {display: table-cell; min-width: 20%; border: 1px solid black} then give the paragraphs different content. Result: cells having equal horizontal space.
styxlawyer
07-12-2015, 05:42 PM
To see what I mean, you could also go to http://www.w3schools.com/cssref/tryit.asp?filename=trycss_display_inline. Replace
p {display: inline;} with
p {display: table-cell; min-width: 20%; border: 1px solid black} then give the paragraphs different content. Result: cells having equal horizontal space.
I just tried that in Opera and the column widths adjust to the width of the content. The "min-width:20%;" token appears to be ignored as the cells will reduce to a single character.
james438
07-12-2015, 06:45 PM
One thing I can't stress enough is to let your content dictate layout. Use a media query breakpoint only when your content needs it.
Can you elaborate on that? A little later I will try to look at box-sizing:border-box; and your reference link (http://www.sitepoint.com/easy-responsive-css-grid-layouts/) you posted.
My main concern right now is having to do with heights. Here is my new demo page that I am working with
http://www.animeviews.com/test2.php?ID=291
Here is how it should look:
http://www.animeviews.com/article.php?ID=291 The middle content stretches to the height of the tallest div.
When I first started working on my website I used tables for my layout. After that I abandoned the idea of getting my website to do table gymnastics in order to get my website to behave the way I wanted and moved to a css layout. What I had heard was that tables were good for working with tables, but was not often a good idea for website layout and floats and whatnot were better.
I'm happy to go back to the table layout if that is what is needed. I am beginning to see some of the things that you can do with tables, but I am more used to floats.
styxlawyer, I am not getting the same results in my Opera browser. The cells shrink to a single word as opposed to a single character. Are you using the current version of Opera or 12.x?
molendijk
07-12-2015, 07:37 PM
I just tried that in Opera and the column widths adjust to the width of the content. The "min-width:20%;" token appears to be ignored as the cells will reduce to a single character.
I made a mistake both in my demo and my reference to w3schools. I forgot the width. We should not only have min-width: 20% (width 5 columns), but also width: 20%. With 3 columns, we would have min-width: 33.33% and width: 33.33% etc. (But just using min-width works in Firefox).
So the statement that we don't need a wrapper seems to remain valid.
James, this works here with Opera too (if we don't forget the width).
styxlawyer
07-12-2015, 07:38 PM
.
.
styxlawyer, I am not getting the same results in my Opera browser. The cells shrink to a single word as opposed to a single character. Are you using the current version of Opera or 12.x?
I'm using Opera 30.0.1835.88 (64-bit) on Windows 8.1.
I guess a single word is the same as a single character if it's only a one character word! My point was that it's not holding to a minimum width of 20%, which it should be doing according to the CSS.
Beverleyh
07-12-2015, 07:38 PM
One thing I can't stress enough is to let your content dictate layout. Use a media query breakpoint only when your content needs it.
Can you elaborate on that? A little later I will try to look at box-sizing:border-box; and your reference link you posted.
No problem - these guys do it better than I ever could;
- https://developers.google.com/web/fundamentals/layouts/rwd-fundamentals/how-to-choose-breakpoints
- http://www.smashingmagazine.com/2014/07/08/breakpoints-and-the-future-websites/
- http://responsivedesign.is/articles/why-you-dont-need-device-specific-breakpoints
styxlawyer
07-12-2015, 07:41 PM
I made a mistake both in my demo and my reference to w3schools. I forgot the width. We should not only have min-width: 20% (width 5 columns), but also width: 20%. With 3 columns, we would have min-width: 33.33% and width: 33.33% etc. (But just using min-width works in Firefox).
So the statement that we don't need a wrapper seems to remain valid.
James, this works here with Opera too (if we don't forget the width).
OK, that works now.
molendijk
07-12-2015, 08:36 PM
My main concern right now is having to do with heights.
James, I think the following will work:
1. Remove the css for #middle;
2. Wrap a div around what you have inside <div class="responsive_div" id=#middle>...</div> and give the wrapper style="background:#ffe4b5; border-radius:10px; color:#000000; padding: 20px". I guess that should do it. So you should end up with something like this
<div class="responsive_div" id="middle" >
<div style="background:#ffe4b5; border-radius:10px; color:#000000; padding: 20px">
<div style="text-align:center;font-size:32px;">demo
<div style='font-size:14px; font-weight: bold'>written by: <span class='o'>admin</span>
</div>
</div>
<hr><br><span class='o'>Date Written: </span>7/12/15 <span class='o'>Last Updated:</span> // <br><br>This is an article stub.<br><br><b><span class='o'>TAGS:</span></b> <a href="http://www.animeviews.com/display.php?category=misc">misc</a>
</div>
</div>
Beverleyh
07-12-2015, 10:28 PM
So the statement that we don't need a wrapper seems to remain valid.Sometimes, but it depends on content and/or available container width. Referring to Arie's content, yes, this is true, because there is enough content to expand a table-cell to 33% width.
Going back to what I originally said;
To get table-cell divs behaving predictably as far as width settings are concerned, they also need a wrapper set to display:table; width:100%;. Without it, a width setting has no effect and the table-cells will collapse, only being as wide as their content needs them to be (and 3 adjacent table-cells, each set to 33% width or min-width, will not occupy equal space).This original answer was more generic than how it appears to have been interpreted, and was also taking in to account cells with either no or very little content, and wide screens vs narrower screens, where shorter content may fill or not fill a cell depending on device, hence "predictably" and the line "only being as wide as their content needs them to be".
This would demonstrate that behaviour;
<!DOCTYPE html>
<html>
<head>
<style>
.table { display:table; width:100% }
.td { display:table-cell; width:20%; border:1px solid #000 }
</style>
</head>
<body>
<div class="td"> one </div>
<div class="td"> two </div>
<div class="td"> three </div>
<div class="td"> four </div>
<div class="td"> five </div>
<br/>
<div class="table">
<div class="td"> one </div>
<div class="td"> two </div>
<div class="td"> three </div>
<div class="td"> four </div>
<div class="td"> five </div>
</div>
</body>
</html>
Now the interesting thing is, if you put a lot of content in one of the parent-less table-cells above - enough to predictably fill whatever defined width, regardless of screen size, then ALL the other tables-cells (regardless of their content) will divide the remaining width up amongst themselves and fill the overall container width too.
So to clarify my original point; To get table-cell divs behaving predictably as far as width settings are concerned (and regardless of their inline text content) they also need a wrapper set to display:table; width:100%; Otherwise, you're relying on content (difficult if you're working with user generated content) and/or viewing device/container width (highly variable in responsive design)
molendijk
07-12-2015, 10:30 PM
When I first started working on my website I used tables for my layout. After that I abandoned the idea of getting my website to do table gymnastics in order to get my website to behave the way I wanted and moved to a css layout. What I had heard was that tables were good for working with tables, but was not often a good idea for website layout and floats and whatnot were better.
What you hear and what you observe yourself are different things. I can imagine a situation in which a person who knows his tables could use them in a responsive design environment. Tables respond well to something like:
<style>
td {display: table-cell}
td {width: 30%}
td {text-align: left}
img {width: 100%}
@media screen and (max-width: 799px)
{
td {display: block}
td {width: 100%}
td {text-align: center}
img {width: 40%}
}
</style>
This would work well with 3 td's.
molendijk
07-12-2015, 10:46 PM
So to clarify my original point; To get table-cell divs behaving predictably as far as width settings are concerned (and regardless of their inline text content) they also need a wrapper set to display:table; width:100%; Otherwise, you're relying on content (difficult if you're working with user generated content) and/or viewing device/container width (highly variable in responsive design)
True! You convinced me.
Beverleyh
07-12-2015, 10:53 PM
. I can imagine a situation in which a person who knows his tables could use them in a responsive design environment.
Yes, this is true (as far a manipulating element/block behaviour with CSS goes), but when talking about a whole layout, semantics play a more important role, and because of this, tables should only really be used for statistical data.
Take the CSS away for a moment and think about what a search engine spider reads in the markup. The tags used to markup a web document offer structural cues in the way it should interpret the information it finds there. So something like a div points a spider to structure, whereas table, tr, th/td tags set the scene for statistical data.
There's also all the extra tags needed for table based layouts - and browsers need to parse them all (reading to the closing </table> tag) before they can interpret organisational structure and draw it to the screen, making them slower to render than div layouts.
And not forgetting that accessibility can be hindered with table based layouts (quite badly with heavily nested ones).
Saying that, I naughtily use tables for layout now and then o_O especially with forms. In fact, Arie's responsive table demo is pretty much how I handled this contact form http://fofwebdesign.co.uk/contact.php
Of course if what you're laying out and displaying just so happens to be a bus timetable, then Arie's responsive table demo is an excellent example of how to handle tables in responsive layouts :D
molendijk
07-12-2015, 11:29 PM
Beverleyh, you're absolutely right in all respects. But James seems to be at home with tables and his (original) table structure was not complicated. So this was ment to allow him to go back to tables if he wanted.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.