On my webpage the right side bar is at the bottom of the main content. and is not properly aligned with the main content section. The CSS code for the right side bar is:
#sidebar{
background: #ddd;
float: right;
}
There is a <div> section named sidebar-wrap which is the container for the sidebar that has the following code:
#sidebar-wrap {
float: right;
width: 200px;
padding: 20px;
margin-top: 20px;
margin-bottom: 20px;
padding-left:20px;
padding-right:20px;
}
You have right-side padding that pushes the text to the left. Just remove that if you don't want it. E.g.
#sidebar-wrap {
float: right;
width: 200px;
padding: 20px;
margin: 20px 0;
background: rgb(221, 221, 221);
}
Update: I've moved the background color to #sidebar-wrap and replaced the padding, for a better effect.
Also, for the sidebar to sit beside the main content, you need to move it above the .entry-content div. There are other ways to do this and keep the content first in the HTML, but this is the easiest way to do it if you don't mind the sidebar coming first in the HTML.
Here's an example of re-ordering the code (with a few inline styles for simplicity, though they should be moved to the style sheet, of course):
<h1>Main Content</h1>
<div id="sidebar-wrap" style="margin-top: 0; padding-top: 0;">
<div id="sidebar">
<p>this is the sidebar.</p>
</div>
</div>
<div class="entry-content" style="overflow: hidden;">
<p>There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, “Oh dear! Oh dear! I shall be late!” (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.</p>
<p>In another moment down went Alice after it, never once considering how in the world she was to get out again. The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well.</p>
</div>
you need to add 2 extra divs and increase the size of page to 800px or so, add two divs ie
.leftDiv {
float:left;
width:500px;
}
.rightDiv{
float:right;
width:295px;
}
.clear{
clear:both;
}
the divs need to seperate the text and the side bar so for example:
<div class="leftDiv">
<h1>Main Content</h1>
<div class="entry-content">
<p>There was nothing so VERY remarkable in that; nor ll.</p>
</div>
</div>
<div class="rightDiv">
<div id="sidebar-wrap">
<div id="sidebar">
<p>this is the sidebar.</p>
</div>
</div>
<div class="clear"> </div>
Related
So I've been looking for days and can't find a way to do that.
I made a WordPress site, and my homepage is displaying the most recent posts I've made.
Thing is, the content of a post is written with some specific layout, and it is meant to stay that way. The layout cannot change! I need the text to stay in the exact same place, even if it becomes way smaller and less readable when looking at the site on a smartphone.
Of course, the site is responsive. Only thing I don't want to be responsive is the content of a post.
I've tried a lot of things, but I can't find a way to make it... This page shows exactly what I'm looking for, except that I don't want the post to be re-sizable by the user. I just need it to fit the parent div.
.responsive-wrapper {
border: 3px solid black;
}
.post-content {
position: relative;
width: 100%;
height: 100%;
padding: 10px;
}
.txt-top-right {
display: block;
float: right;
margin-left: auto;
padding-right: 20px;
}
.txt-under-top-right {
clear: both;
}
.txt-center {
text-align: center;
}
.post-content img {
display: block;
max-width: 200px;
float: right;
padding-right: 20px;
}
<div class="responsive-wrapper">
<div class="post-content">
<p class="txt-top-right"><em>Div right-top corner</em></p>
<p class="txt-under-top-right">
Div following the one on right-top corner
</p>
<div class="txt-center">
<h2>h2 in the middle of the page</h2>
<h1>h1 in the middle of the page</h1>
<h3>h3 in the middle of the page</h3>
</div>
<img src="http://cs.pes.edu/wp-content/uploads/2016/06/default.jpg" />
<p>
paragraph<br> on the left side<br> of the page<br> describing<br> a lot of things<br> on a lot of lines
</p>
<p>
Adress<br> City<br> Country
</p>
</div>
</div>
I understand HTML/CSS/JS, but I am struggling with JavaScript... I can insert some <script> tags in my html header with functions in it, but I have hard times understanding what these functions do.
I'd like the layout to stay the exact same way, doesn't matter which device the user is on. For instance, I want the .txt-top-right paragraph to take this amount of space. On a smartphone, the font size shouldn't re-size and fill up more than this amount of space of the container...
This is an example of what is happening right now when re-sizing the window. The layout changes completely !
Thank you for reading, hope it was clear enough :)
Basically I simply want to make it so that this website
NO LINK
doesn't get squashed when you make the page smaller than the elements that have been defined. However I want the elements to remain at the exact same size they are at, for obvious design issues. Therefore I need a simple horizontal scroll bar or something, but when I've messed with such a design it doesn't seem to make much difference. If you need any coding, or have any questions.. Feel free to ask.
If you notice when you make the page smaller in the horizontal margin, the sidebar gets shoved into the main content. That is one of the main issues, and I figured it would be a good idea to point it out. Just to show part of the problem.
ANSWER
#Wrapper{
overflow: auto;
z-index: 6;
min-height: 1400px;
width: 100%;
min-width:1400px; <--- Added that to make sure that the content never gets squashed.
}
You could tell your sidebar to be always posioned next to your main container. To do that you need first of all to give a class name to this div:
<div style="padding-bottom:15px;">
<p align="center"><font size="+2">SITE UNDER CONSTRUCTION</font></p>
....
</div>
Once you do that you need to put your #Sidebar inside that div to get something like this:
<div class="mycontentclass">
<div id="Sidebar">
<div style="margin-left:5px;">
Home<br>
...
</div>
</div>
<p align="center"><font size="+2">SITE UNDER CONSTRUCTION</font></p>
....
</div>
And then in your CSS styles you need to add:
.mycontentclass{
padding-bottom: 15px; //This is the attribute you defined inline before setting a class for you div
position: relative;
}
#Sidebar{
position: absolute;
left: -205px; //Sidebar width + gutter between the content
}
And now your menu won't go over your content, it'll stay always next to it.
This is what I used to fix the problem.
#Wrapper{
overflow: auto;
z-index: 6;
min-height: 1400px;
width: 100%;
min-width:1400px; <--- Added that to make sure that the content never gets squashed.
}
I'm working on a project to better my knowledge of Spring MVC practices. To do this, I've been creating a very scaled down version of Twitter. Basically, a user can sign in and post a little blurb and also see a timeline of their previous blurbs and all their follower's blurbs.
I have a background image across the whole page and a container in the middle with a light blue background for just the post blurb box and the timeline. The light blue background only goes to the bottom of the visible page. If the timeline goes down past a single page view where you have to scroll down, the light blue background stops at the bottom of what was visible on the initial load.
I have my page defined like this:
The div class=blurb is the blurbs in the timeline.
<div id="container">
<div id="mainPanel">
<div id="timeline">
<div class="class="blurb"">
<span class="user">test</span> <span
class="displayName">Test User</span> <span class="bodytext">This is a small blurb.</span>
<span class="timestamp">1 hours ago</span>
</div>
<div class="blurb">
<span class="user">admin</span> <span
class="displayName">Test admin</span> <span class="bodytext">This is another small blurb.</span>
<span class="timestamp">1 hours ago</span>
</div>
</div>
</div>
</div>
The CSS style for the container is shown below.
#container {
width: 650px;
height: 100%;
margin: 0 auto;
padding: 10px;
background-color: #DDEEF6;
}
Can I modify that container CSS in a way to make it be as long as the timeline is? The timeline grows with every blurb post.
Screenshot with height defined to 100%
Screenshot with height undefined
UPDATE:
Okay, so it absolutely has to do with the floats. Thanks to the two commenters below. The #socialPanel is defined as such:
#socialPanel {
width: 250px;
float: right;
}
Using Chrome's developer tools, if I clear the float is drops the social panel below my blurbs/tweets and moves the light blue background all the way down the list of blurbs.
Any suggestions on what I could research to keep the socialPanel floating left at the top, but still have my light blue background use all the available height? Many thanks on helping me figure it out this far!
UPDATE TWO:
I combined the methods shown in the answer below to solve my problem. I added a div with class clearer with clear:both; and then removed the height: 100%; from the #container styling. This resolved the problem.
NOTE:
Adding the overflow: hidden; to my container's styling made the page cut off after the light blue area, it did not make the light blue area go all the way down.
Many thanks to all the help! I'm still learning and it was all very appreciated!!
Place overflow:hidden on the #container.
How does it work?
One would think placing this style on a container would hide the floats instead of containing them. What actually happens is that overflow:hidden makes the element establish a new block formatting context. This fixes the float containment of any children floating within it. This CSS fix is more practical then including an additional element in the HTML styled with clear:both and works on all modern browsers, including IE7+.
You probably just need to add a clearing div after your two inner divs. http://jsfiddle.net/c3vTU/1/
<div class="outer">
<div class="inner-left"> Stuff on the left</div>
<div class="inner-right">Stuff on the right <br/><br/></div>
<div class="clearer"> </div>
</div>
CSS
.outer {
width: 520px;
padding: 10px;
background-color: #eee;
}
.inner-left {
float: left;
width: 300px;
background-color: red;
}
.inner-right {
float: right;
width: 200px;
background-color: yellow;
}
.clearer {
clear: both;
}
As #MichaelIrigoyen noted, you can also just add overflow: hidden or overflow:auto (I think makes more sense) to your container. http://jsfiddle.net/c3vTU/4/ This is cleaner and I love it!
If you simply remove the height declaration (height: 100%;) from #container, it will expand as its children do (and the background of course, too).
Could someone please help me position my footer correctly in my webpage?
I have the following layout:
This is how I want the footer to behave:
The footer should be positioned at the bottom of the page when the content is empty.
The footer should be 'pushed' down when the content exceeds the height of the page.
here is my HTML:
<html>
<head>
<title>#ViewBag.Title</title>
</head>
<body>
/* This is outside of the container as I want the background
to stretch across the top of the webpage */
<div id="menu">
<div>
/* This contains an unordered list which is restyled as a series of links.
The reason it is contained in inside the menu div is because I want this
content to be centred. /*
</div>
</div>
<div id="page-container">
<div id="header">
<h1>Website title</h1>
</div>
/* This is floated to the left of the content area. */
<div id="content">
#RenderBody()
</div>
/* This is floated to the right of the content area. */
<div id="sidebar">
#RenderSection("sidebar", false)
</div>
</div>
<div id="footer">
My footer content goes here.
</div>
Please note the following:
The content and header is contained in a 'Div' called 'page-container'.
The content is made up of two Divs which are floated to the left and right of the content area.
The menu is outside of the page-container div. This is because I want the menu background to stretch across the top of the page (like the Stackoverflow menu)
I am aware that there are many similar questions on Stackoverflow and that a Google search will return a large amount of results.
The thing I have noticed whilst trying to adapt the samples I have found is that they usually depend on a very specific html structure (E.G. everything but the footer is in a container) that does not match mine. No matter what I try I end up with something that doesn't work (E.G. the footer is positioned below the screen bounds when the content is empty or is not moved down when the content exceeds the page).
Update
I can get my footer to stick to the bottom of the page but it is not pushed down when my content expands. I think this is because my content is made up of two floating elements.
Most people seem to be pointing me to tutorials they have found on Google (as already stated I have read most of these and already attempted to adapt them).
I have come to the conclusion that I am going to have to restructure my HTML to get this to work; the point of my question was how do I do this with the HTML I already have? So much for separation of concerns!
A quick google search gave me a few links that you'll find useful.
http://www.cssstickyfooter.com/
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
I would stick to with the first one, but either should do what you want.
I made a fiddle: http://jsfiddle.net/karlroos/ZVkYC/ (sorry for the badly organized CSS)
Take a look. You'll have to make some workaround for the min-height: 100%; in older versions of IE, presumably with JavaScript.
As mentioned in the edit to my post, I ended up having to alter my HTML slightly:
<body>
<div id="page-container" >
<div id="menu">
<div>
</div>
</div>
<div id="layout-container">
<div id="header">
<h1>Website title</h1>
</div>
<div id="content">
#RenderBody()
</div>
<div id="sidebar">
#RenderSection("sidebar", false)
</div>
</div>
</div>
<div id="footer">
</div>
My CSS is based on CSS found here (This same link was posted by a couple of people but I was already using this anyway!)
The solution is about 99% effective. My footer sticks to the bottom of my page when the content area is empty and is also pushed down when the content grows larger than the screen but I now have a permanent scrollbar as my page height seems to be off (moving the mouse-wheel scrolls the page up and down by a single pixel).
I have so far been unable to get rid of this so I am begrudgingly accepting this as a complete solution unless anyone else can point me in the right direction.
Update
It seems the 1 pixel offset was caused by my footer having a 1 pixel top border. I simply adjusted my CSS to account for this and the scrollbar disappears when the content does not completely fill the screen.
#footer {
margin-top: -151px;
height: 150px;
}
Try editing your CSS to include something like the following:
#footer {
width: 710px;
height: 50px;
margin: 0 auto;
padding: 40px 0 0 0;
}
#footer p {
margin: 0;
text-align: center;
font-size: 77%;
}
#footer a {
text-decoration: underline;
}
#footer a:hover {
text-decoration: none;
}
Then call it in your footer.
Wrap your div-s in a wrapper:
#wrapper {
width:100%;
height:500px;
background:#ccc;
margin:auto;
position:relative;
}
and use the following CSS for your footer:
#footer {
width: 100%;
height: 80px;
background-color: #ccc;
position:absolute;
bottom: 0;
}
Have you tried setting the body to position:relative and the footer to position:absolute with bottom:0 ?
Consider the following 2 cols html structure:
<div id="container">
<div class="left">some text</div>
<div class="right">some text</div>
</div>
CSS:
#container { overflow: hidden; }
.left { float: left; width: 200px; background: red; }
.right { overflow: hidden; background: green; }
The same code in jsFiddle - http://jsfiddle.net/vny2H/
So we have 2 columns. The left column width is fixed, the width of the right one is liquid.
If we remove the left column from html, the right column stretches to 100% of parent #container width.
The question is: can we change the order of the left and right columns?
(I need it for SEO)
<div id="container">
<div class="right"></div>
<div class="left"></div>
</div>
Thanks.
Added
There's one interesting method to reach what I want, but fixed column becomes not removable. The method is based on negative margin. http://jsfiddle.net/YsZNG/
HTML
<div id="container">
<div id="mainCol">
<div class="inner">
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
</div><!-- .inner end -->
</div><!-- .mainCol end -->
<div id="sideCol">
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
<p>Some text</p>
</div><!-- .sideCol end -->
</div><!-- #container end -->
CSS
#container { overflow: hidden; width: 100%; }
#mainCol { float: right; width: 100%; margin: 0 0 0 -200px; }
#mainCol .inner { margin: 0 0 0 200px; background: #F63; }
#sideCol { float: left; width: 200px; background: #FCF; }
So we have 2 ways:
Using "float" for the fixed column and "overflow: hidden" for the liquid. Fixed column becomes removable. But liquid one goes second in code.
Using negative margin. Liquid column goes first in code. But fixed one is not removable.
Is there a third way, when fixed column is removable and liquid one is the first in code?
Added
Half-decision has been suggested by #lnrbob. The main idea - using table-like divs. http://jsfiddle.net/UmbBF/1/
HTML
<div id="container">
<div class="right">some text</div>
<div class="left">some text</div>
</div>
СSS
#container { display: table; width: 100%; }
.right { display: table-cell; background: green; }
.left { display: table-cell; width: 200px; background: red; }
This method is suitable, when a fixed column is placed to the right in a site. But if we need it to the left - it seems to be impossible to do this.
Consider the semantics of the content you are marking up before anything else, that will almost always lead to a solution that has both decent markup and is search engine friendly.
For instance, is .right the main content of the page, and .left some supplementary information or navigation? In that case, mark it up as such and the search engines will do a good job of interpreting it the way you want them to. HTML5 provides many elements for just this purpose:
<div id="container">
<nav>
<ul>
<li>Home</li>
<li>etc.</li>
</ul>
</nav>
<article>
<h1>My nice, juicy content</h1>
<p>Cool stuff, huh?!</p>
<article>
</div>
Or for supplementary content you might consider <aside> or simply <div role="supplementary">.
Google will happily scrape that and recognise the difference between the navigation and the actual content, the idea that source order is important no longer applies to SEO in the same way it did a few years ago.
Because your elements have same height you can do this:
#container { overflow: hidden; position:relative; }
.left { float: left; width: 200px; height: 200px; background: red; position:absolute; top:0; left:0; }
.right { overflow: hidden; height: 200px; background: green; margin-left:200px;}
Fiddle page: http://jsfiddle.net/Ptm3R/9/
I still think that this is a rather pointless endeavour, because the only reason to try is for dubious SEO benefits. But, I've been dragged back to this question so many times that I'm going to bring something to the table.
If I was forced on pain of death to come up with a pure CSS solution, this is it - but I don't recommend it:
http://jsfiddle.net/RbWgr/
The magic is transform: scaleX(-1);. That's applied to .container to flip the visual order, and then also to the child divs so that the content of each div is not flipped.
It won't work in IE7, because I'm using display: table-cell.
It's not so hot in IE8 - any text looks horrible, as is usual with filters. But, it does work.
Extra div wrappers were required to make it work in Opera - and the text doesn't look perfect.
It works fantastically in other modern browsers (IE9, Chrome, Safari, Firefox), but applying transforms to a parent of "every element" might have unforeseen consequences.
To be honest, I'm not sure why you're boiling it down to having to use only two id's ( [#left / #right] OR [#mainCol / #sideCol] )...
Would it not be far easier to use the mainCol/sideCol solution you had in JSFiddle at http://jsfiddle.net/YsZNG/ and introduce a third class that could be applied to the main div in the absence of the sideCol programmatically.
As in http://jsfiddle.net/biznuge/aAE3q/4/
Sorry. I may well have missed the point of all this, but I've had previous gut wrenching agony with trying to work in fluid/fixed mixture sites so just thought I'd share my own feelings on the matter...
UPDATE
I provided a second answer to this now that I think works. Sorry to double answer but it seemed sufficiently different from my initial response that I thought it would stand on its own two feet.
Depends on your browser support requirements. For IE8 and above (and all modern browsers) you could use display: to set a table layout (still using your <div />'s of course.)
Here is an example -I've only added javascript so you can toggle whether the element is hidden or not easily :)
How about putting the left col inside the right one at the bottom?
http://jsfiddle.net/vny2H/32/
http://jsfiddle.net/biznuge/aAE3q/12/
this seems to satisfy the brief I think. Works in FF anyway, but I'm unsure how other browsers might react to the table type display attributes.
UPDATE
Have tested this in FireFox(4), IE(9), Opera(11), Safari(5)[Win] and Chrome(12) and the layout seems to be robust across all browsers.
Rather surprising really...
UPDATE FOLLOWING CLARIFICATION
thanks to #thirtydot for that
http://jsfiddle.net/biznuge/aAE3q/19/
Works ONLY in Firefox 4 as far as I can tell, after some brief checking... But it's a start...