What is the best way to implement this particular layout?

I want to have something like StumbleUpon for my website to view external articles. There is a sidebar for comments, etc. Here's the jsfiddle for her.

What I've done

HTML

<div id="header">Head</div> <div id="sidebar">Sidebar</div> <iframe id="article" src="http://cnn.com"></iframe> 

CSS

 html,body{width:100%;height:100%;overflow:hidden;} #header{width:100%;height:49px;border-bottom:1px solid #000;} #sidebar{height:100%;width:249px;border-right:1px solid #000;float:left;} #article{border:0;overflow:visible;float:right;} 

Js

 $('#article').height($('html').height()-50).width($('html').width()-$('#sidebar').outerWidth()-1); 

I found many ways to implement this layout, including float, position: absolute, padding, table (definitely not), etc. What is the best way to implement this in terms of compatibility and speed?

+4
source share
7 answers

HTML5 runs IE7 and above (thanks to html5shiv ).

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <style> body,html{ padding: 0; margin: 0; } header{ height: 49px; border-bottom: 1px solid black; background-color: #fdd; } nav { position: absolute; width: 249px; top: 50px; bottom: 0; left: 0; background-color: #dfd; border-right: 1px solid black; overflow: hidden; } body > section { position: absolute; top: 50px; right: 0; bottom: 0; left: 250px; overflow: auto; background-color: #ddf; } </style> </head> <body> <header> Header </header> <nav> Sidebar </nav> <section> <article> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </article> </section> </body> </html> 
+1
source
 <style> #side_bar { width:200px; float:left; } #body_con { overflow:hidden; /*expands to fit in sidebar*/ } #main_content { margin-left:200px; } </style> <div id="header"></div> <div id="body_con"> <div id="side_bar"></div> <div id="main_content"></div> </div> 

Just like that.

0
source
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style> body,html{ padding: 0; margin: 0; height: 100%; cursor: default; overflow: hidden; } #divContainer{ position: relative; height: 100%; } #divHead{ position: relative; height: 100px; border-bottom: 1px solid #ccc; background-color: #eee; } #divMain{ } #divSidebar{ position: absolute; background-color: #eee; border-right: 1px solid #ccc; width: 250px; left: 0; top: 101px; bottom: 0; overflow: hidden; } #divContent{ position: absolute; left: 251px; top: 101px; bottom: 0; right: 0; overflow-y: scroll; } </style> </head> <body> <div id='divContainer'> <div id='divHead'> Header </div> <div id='divMain'> <div id='divSidebar' > Sidebar </div> <div id='divContent' > Content </div> </div> </div> </body> </html> 
0
source

In response to your comment: “I am mainly looking for (in an approximate order of importance) compatibility, usability, speed and clean codes.”

Compatibility . This seems to be your main problem. Your other comment says: “Floats lag behind slow processors, position: the absolute does not work well on touch devices, and indents behave differently in IE.” As tybro0103 pointed out in his comment, populating IE should not be a problem with proper doctype. Regarding the speed of rendering float , see below "Speed". Your concern for position: absolute may seem valid and probably best avoided - but other than that, any other method is unlikely to have any compatibility issues.

Usability . I'm not sure what you mean by this, since you have limited the layout to “this particular layout,” and usability is more of a layout problem (rather than a layout layout).

Speed . I think that the speed will be much more affected by the content of what is in the header , sidebar and article (especially if the article is linked outside the site) than the structure and minimal css used to create the main layout. Even if the float slows down a little on slow processors (I’ve never heard of this problem before, but isn’t it all slower on a slow processor?), Large images, massive javascript, etc. Slow down the page display much more slowly than css float declaration.

Clean codes . Your original violin was pretty clean. Three html elements with four minimal css bits are about as compact as you can get.

0
source

I have never had a position:absolute compatibility issue on touch devices, are you sure you don't confuse it with fixed ? In addition, padding works great in all browsers unless you install IE in quirks mode, and you definitely don't want this for many reasons.

I would use the position: absolute in your layout, this makes sense, since you are squeezing everything inside the body without having a natural scroll stream.

Absolute positioning also has a big advantage; you can f.ex do left:250px;right:0 , and it will expand the available area with a left margin of 250 pixels. I think this is a more logical way to program the liquid layout inside the container instead of hacking the negative fields and using a float.

Another important aspect: using absolute positioning, you can also move the DIV article over the sidebar in the order of content . This is something that many people forget, in most cases for screen readers and search engines it makes more sense to get to the content as quickly as possible.

The disadvantage of this is that IE6 and below do not play the ball, but there are simple workarounds described in this article (as you will see).

The use of floats is still an option, but, as I mentioned, this can cause a big headache, as they are intended for a partial natural flow of layouts.

I would also put an iframe inside the #article div, it makes sense to separate it from the layout grid.

Something like this

 <div id="header">Head</div> <div id="article"> <iframe src="http://cnn.com"></iframe> </div><div id="sidebar">Sidebar</div> 

And CSS:

 html,body { width:100%; overflow:hidden; } #header { position:absolute; left:0; right:0; height:49px; border-bottom:1px solid #000; } #sidebar { position:absolute; top:50px; bottom:0; width:249px; border-right:1px solid #000; } #article { position:absolute; top:50px; left:250px; right:0; bottom:0; } #article iframe { border:none; width:100%; height:100%; } 

Finally some magic for IE5 and IE6 (if you want to go this far):

 <!--[if lt IE 7]> <style> body, #header { width:100% } #sidebar, #article{ height: expression(document.body.clientHeight-50) } #article{ width: expression(document.body.clientWidth-250) } </style> <![endif]--> 

In terms of compatibility , this should be about as compatible as it gets. It works without javascript and its fluids (or "responsive" as it is called now), so it should work in many different screen sizes. You might want to add some media queries to shuffle the layout on the smallest screens, though, depending on how you do the default scaling.

When it comes to speed , there is one big bottleneck regarding rendering speed, and that is the DOM manipulation with javascript. Just leave it and you will make good use of whatever CSS technique you want. (Agreed, the IE5 / 6 expression is not the fastest way to render, but it works great, and we're talking about serious support here ...)

On may argue that using HTML5 elements such as ASIDE , ASIDE and ARTICLE would be appropriate, but you will need an HTML5 script to make this work in some versions of IE, and then you will lose some compatibility for those who have installed javascript.

0
source

It would be best to load the contents into a div container rather than using an iframe and all the problems that arise with this (2 scroll bars for the window / iframe)

Why not use javascript to display page content using AJAX. You can also preload the following sites after loading the current page to save time.

Your layout looks fine, but it may make the sidebar / title slide so that you maximize the target site on your page — stumbling on the title is pretty unobtrusive, and that’s what you should aim to mimic.

0
source

I would put an absolute title, put a sidebar and a content window on the left;

The sidebar will be sharper if you used something like lionbars.js or js.scrollpane to save space and aesthetics.

-one
source

Source: https://habr.com/ru/post/1397494/


All Articles