Centered body with a fixed width 'stationary' header - css

My question is almost identical to part of this question, yet it did not lead me to a solution. How do I center my page while making my header take the full width of the browser window?
Using the following css snippet my page is perfectly centered in the viewport as the browser window changes size, however I want the header image to remain in the same position, flush against the left hand side of the viewport, no matter what the viewport window width is.
#page{
margin-left: auto;
margin-right: auto;
width: 1024px;
}
#header {width: 1200px;
}

put your #header outside your #page and set margin-left and margin-right to auto

Related

Image Not Staying Within Parent Div

I am trying to make some responsive cards. I have the cards completed and spaced out properly. On the front of the cards I want an image on the top of the cards and a title in the middle. The title is fine and the image is fine except for the right side of the image.
Here is the CSS code for the image (image is in an img tag in HTML page with a class of "image"):
div .image {
padding: 5%;
height: 45%;
width: 100%;
}
The right side for some reason is ignoring the padding and sticking out of the card parent div. Any ideas why?
did you already set div's width?
also as far i know is no need to set image's height if you already set it's width to 100%
anyway here some example
div { width: 200px; height: 150px; padding: 6px; }
div img { width: 100%; }
You set the width to be 100% and padding 5%. Make sure you have:
box-sizing: border-box;
for the parent.
Also without the full example of code, hard to answer. Can use overflow: hidden; on the parent to hide that part sticking out.

I want an image with fixed height and width

Here is my site: http://highcatering.wpengine.com/
At the bottom of the site, there is an image of a bride sitting on a couch.
I want that image to keep its height and width. Here's an example: http://lydialavin.com/category/colecciones/
If you see, all the images there don't change size when the screen resolution is reduced.
Any suggestions?
If i understand your question correctly, you don't want the image to be smaller than a specific value. In this case, you should set a min-width pixel value on the element. Let's say 900px:
#novia img {
display: block;
float: none;
margin: 0;
padding: 0;
width: 100%;
min-width:900px;
background-position: center center;
}
and remove the overflow-x from its container:
#novia {overflow-x: hidden;}
This way, the background won't get as small as it does now when you see it on smaller screens. Please note, though, that the element will not be perfectly centered as it is now, and some portion of the image will not be shown.
Alternatively, you could give the image a fixed value, but it wouldn't be as effective, as it would probably be too big for smaller screens.
This css will fix the width and height of you bgackground
<style>
.your-img{
background:url(img/bg.jpg) no-repeat center center fixed;
}
</style>

How to make a flexible-height modal with fixed header

I've created a really simple modal that allows the content to decrease or expand without running off the page - always leaving 10% margin on the top and bottom. When the page isn't tall enough to contain all the modal content, the entire modal becomes scrollable.
See jsfiddle here
Is it possible, using only CSS, to replicate this behavior but only have the modal body be scrollable, so the header is always fixed. I've tried a few things, but haven't come up with the solution yet. Making the header position: fixed almost works, I have to reposition it over the modal box and then try to add padding to the body so the content is visible under the header, which doesn't budge the scrollbars down. I always prefer to exhaust all the css alternatives before I bind some js to window resize and manually manipulate the body height.
This might be late, but I had to solve a similar issue of fixed header, fluid height, fluid width.
This is how I tackled the issue:
Give your elements a border-box box-sizing. Use a wrapper to center and create a bounding box. This can be a fluid one with min-width and max-width + percentages.
Give your content element an overflow-y of auto and a max-height of 100%;
Use box-sizing:border-box;
The complete code should be something like this:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.modal {
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.8);
}
.wrap {
position: relative;
margin: 0 auto;
display: block;
width: 90%;
/* Change the max-width value on a media query breakpoint to make this example more "responsive" */
max-width: 500px;
height: 90%;
padding: 30px;
}
.modal header {
height: 30px;
padding: 0;
color: #FFF;
background-color: #007;
}
.modal .body {
background-color: #FFF;
max-height: 100%;
overflow-y: auto;
}
http://jsfiddle.net/mariomc/EhR7r/
Applying the max-height and overflow-y settings to .body rather than to .wrap...?
Edit 1:
Nothing's turned up so far within the constraints, which suggests either JavaScript or straying from the constraints (using % for the header height or px margins).
Edit 2:
Here's an initial demo using % for the header height. I added a px min-height to the header tag to prevent the header from almost disappearing on very small screens, at the expense of the top margin (which is reduced on very small screens).
On a screen >= 400px tall, it should work exactly as per the requirements (40px header with 10% height). If the header were reduced in height, it would support slightly-smaller screens (a 30px header with 10% height would support >= 300px screens). Here's a demo with a 30px header.
It's a clumsy solution, but it's the only one that turned up without using JavaScript.
Also, note that I added an h2 and a .content tag and moved the padding:10px; there, to avoid combining % height and padding in the same elements (which leads to a taller height than the % value specified).

Vertical Pagination of Divs

What I want to do is setup multiple div's that each contain the contents of an entire page. Each div should be centered in the viewport and fill it entirely. Each successive div should be evenly spaced vertically based on the variable height of the viewport. For example say I have a view of 800x600 then each div should be this size and stacked. So, if I scrolled down exactly 600px I would only see page 2 div, 1200px I'd only see page 3 div. I don't have any code or example to share and my exhausted searches have turned up nothing of this sort. Is this possible with just css?
You simply have to give your html, body & divs a height: 100%;:
html, body {
height: 100%;
}
div {
height: 100%;
margin-bottom: 5px;
}
http://jsfiddle.net/KMMjv/
Because this would vary depending on the size of the user's browser window you would need to JavaScript to detect screen height and position them accordingly. Although you could set the height of each div with just CSS (height: 100%;) you would need to set the top with JS.
Here is a working JSBin: http://jsbin.com/ogokef/edit#preview
Use the following units:
vh for viewport height
vw for viewport width
html, body {
height: 100vh;
}
div {
height: 100vh;
width: 100%; /* you can use 100vw too, but for height it must be vh */
}

Footer height based on screen size

I would like to create a footer which is relative to the content (so not fixed), but fills the rest of the screen. So for example, on my larger monitor, the footer would start in the same place, but fill up 100px (for example). On a smaller monitor, it only needs to fill up 75px. I tried using 100%, but it causes the page to be really big and the user can scroll down and fill the entire screen with the footer. Is there a way to get it to be a bit more reasonable size, so that it just about fills the bottom of the screen?
My current code is this:
.footer
{
position:relative; //can't be fixed as content might overlap if extended
height:100%;
width:100%; //fill the entire screen horizontally
bottom:0px;
margin-top:345px; //used to make sure content doesn't overlap
}
I was struggling with something similar and the trick I found to solve it was to make sure to set body and html to min-height:100% as well as then have content and all other divs equal 100%.
html {
min-height: 100%;
}
body {
margin: 0;
padding: 0;
min-height: 100%;
}
#content {
min-height: 100%;
}

Resources