How Can I Make The HTML Page More Narrow? - html

I want to change the width of the area that i present things (the body), i add picture for better understanding of what i'm looking for:
(the yellow mark is the width that i'm looking for to my HTML body, How can i do it ?
I'm using MVC 4 w/ bootstrap.
Additional info: I have a navbar that require from me to add style configures in the '_layout' in order to display the page in a proper way and not to allow the navbar to be over the body content, here is it:
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
.aligntobottom {
bottom: 0;
position: absolute;
}
</style>
What i need to add to the style markup in order to get what i want?
Update This is how i render the body (in the '_layout'):
<div class="container">
#if (IsSectionDefined("featured"))
{
<div class="hero-unit">
#RenderSection("featured", required: false)
</div>
}
#RenderBody()
</div> <!-- /container -->
So its inside a container at the first place.(i render the body into the container)
update
**I notice that the problem is because the '#media' :
But now i see that i have a couple of #media section in my CSS:
#media (min-width: 768px) {
.container {
width: 550px;
/*width: 750px;*/
/*MAYBE THIS*/
}
#media (min-width: 992px) {
.container {
width: 550px;
/*width: 970px;*/
/*MAYBE THIS*/
}
#media (min-width: 1200px) {
.container {
/*width: 1170px;*/
width: 550px;
/*MAYBE THIS*/
}
what i need to change in order to keep the suitability for all type of browser and screens ??
I change all of them(1200px, 992px, 768px) like the code i post, how can i know which one i'm currently using ? hence what my media width?

If I read your post correctly, I think you're trying to make the content narrower keeping the nav bar to the full width.... then I suggest changing the following
<div id="navbar">
code of the navigation bar
</div>
<div id="content" >
content
</div>
and then change the stile to look like this
#navbar{
width:100%;
/*other styles*/
}
#content{
width:920px;/*change the value to suite ur need*/
margin:0 auto;/*this will center ur content*/
}
If you want to make the nav bar the same width as the content then add the #navbar div inside the content div as follows:
<div id="content">
<div id="navbar">
code of the navigation bar
</div>
content
</div>

create a new div, just after the body tag, put everything inside it, give width (eg 1200px) and margin:0 auto; to keep it at the center of the screen.
if you are using bootstrap, put everything inside of "container".

There's no need to modify the CSS, jsut put the content of your page inside a
<div class="container">
<!-- More HTML here -->
</div>
If you want to make is narrower you could use:
<div class="container">
<div class="row">
<div class="col-lg-offset-1 col-lg-10">
</div>
</div>
</div>

Related

Push div after content on smaller screens

I have a sidebar on page which should have background color all the way to the right side so it can't be inside container (or it can?). I am struggling with positioning it so that the content and sidebar don't overlap.
But my question is how can I push the sidebar on smaller screens after content? (without having duplicate content)
I am trying to mess a little as possible with Bootstrap code so that it doesn't break somewhere later
https://jsfiddle.net/vzoz53zm/
#sidebar {
position: absolute;
right: 0;
width: 35%;
max-width: 300px;
}
#media only screen and (max-width: 480px) {
#sidebar {
position: relative;
width: 100%;
}
}
<div id="sidebar">
<p>
SIDEBAR
</p>
</div>
<div class="container">
<div class="main">
CONTENT
</div>
</div>
You just need to move your HTML for the side bar after the container, and add top: 0; to your #sidebar styles. At the moment your sidebar appears first in the document, you have removed it from the document flow using absolute positioning, but when you insert it back in (setting it to position: relative;) it goes back into the document above the .container div.
See fiddle. https://jsfiddle.net/vzoz53zm/1/
Add top:0 styles to the sidebar styles, it will meet the requirement.

How to change sidebar div position to the top of content if window resized

I got two numbers of div tag, with float left and the width 50% like the following image :
What i want my div tag position on the screen change like this if the window size changed:
I know that the code must be written into media, for different screen sizes but i don't know what to do in order to change the position of these two DIV tags
<div class="wrapper">
<div class="content"></div>
<div class="sidebar"></div>
</div>
It will be like this, when the width is smaller than 796px the sidebar will be over the content but note that in the html the div.sidebar should be before the div.content
.sidebar{
background:#4F6072;
}
.content{
background:#4F9996;
}
#media only screen and (min-width: 769px) {
.sidebar{
width:50%;
float:right;
}
.content{
width:50%;
float:left;
}
}
<div class="wrapper">
<div class="sidebar">Page sidebar</div>
<div class="content">Page content</div>
</div>
You can also doing this using Bootstrap.
So, You need not to write #media query for that
You can check out link here:
https://jsfiddle.net/md93vpxj/
https://jsfiddle.net/md93vpxj/

Adding a responsive image to a position fixed div within a Bootstrap column

I have a two column layout, one column is the document content and the other is the navigation. I've set this up using a Bootstrap row, one column is 8 units wide and the other is 3 units wide with an offset of 1 unit. I've set the navigation content to fixed so that it stays on the page.
On some of the pages I want to have an image at the top of the navigation column. I want this image to be responsive and stay within the 3 unit column and be fixed along with the navigation. However, when you set the content to fixed the image is no longer constrained within the 3 unit column.
I've set up a jsfiddle of the problem at http://jsfiddle.net/yKUZW/3/.
Here is the example html:
<div class="container">
<div class="row">
<div class="col-xs-8 content">Content goes here...</div>
<div class="col-xs-3 col-xs-offset-1">
<div class="fixed">
<img class="img-responsive" src="http://placekitten.com/300/200">
Some links go here.
</div>
</div>
</div>
</div>
And the relevant css:
.fixed {
position: fixed;
top: 150px;
}
Notice that when the page is resized horizontally the image stretches outside of the light grey container area. What I want is for the right hand side of the image to always align exactly with the right hand edge of the container, resizing the image as needed.
How would I go about accomplishing this?
The Problem
Ignore the image for a second... .img-responsive just makes the image take up 100% of the available space in the parent container.
Then the question becomes, can I add position: fixed to a div and still have it take up the same width as it's parent which has .col-xs-3 (width: 25%)? Once we resolve that, the image should fall into line.
As you may already know about fixed positioning:
for a fixed positioned box, the containing block is established by the viewport
Meaning Fixed is always relative to the parent window, never an element.
Simple Solution
If the viewport is the same width as the parent div, this can be resolved trivially:
HTML:
<div class="row">
<div class="col-xs-9" id="content">C</div>
<div class="col-xs-3">
<div id="navbar">Navbar</div>
</div>
</div>
Relative - div takes up 100% of width of parent (.col-xs-3):
#navbar {
background: yellow;
position: relative;
}
Fixed - div takes up 100% of screen - apply .col-xs-3 width ourselves:
#navbar {
background: yellow;
position: fixed;
width: 25%;
}
Demo in Fiddle
Better Solution
However, that solution isn't much help to us because the the .container class applies variable widths at different breakpoints to the row. This causes 25% of the parent div and 25% of the viewport to get out of sync.
So how can we get them to sync up again?
To answer that, let's look at exactly what .container is doing:
.container {
#media (min-width: #screen-sm-min) {
width: #container-sm;
}
#media (min-width: #screen-md-min) {
width: #container-md;
}
#media (min-width: #screen-lg-min) {
width: #container-lg;
}
}
So instead of trivially being able to apply a 25% width, we now have to mimic the width applied by .container. Here's how:
Here's some sample markup:
<div class="container">
<div class="row">
<div class="col-xs-8 content">Content</div>
<div class="col-xs-3 col-xs-offset-1" id="sidebar-outer">
<div id="sidebar">
Width: <span id="width-placeholder"></span>px
</div>
</div>
</div>
</div>
Now we can apply a width at all breakpoints with the following CSS:
#sidebar {
background: yellow;
position: fixed;
width: 25%;
}
#media (min-width: 768px) {
#sidebar {
width: 158px; /* 632 * .25 */
}
}
#media (min-width: 992px) {
#sidebar {
width: 213px; /* 852 * .25 */
}
}
#media (min-width: 1200px) {
#sidebar {
width: 263px; /* 1052 * .25 */
}
}
Here's a side by side comparison of using relative vs fixed position with styling:
Demo in Fiddle
Back to our problem at hand:
Just take the demo from above and add back in our responsive image:
Solution Demo in Fiddle
As a note: most sites opt to use a fixed width side navbar when using position:fixed in order to sidestep these kinds of issues.
After messing with it a bit I believe the best way would be to remove the the fixed div from the bootstrap column, and place it higher up in the dom, or at least outside of the row. There is a lot of negative margin and strange padding stuff going on to get the BS cols to work properly and it is pushing your fixed div around. If it were me and this was going to be a main feature on the site I would make a div with width 100%, abs pos, top left right bottom all at 0, and then place the fixed div inside of that. For a fixed pos div you want it to live in a relative pos parent with right set to 0 and top set to 150 in your case. If the parent is 100% of the windows width then you have pretty good control over where it goes using either px or %.
Thanks Kyle for the amazing solution you described at the top.
Here is a solution for 8/4 situation in a normal container (not fluid)
<div class='container'>
<div class='row'>
<div class='col-xs-8> something here </div>
<div class='col-xs-4>
<div id='sidebar'> content
</div>
</div>
</div>
</div>
and here the css
#sidebar {
background: blue;
position: fixed;
width: 33.3333%;
}
#media (min-width: 768px) {
#sidebar {
width: 235px;
}
}
#media (min-width: 992px) {
#sidebar {
width: 309px;
}
}
#media (min-width: 1200px) {
#sidebar {
width: 375px;
}
}

Moving up the div at window resize without using absolute

Lets say I have a structure like this.
<div class="container>
<div class="left-col>
some content
</div>
<div class="right column>
<div class="login-form">Login Form</div>
</div>
</div>
Above is the structure of my webpage at 700px width and above.. What I wanted to do is whenever the browser width decreases to 480px and below.. the div class login-form would be at the top and then below of it is my left-col.. is there any way for this? I would love to do it without using the position: absolute
if browser width is 480px and below structure would be like this
<div class="container>
<div class="right column>
<div class="login-form">Login Form</div>
</div>
<div class="left-col>
some content
</div>
</div>
Does your HTML have to be like that or can you swap it around? Meaning the html looks different, but you still have the login form on the right on big screens. It's much simpler if the HTML is:
<div class="container">
<div class="right-col">
<div class="login-form">Login Form</div>
</div>
<div class="left-col">
Some Content
</div>
</div>
Then the CSS:
.left-col {
background: green;
}
.right-col {
background: red;
}
#media (min-width: 481px) {
.container {
overflow: hidden;
}
.left-col {
overflow: hidden;
}
.right-col {
float: right;
margin-left: 10px;
}
}
Working Fiddle: http://jsfiddle.net/jhummel/4aNjd/
There is a way to do this and it is called responsive web design. You would use media queries that will tell the page how to behave at certain sizes.
Lucky for you there are more functions to the position attribute than position:absolute;.In this case, I would use position:relative; and move "left-col" down.
Here is a great article to get you started with Responsive web design. CLICK HERE
Do those divs show up left and right when the browser is 700px? If so...
Just have the "right column" div before the "left-col" in your html. In the css use floats so "right-column" shows up on the right and "left-col" still shows up on the left. I am assuming their widths fit in the container. Then, within your media query give "right column" float:none and width:100% so that when the browser is less than 480px the form div will show up on top.
note: I think you meant "right-column" and not "right column".
<style>
.left-col{
float:left;
}
.right-column{
float:right;
}
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
.left-col{float:none; width:100%;}
.right-column{float:none;}
}
</style>
<div class="container>
<div class="right-column>
<div class="login-form">Login Form</div>
</div>
<div class="left-col>
some content
</div>
</div>

Implementing Header so its elements (logo images) scaffolds with screen size

I am trying to make the logos in a header to scaffold (stack downwards) when screen size is decreased. At the moment i get the following:
<div id="header_inner">
<div class="logo"><a rel="home" href=""><img src="/logoShort1.png" alt=""></a></div><!-- .logo -->
<div id="header_extras"><div id="header_extras_inner"><div class="header_social"><div class="social_icon awake_dark"><img src="twitter.png" alt=""></div><div class="social_icon awake_dark"><img src="http://10.10.1.202//facebook.png" alt=""></div><div class="social_icon awake_dark"><img src="http:///email.png" alt=""></div></div></div><!-- #header_extras_inner -->
</div>
<div id="logoMob" class="headerStack"><img src="/logoMobPhone.png"></div>
<div id="logoLand" class="headerStack"><img src="/logoLandline.png"></div>
</div>
I simplified your CSS. It looked like you were trying to do too much.
http://jsfiddle.net/WtZad/1/
CSS
#header_inner {
min-width: 900px;
margin: 0 auto;
}
#header_inner > div {
float: left;
margin: 5px; /* add some space around them */
}
Using a set width with width: 900px; will create a horizontal scroll bar. Using max-width: 990px; allows it to flex at smaller screen sizes.
You can do this by specifying in CSS float:left; and clear:left; whilst using Adapt.js you can change load css files dependant on screen size. This way you can make the CSS rules specific for the layout.
Make sure to include the CSS files, JS and the initialisation.
EDIT /*
This is without the JS and a simple media query http://jsfiddle.net/meeb0/mSTrQ/1/