Content overflowing off page with bootstrap - html

I am using bootstrap and I am making my website when I created a fixed navigation bar on the left side of my page with the width of 250px and then I have a div to the right of it being my page content, I have set the width of that to 100% and inside that I have a col-lg-12 and the content is leaking off the page, I was wondering if anyone knew a solution to this so that the content box is only the width of the remaining width of the page instead of being always 100% of the page width, If you need the code I can upload it to pastebin or something like that. But I am putting just some lil tid bits of the code here. And if any more info is needed just comment.
.navigationWrapper {
position: absolute;
float: left;
width: 250px;
height: 100%;
background-color: black;
}
.contentWrapper {
left: 255px;
position: absolute;
float: left;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="navigationWrapper">
<div class="navIcon">
<span>ICON</span>
</div>
</div>
<div class="contentWrapper">
<div class="col-sm-12 test">
<h1>Test</h1>
</div>
</div>

you can use Flexbox to do this:
JsFiddle. There are some height properties, which should be fixed.
.wrapper {
display: flex;
}
.navigationwrapper {
flex: 0 0 250px;
}
.contentWrapper {
flex: 1 0 auto;
}
with flex: 1 0 auto you can grantee that the element will grow and take the rest of the space left.
and this is your updated Fiddle https://jsfiddle.net/Marouen/n9v4Ly7e/

You can use calc() in your CSS because the width of your container is not 100% but 100% - menu width
It makes something like : width: calc(100% - 255px); because you are starting your container from 255px left.
updated js fiddle
PS : i also added background-color:black; to your .navNav{} so the background works even if the viewport is smaller than the size of the menu.

The issue you are having is that the width: 100%; you have applied to the .contentWrapper referances the width of it's parent (in this case the body) and not remaining space. You can use width: calc(100% - 255px); (see updated example below) to fix the issue. Flex-box is also reasonable solution, but this is what was causing the issue.
.navigationWrapper {
position: absolute;
float: left;
width: 250px;
height: 100%;
background-color: black;
}
.contentWrapper {
left: 255px;
position: absolute;
float: left;
width: calc(100% - 255px);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="navigationWrapper">
<div class="navIcon">
<span>ICON</span>
</div>
</div>
<div class="contentWrapper">
<div class="col-sm-12 test">
<h1>Test</h1>
</div>
</div>

Related

Fluid div next to fixed div

I have the Bootstrap framework for basis of the website.
Now, the main content is let's say is 1000px wide.
Then I have this 100% wide area, inside of which I have centered 1000px area.
But...
The left section is fixed width of 290px.
The right long section is fluid width and starts right from the border of the left section and it ends where the 100% wide container ends.
Inside of the right long section is 710px fixed content.
I want to have fluid width right content.
Image slider or google map or something.
I think the basic html should be:
<div class="wide_container">
<div class="container1000px">
<div class="left290px">
</div>
<div class="rightFluid">
<div class="right710px">
But inside of this the image slider should be wider than 710px.
And this website is responsive, too.
</div>
</div>
</div>
</div>
Thanks a lot for any ideas!
(Full image)
set .rightFluid to min-width:710px and add class pull-right.
.rightFluid{
min-width:710px;
}
<div class="rightFluid pull-right">
I think, this should work.
You can see reference here: http://jsfiddle.net/ashishanexpert/B8L6L/
for that u need to use structure like table -->
right-box will be fluid
<div class="table row-fluid">
<div class="left-box"></div>
<div class="center-box"></div>
<div class="right-box"></div>
</div>
<style>
.table {
display : table;
}
.table > .div {
display: table-cell;
}
.left-box {
width: fixed-with;
}
.center-box {
width: fixed-with;
}
</style>
in that photo i saw u need fluid space for left side that i dont know what should be the rule for width (fluid - something related to parent tag) , any way this link may be help u by extra little information about how this is work ,
Check here
in that link u saw the gray part , that gray part is fluid , other color part got fixed width , in any table if u use fix width for some table-cell and leave other with out set any width they will fill remind width n if this answer is not helpful it must be misunderstanding from me of ur problem
.table {
display : table;
height: 400px;
width: 100%;
background-color: #808080;
}
.table > div {
display: table-cell;
}
.right-box {
width: 300px;
background-color: blue;
}
.center-box {
width: 100px;
background-color: red;
}
OK guys, finally found the solution
HTML:
<div class="table">
<div class="row hidden">
<div class="cell"></div>
<div class="cell-centered">fixed width 600px; row in yellow just to show cell alignment, actually goes "hidden"</div>
<div class="cell"></div>
</div>
<div class="row">
<div class="cell">
</div>
<div class="cell-fixed"><div class="fixed"><br>fixed width 200px<br><br></div></div>
<div class="cell relative">
<div class="outer absolute"><div class="inner absolute">100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100% 100%</div></div>
</div>
</div>
</div>
<div class="container"></div>
CSS:
body {margin: 0; text-align: center;}
.table {width: 100%; position: fixed; top: 50px;}
.row {display: table-row;}
.cell {
background: #ccc;
display: table-cell;
width: 50%;
}
.cell-centered {
background: #aaa;
display: table-cell;
min-width: 600px;
}
.cell-fixed {
background: #bbb;
display: table-cell;
min-width: 200px;
}
.fixed {
background: #1dcf53 ;
width: 200px;
}
.hidden .cell {background: #f0ff00 ;}
.hidden .cell-centered {background: #e0ee00;}
.relative {position: relative;}
.absolute {position: absolute;}
.outer {
width: 100%;
padding-right: 400px;
right: 0;
}
.inner {
background: #1dcfa6;
width: 100%;
right: 0;
}
.container {
background: #eee;
width: 600px;
height: 300px;
margin: auto;
}

2 div floated but same height

Here's my html
<div class="container">
<div class="box">
<div class="float">
<img src='http://media-cdn.tripadvisor.com/media/photo-s/03/9b/2f/db/miami-beach.jpg' />
</div>
<div class="float float_txt">
text here!
<p class"a_p">a</p>
<p class"b_p">b</p>
<p class"c_p">c</p>
</div>
</div>
</div>
and css
.container{width:400px}
.box{display:inline-block}
.float{width:50%; float:left}
.float img{width: 100%; height:auto;}
.float_txt{background:red}
http://jsfiddle.net/MdtR8/1/
.container has a dynamic width (responsive design) and image will auto-resize itself.
I need to have .float_txt at same height as image, but I need a REAL height because I must divide a b c in percentage. Example:
.a_p, .b_p{height: 20%}
.c_p{height:60%}
How I can to this? only css no js :S
Why don't you solve it with JQuery. Here is the example of JQuery to calculate the height of .float img and add it to float_txt height.
$(".float_txt").css({
'height': $('.float img').height()
});
It's just one solution using JQuery. It's absolutely easier than using only css.
Jsfiddle
Here's one of the approaches.
I don't consider it to be the answer neither an elegant solution but this is one of the workarounds which actually meets the most important condition - it works (with some restrictions).
Here's the fiddle
First, we must assume that everything inside the .float_txt will be wrapped within those three paragraphs - they're meant to be 20%, 20% and 60% which is 100% all together so there's no more space for any other elements. Next, we wrap all three paragraphs with a div and put a copy of the image next to this div. We'll add the id="speculate" to the image.
The whole HTML will look like that:
<div class="container">
<div class="box">
<div class="float">
<img src='http://media-cdn.tripadvisor.com/media/photo-s/03/9b/2f/db/miami-beach.jpg' />
</div><div class="float float_txt">
<img id='speculate' src='http://media-cdn.tripadvisor.com/media/photo-s/03/9b/2f/db/miami-beach.jpg' />
<div class='content'>
<p class="a-p">a</p>
<p class="b-p">b</p>
<p class="c-p">c</p>
</div>
</div>
</div>
</div>
We'll use the #speculate image to set the height of the .float_txt div. The image will have visibility: hidden which makes it invisible but still occupying_ the space in its container. The .content div will be positioned absolutely and spread to the whole space of the .float_txt with top:0; right:0; bottom:0; left:0.
The paragraphs will be also positoned absolutely and placed with the top property. The disadvantage here is the fact that we must know the percentage heights of the preceding paragraphs, e.g. to position the second paragraph we must set top: 20% because the first paragraph has height: 20%. I hope it's clear.
The whole CSS will look like this:
.box {
display: inline-block;
}
.float {
display: inline-block;
width:50%;
}
.float img {
width: 100%;
height: auto;
}
.float_txt {
background: red;
position: relative;
}
#speculate {
width: 100%;
visibility: hidden;
display: block;
}
.content {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.content p {
margin: 0;
position: absolute;
}
.content .static {
position: static;
}
.a-p {
height: calc(20% + 20px);
top: 20px;
}
.b-p {
height: 20%;
top: calc(20% + 20px);
}
.c-p {
height: 60%;
top: calc(40% + 20px);
}

Let div fill up space next to centered container

I have a webpage containing a centered container with content and I want to display a logo next to it.
The layout is as following: div - container. Where the container is centered and the div lef of the container needs to fill out the width left on the screen.
html, body {
height: 100%;
width: 100%;
}
#container {
width: 800px;
margin-left: auto;
margin-right: auto;
min-height: 100%;
}
<div id="container">
</div>
<div id="lef">
</div>
A jsfiddle with this code is available on http://jsfiddle.net/7QJQn/
This is the option that comes closed
http://jsfiddle.net/7QJQn/4/
I think that the best solution for doing something like this is just using javascript / jQuery.
Depending on which browsers you wish to support, you could use calc().
Basically, you want 50% of the viewport width (50vw) minus half of width of #container (so you're measuring from the center of your #container and you use half of all the values) - I'm assuming that you're OK with absolute positioning #lef to the viewport to keep it to the right?
CSS (fiddle here):
#lef {
background-color:yellow;
width:calc(50vw - 100px);
height:20px;
position:absolute;
right:0;
top:0;
}
Add this to your css:
#lef{
float:left
}
And change the order of the divs in the html, like this:
<div id="lef"></div>
<div id="container"></div>
First of all, you should wrap your markup in a wrapper div so elements stay tight.
I made some changes, take a look:
<div id="wrapper">
<div id="lef">
</div>
<div id="container">
</div>
</div>
​
And the css:
html, body {
height: 100%;
width: 100%;
}
#wrapper{
width: 360px;
}
#container {
width: 200px;
margin-left: auto;
margin-right: auto;
height: 100px;
background-color:red;
}
#lef {
background-color:yellow;
width: 160px;;
height:100px;
float: left;
}​
Example
If using flexbox is an option, you can do this with the flex-grow property:
With the following markup
<div class="main-row">
<div class="filler"></div>
<div class="row-content">Fixed width centered div</div>
<div class="filler"></div>
</div>
you need to set flex-grow: 1 on the filler divs. See this fiddle.

CSS Using div to simulate tables

I'm new as webdesigner and I have to create a portion of a page that has 3 columns: a menu on the left side, the central body and a vertical banner. I can't use tables, so I've created a similar HTML:
<div class="Body">
<div class="LeftMenu">My menu</div>
<div class="Content">Foo body</div>
<div class="VerticalBanner">My menu</div>
</div>
While the CSS:
.LeftMenu {
width: 20%;
}
.Content {
margin: auto;
left: 20%;
position: absolute;
top: 0px;
width: 60%;
}
.VerticalBanner {
left: 80%;
margin: auto;
position: absolute;
top: 0%;
width: 20%;
}
So, my problem using that code is that the parent div (Body) takes the height of the first div (LeftMenu), which is not the bigger. This causes the content of "Content" and "VerticalBanner" to flow out "Body" and to go under the Footer div. If I use the float attribute, the "Body" div collapse without dimensions and then the footer div slides under the three columns inside "Body".
I also tried with display attribute, but Internet Explorer doesn't support this and some columns have strange behaviour.
What is the correct way to do this?
I think you should use floats for your DIVs. It's much easier after that to move them around.
Use display: table-*:
.Body { display: table; }
.Left, .Content, .VerticalBanner { display: table-cell; }
See e.g. this JSfiddle.
To stop the body div from collapsing you can use
.body{ overflow: hidden; }
I'm don't think you need position absolute.
<div class="Body">
<div style="width:20%;float:left;">My menu</div>
<div style="width:60%;float:left;">Foo body</div>
<div style="width:20%;float:left;">My menu</div>
<div style="height:1px;font-size:1px;clear:both;"> </div>
</div>

How to make this background stretch throughout the whole website

Hi Guys I have this site:
http://www.ryansammut.com/orijen/
Basically so far I managed to make the top part strech as a background, now I need to make the other parts too. I'm not sure how to do it, so I'm asking for ideas how this would be done best, keeping the positioning all relative and the background image would adjust according to the needed content area.
PS. This is only needed for resolutions greater than 1280px, so zoom out if you need to see what's happening.
You can not stretch those elements because they are contained in a div named 'wrapper', which has a maximum width of 1280px.
add the following properties to : header, contentbackground, and footer:
margin-left:auto;
margin-right:auto;
this will make sure the elements are centered.
then remove the width property from #wrapper, and add the background to it so it reads as follows :
#wrapper {
position: relative;
margin: 0 auto;
top: 0px;
padding: 0px;
background-image: url(../images/contentBG.png);
}
However, now we won't see the horizontal stretch of the header anymore, so we need to move #header above #wrapper.
<div id="header">
...
</div>
<div id="wrapper">
...
</div>
Don't use tables, use DIVs only.
No need to include FlowPlayer script two times.
I dont see you use JQuery (no need to include that).
Replace Dreamweaver's rollover images with proper CSS:
.item {background: image.jpg}
.item:hover {background: image_rollover.jpg}
Get sprite images (you can read here: http://css-tricks.com/css-sprites/)
As the original question... you have to use two DIVs for each "row", like this:
#header_wrapper {
float: left;
width: 100%;
background: header_backgroud.jpg;
}
#menu_wrapper {
float: left;
width: 100%;
background: menu_backgroud.jpg;
}
#content_wrapper {
float: left;
width: 100%;
background: content_backgroud.jpg repeat center top;
}
.wrapper {
margin: 0 auto;
width: 1260px;
}
<div id="header_wrapper">
<div class="wrapper">
--- header content ---
</div>
</div>
<div id="menu_wrapper">
<div class="wrapper">
--- menu content ---
</div>
</div>
<div id="content_wrapper">
<div class="wrapper">
--- page content ---
</div>
</div>
You need to change the structure to something like this:
<div id="header">
<div>
<ul>Nav</ul>
</div>
</div>
<div id="mainContent">
<div>Content</div>
</div>
<div id="footer">
<div>Content</div>
</div>
Then the CSS could look something like this:
div#header { width: 100%; background: black; }
div#header div { width: 600px; margin: 0 auto; background: url(...); }
div#mainContent { width: 100%; background: url(...); }
div#mainContent div { width: 600px; margin: 0 auto; }
div#footer { width: 100%; background: black; }
div#footer div { width: 600px; margin: 0 auto; }
It is fast written, hope you can see the idea? I can't see why you would go with position absolute or relative. Use margin: 0 auto; to center divs instead :)