Here is a nice tutorial on how to create a web layout with a main section and a lateral bar. I´m focusing on the float example.
My question is: is it possible to properly move the position of the lateral bar from the left to the right side? I have changed the lines float: right; with float: left;, margin-right: 170px; with margin-left: 170px; and border-right: 1px solid gray; with border-left: 1px solid gray;.
By doing this the bar shifts to the right side but if I increase the number of the line´s text inside the lateral bar (for example by replicating several times <li>London</li> inside the <ul> tags) the content of the lateral bar overlaps the footer! If I do the same with the bar on the left side (as in the example), the footer correctly shifts to the bottom of the page to accommodate the extra data but than there is a problem with the vertical grey bar that separate the main section to the lateral bar.
How this can be solved? How can the layout be modified to have 2 bars (one on the left and one on the right) with undefined lines of text that do not overlap the footer section?
Use this as your CSS
#left-bar{
float:left;
width:100px;
height:100%;
border-right:1px solid black;
}
#right-bar{
float:right;
width:100px;
height:100%;
border-left:1px solid black;
}
Your HTML will look like this
<div id="left-bar">This is on the left</div>
<div id="right-bar">This is on the right</div>
You have to imagine yourself how a html file is build and how it will be displayed. All containers you have are listed below each other in plain html. With css you can define a floating structure by asigning component dimensions and margins and paddings. To align components horizontally you need to have a wrapping container (r.g. the body or a div within the body) with a fixed pixel size. Then you can define e.g. 3 components, a left side bar, an article middle field an a right side bar. These containers will be childcontainers of the wrapper, so they are defined within. These subcontainers you asign a size, normally by % and fineposition them with margins. In chrome and firefox you can see the margins and paddings in the dev console (press F12) under Box-Model.
Css can be quite frustrating. When I teached it myself by building my own website, I lost plenty of ours with this.
You can check out my website for reference. It's a plain Html/Css website, no positioning by JS or php.
It isn't the most beautiful website but the structure framework works as it should. See here: http://richardrudolph.com/
i am not sure if this is what you want . the navigation is on the right.
<https://jsfiddle.net/zpupster/v659zpod/>
Maybe you want to read more about CSS grids, they make such a work you may find tedious easy.
As for the time being I really did not get your question very well, but I believe if you wrapped every section of your HTML in its proper tag you will be able to just use the CSS float property to put them wherever you want. So the lateral bar I believe this is the aside section which would be in an aside tag
<aside>
<ul>
<li>
this is a dummy link
</li>
</ul>
You would just float the whole aside tag to the right as it will by default be floated to the left, so the CSS
aside{float:right;}
Related
I have just started learning Bootstrap 5. I made a very simple webpage with basic blocks using the row/column guidelines on Bootstrap. One of these columns that I made is not displaying the gutter padding. The other columns are displaying the gutter padding to the left and right, but not the content1 column that consists of the two "posts". I am attaching my HTML and CSS code here.
Here is the webpage that I made in Bootstrap 5: Click Here to View
And I am attaching my CSS code here:
.header1 {
background:#ededed;
border-bottom:1px solid #ddd;
}
.content1 {
padding:40px 0;
}
.post {
background:#ffe6fa;
margin-bottom:30px;
}
.sidebar1 {
padding:40px 0;
}
#widget1, #widget2, #widget3 {
background:rgb(233, 250, 205);
padding:30px;
margin-bottom:30px;
}
.footer1 {
background:#000;
color:#fff;
}
Can you please help me understand what did I do wrong in my code? Why is the Bootstrap gutter padding not displaying for the column with class "content1"?
Thank you so much.
There is a way for Bootstrap to do all the work and you get to shrink down your CSS file too.
blahblahblah{
etc.etc.etc
etc.etc.etc
etc.etc.etc
}
^ done for one tiny UX result eventually adds up to a large file that needs to be loaded by each visitor. You could do it all by adding 4 characters only to your HTML.
You are adding a lot of CSS when Bootstrap will take care of it for you. In the same way that you can add rows and columns to your HTML to make a cool layout where all the CSS is pre-written, you can also add margins and padding to your HTML and the CSS is all automatic too. You've already been doing this by adding gutters (if you were also following the GetBootstrap info for those rather than adding your own).
In your thing above, the two items that require a gutter on their right hand side could just have a little margin on their right hand side, or the column they are housed in could have a little right-side padding.
So, padding in Bootstrap, use any number between 0 and 5. Everything below also applies to Margins, just swap the p to an m.
<div class="p-0">
Padding - None
<p class="p-5">
Padding - Maximum (but you can add CSS)
<a class="pt-0">
Padding Top - None
<h1 class="pb-5">
Padding Bottom - Maximum
In Bootstrap we don't use left and right for some things, we use Start and End.
<nav class="ps-5">
Padding Start (the left side of whatever is being padded)
<footer class="pe-2">
Padding End (the right side of whatever is being padded)
^ That last one can be added to the parent div of your two boxes. Adding pe-2 to your HTML is better than brain-aching over custom CSS? As promised, 4 characters only ;)
Couple of variations...
<img class="px-0">
Padding left and right
<button class="py-0">
Padding top and bottom
The main point is, especially with the layout of the page. Let Bootstrap do the work, adding more and more layout CSS often results in a negative.
The thing is you are adding padding for content1 as padding: 40px 0; which makes the padding zero on both left and right of the content1.
If you want to have some padding,
.content1{
padding: 40px 10px;
}
will do the trick.
And if you want to add some padding to .post classes as well, you can use,
.post{
padding: 30px;
}
On this one particular page, I have added a secondary menu (gray bar) under the primary menu (red bar) to have a few links that, when clicked, will scroll down the page to the correct area.
The secondary menu was, by default, much taller than I wanted it - so by adding a height: 40px; value, I was able to get it to the height I want. The page links, however, stubbornly did not adjust along with the height of the menu and thus, when viewed, they are obviously not in the correct place.
Is there a particular CSS value I can add to try and help this issue? I've tried adjust margin-top, padding-top, vertical-align, etc... and some of that adjusts the gray bar, but absolutely nothing has yet to adjust the text for me.
It doesn't help that I'm using a paid theme I bought rather than one I developed myself (in an attempt to make site management easier for someone else who takes over the site, this is more of a "drag-and-drop" template).
http://www.miltonpreserve.com/about/
It looks like you added the 40px height to the div with the #aboutmen id. However, some of the content nested in that div has padding that makes it taller than that. If you remove the padding from #menu-about-menu you should see the text become visible. Then (if needed) you can add 'vertical-align: middle' to the elements that you have nested in #menu-about-menu.
Here's a simplified version of what you have going on:
HTML
<div class="outer">
<div class="inner">
<div class="text">item one</div>
<div class="text">item two</div>
</div>
</div>
CSS
outer {
height: 40px;
background-color: yellow;
}
.inner {
padding: 30px;
}
This simplified example has the same problem you're experiencing. If you remove the padding from .inner, you'll see that the problem goes away. Here's a
jsfiddle with the same code.
Hope that helps!
I'm currently creating a website and I came across a strange thing: I have a content div that's 950 width and centered on the page. Inside that I have a header div, a menu div and some other content div. I would like the menu div and that other content div to be right next to each other so I thought about using float:left on both divs. However, when I use this float:left on the menu div, it's getting pushed to the right and I can't figure out why. I think some other element is pushing it to the right.
I'm using a custom Drupal theme, a subtheme of Zen to create the page by the way.
Here's the HTML I'm using to create the page (without the header):
<div id="root">
<div class="content">
<div class="left-menu">
<ul>
<li><p>Camera</p></li>
<li><p>Audio</p></li>
<li><p>Licht</p></li>
<li><p>Lenzen</p></li>
<li><p>Grip</p></li>
<li><p>Accessoires</p></li>
<li><p>Recorders</p></li>
<li><p>Transport</p></li>
<li><p>Edit suits</p></li>
<li><p>Crew</p></li>
</ul>
</div>
<div class="products-overview">
This is some other content that I want to the right of the menu.
</div>
</div>
And here are some CSS properties I've set on left-menu and products-overview:
.left-menu {
margin-top: 10px;
background-color: #BBB;
width: 150px;
float: left;
}
.products-overview {
background-color: #BBB;
float: left;
}
Could anyone please explain me why the left-menu is being pushed to the right?
Hmm, I believe this is a result of the normalize.css stylesheet you're using.
The problem stems actually from the .header element, which has a table within it. The normalizing stylesheet has a margin-bottom:1.5em applied to the table, which translates into a margin on the .header element (since it has no padding/border), which in turn sends the .left-menu to the right (since the margin causes there to be no space for it to fit on the left).
Adding to your current .header table definition can fix this, with a simple:
.header table{
margin-bottom: 0;
}
I hope this is what you were looking for! If not, let me know and I'll be happy to help further. Good luck!
I tried to replicate your problem. I did and found a solution that should work. Just set the products-overview class to float:none. See this fiddle. http://jsfiddle.net/shaansingh/yj4Uc/
In Mozilla Firefox it looks ok to me. From your code, I can only see that you need a width for the content div. and watch the dimensions, especially left/right padding and borders.
I am experiencing difficulties when I am trying to Right align text links inside a div. I'm not sure what I am doing wrong. But this is the code for the div that is supposed be right aligned:
<div class="menu">
Home
Sign In
Join The Crowd!
</div>
And all the code is here: http://jsfiddle.net/GSfmf/1
I am wanting the buttons still vertically-centered in the header_div, but aligned to the right. And anything that I do doesn't move it.
Thanks, sorry for being foolish about the css.
Take out display table from your header div. Is there a reason your displaying it as a table?
Works fine when you take out display header
div.header_div{
background-color: #ffffff;
padding: 15px 50px 15px 50px;
}
in the css stylesheet just add the following code...think it wd work
.menu{ float:right;}
I have managed to put two divs side by side using a <div class="clear"></div> as explained elsewhere.
I now want to put two divs side by side, inside a fixed-size box that can scroll horizontally. Vertical space isn't a problem, but the two divs must be side by side and can expand vertically when needed. If space is needed horizontally, they must expand inside the box with fixed width but whose insides can scroll horizontally.
The following code does this with tables, but I was wondering if it can be done with divs as well, to keep the page semantically correct. The div version fails, because it keeps the second pane under the first one, even with a <div class="clear">.
Cheers for any advice!
PS: I can't seem to insert a block of html code in here, so I saved the file here: http://husnoo.com/scroll1.html (tested with chrome and safari, open the source code to see what I mean).
give the right box float:right;and it will stick to the right side :)
http://jsfiddle.net/loktar/Mbs3q/1/
div#wider {
background-color: #ddd;
width: 700px;
float:left;
}
.second_pane{
background-color: #eee;
width: 300px;
float: left;
}
Is that what your looking for? Floats them both to the left so they stick to each other, and are inline.