I have tried almost every answer in similar thread, but could find anything that works for me.
I have following site:
A header (div span over the full width).
A left column.
A right column.
The header and the right column are fixed.
I would like the text in the left column to disappear beneath the header when scrolling.
Something like I see on many websites where a header with a message (ex. "accept cookies") stays on a fixed place.
Any ideas?
HTML:
<div id="head">
<!-- here is the code of our header -->
</div>
<div id="content">
<!-- The next block for example with the main content -->
</div>
CSS:
#head{
width: 1000px;
height: 60px;
position: fixed;
background: #fff;
z-index: 1000;
}
/* So that our next block does not run under the header, as soon as the page is loaded, add an indent. */
#content {
margin-top: 60px;
}
Everything works now.
Left column scrolling with fixed header:
.header {
overflow: hidden;
background-color: black;
position: fixed;
top: 0;
width: 100%;
}
Right column fixed (responsive):
#media (min-width: 1200px) {
.rightcolumn {position: fixed;}
}
I am using mPDF(v7.0) to create a PDF from my HTML. I want to create a PDF that contains an image, within a div (.container-sizing). I have to be able to have the ability to position the image within .container-sizing using CSS and zoom and flip the image.
I have tried the below:
CSS
.container-sizing {
overflow: hidden;
position: relative;
width:600px;
height:430px;
}
.img {
max-height: 100%;
position: absolute;
top: -100px;
left: -100px;
right: 0;
bottom: 0;
margin: auto;
transform:scale(1, -1);
}
HTML
<div class='container-sizing'>
<img src='images/my-image.jpg' alt='' class='img'/>
</div>
This doesn't work as it ignores overflow:hidden on the containing div - which is pretty essential when positioning the image. Instead, I tried styling the image as a background image, which works great but then I have run into problems with transform: scale(1, -1). Despite mPDF's documentation saying that this is supported, it doesn't seem to work when applied to a background image.
CSS:
.container-sizing {
width:600px;
height:430px;
overflow: hidden;
}
.img {
background-image: url('images/my-image.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
width:600px;
height:430px;
transform:scale(1, -1) ;
}
HTML:
<div class='container-sizing'>
<div class='img'></div>
</div>
Does anyone have any ideas how I can get this working to produce a pdf that shows the image how it is declared in the css?
Thank you!
After spending ages trying to figure this out, I ended up dropping mPDF and using domPDF instead as this supports the overflow: hidden property I needed. Just posting in case anyone else runs into a similar issue!
I am making an interactive map and want to have buttons on it that will change color (separate image) when hovered over, and then link to different images.
I am having a huge problem with making this work... My current css is a mess:
a.button
{
position: inherit;
display:block;
background:transparent url('images/button.png') bottom;
background-repeat: no-repeat;
}
a.button:hover
{
position: inherit;
background-image: url('images/button_hover.png');
background-repeat: no-repeat;
}
#one
{
position: fixed;
left:225px;
top:702px;
}
HTML:
<div id="map"><img src="images/map.png"/></div>
<a href="http://matthewligotti.com" class="button"/>
<img src="images/button.png" id="one"/>
</a>
</div>
So I want the images to be links and hover the same two images for each button the only thing changing would be the links they bring you to. How do I do this?
If you can edit the images, you can combine them into one .png by stacking them on top of each other. Then, if buttons the buttons were 100px x 200px, you could do something like this:
a.button
{
display:block;
height:100px;
width:200px;
background-image:url('1.jpg');
background-position:0 0;
background-repeat: no-repeat;
}
a.button:hover
{
background-position:0 -100px;
}
and
<a href="http://matthewligotti.com" class="button"/></a>
<a href="http://matthewligotti.com" class="button"/></a>
which would switch the top or bottom half of the new double-image being displayed.
does that do what you mean?
I have a html document structured with a header, content, and footer divs. I am trying to center an image (a logo) inside my header div to display at the top of my webpage in the middle. I can absolute position it into the middle, but when I change the browser size, the img doesn't move along with it. I want it to be place automatically in the center of the window. I am stumped..?
I have tried , margin-right:auto; margin-left:auto. I have also tried the trick where you make margin-left negative half the width and top 50%, but nothing has worked so far.
html:
<body>
<div id="container">
<div id="header">
<img id="logo-img" src="http://f.cl.ly/items/3c0h1b0F3t1D1S1T2J0F/smallersticker.png">
</div>
/*...(body div)
...(footer div)*/
</div> /*container*/
css:
#header {
background-color:transparent;
height:260px;
width:100%
}
#logo-img{
display: block;
margin-left: auto;
margin-right: auto;
}
Also, Do I even need a container? Not sure if I need javascript for this, or if it can be accomplished with just html/css? Hope someone can help, thanks!
What is happening is that you are already correctly centering your image.
Your problem is that the image is huge. If you notice closely, the image is not centered if your browser window becomes smaller in width than the image.
Remove the white area from the image and it will center correctly.
Edit: in IE, you need to add the rule text-align:center to #header
Another way:
If you don't want to change your image, you can use this hack:
<style>
#header {
overflow-y: hidden;
background-color: transparent;
height: 260px;
width: 100%;
margin-left: 50%;
}
#logo-img{
display: block;
position: relative;
right: 50%;
}
</style>
<body>
<div id="container">
<div id="header">
<img id="logo-img" src="http://f.cl.ly/items/3c0h1b0F3t1D1S1T2J0F/smallersticker.png">
</div>
/*...(body div)
...(footer div)*/
</div> /*container*/
I learned this hack a while ago here
Just use the logo at a size it's supposed to be (like this here), then all you need to do is add the align="center" attribute to your logo's div.
I have three div elements: one as a header, one as a footer, and a center content div. the div in the center needs to expand automatically with content, but I would like a min-height such that the bottom div always at least reaches the bottom of the window, but is not fixed there on longer pages.
For example:
<div id="a" style="height: 200px;">
<p>This div should always remain at the top of the page content and should scroll with it.</p>
</div>
<div id="b">
<p>This is the div in question. On longer pages, this div needs to behave normally (i.e. expand to fit the content and scroll with the entire page). On shorter pages, this div needs to expand beyond its content to a height such that div c will reach the bottom of the viewport, regardless of monitor resolution or window size.
</div>
<div id="c" style="height: 100px;">
<p>This div needs to remain at the bottom of the page's content, and scroll with it on longer pages, but on shorter pages, needs to reach the bottom of the browser window, regardless of monitor resolution or window size.</p>
</div>
Just look for my solution on jsfiddle, it is based on csslayout
html,
body {
margin: 0;
padding: 0;
height: 100%; /* needed for container min-height */
}
div#container {
position: relative; /* needed for footer positioning*/
height: auto !important; /* real browsers */
min-height: 100%; /* real browsers */
}
div#header {
padding: 1em;
background: #efe;
}
div#content {
/* padding:1em 1em 5em; *//* bottom padding for footer */
}
div#footer {
position: absolute;
width: 100%;
bottom: 0; /* stick to bottom */
background: #ddd;
}
<div id="container">
<div id="header">header</div>
<div id="content">
content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>content<br/>
</div>
<div id="footer">
footer
</div>
</div>
I found this courtesy of ryanfait.com. It's actually remarkably simple.
In order to float a footer to the bottom of the page when content is shorter than window-height, or at the bottom of the content when it is longer than window-height, utilize the following code:
Basic HTML structure:
<div id="content">
Place your content here.
<div id="push"></div>
</div>
<div id="footer">
Place your footer information here.
</footer>
Note: Nothing should be placed outside the '#content' and '#footer' divs unless it is absolutely positioned.
Note: Nothing should be placed inside the '#push' div as it will be hidden.
And the CSS:
* {
margin: 0;
}
html, body {
height: 100%;
}
#content {
min-height: 100%;
height: auto !important; /*min-height hack*/
height: 100%; /*min-height hack*/
margin-bottom: -4em; /*Negates #push on longer pages*/
}
#footer, #push {
height: 4em;
}
To make headers or footers span the width of a page, you must absolutely position the header.
Note: If you add a page-width header, I found it necessary to add an extra wrapper div to #content. The outer div controls horizontal spacing while the inner div controls vertical spacing. I was required to do this because I found that 'min-height:' works only on the body of an element and adds padding to the height.
*Edit: missing semicolon
If #top and #bottom have fixed heights, you can use:
#top {
position: absolute;
top: 0;
height: 200px;
}
#bottom {
position: absolute;
bottom: 0;
height: 100px;
}
#central {
margin-top: 200px;
margin-bot: 100px;
}
update
If you want #central to stretch down, you could:
Fake it with a background on parent;
Use CSS3's (not widely supported, most likely) calc();
Or maybe use javascript to dynamically add min-height.
With calc():
#central {
min-height: calc(100% - 300px);
}
With jQuery it could be something like:
$(document).ready(function() {
var desiredHeight = $("body").height() - $("top").height() - $("bot").height();
$("#central").css("min-height", desiredHeight );
});
to get dynamic height based on browser window. Use vh instead of %
e.g: pass following height: 100vh; to the specific div
As mentioned elsewhere, the CSS function calc() can work nicely here. It is now mostly supported. You could use like:
.container
{
min-height: 70%;
min-height: -webkit-calc(100% - 300px);
min-height: -moz-calc(100% - 300px);
min-height: calc(100% - 300px);
}
No hack or js needed. Just apply the following rule to your root element:
min-height: 100%;
height: auto;
It will automatically choose the bigger one from the two as its height, which means if the content is longer than the browser, it will be the height of the content, otherwise, the height of the browser. This is standard css.
You propably have to write some JavaScript, because there is no way to estimate the height of all the users of the page.
It's hard to do this.
There is a min-height: css style, but it doesn't work in all browsers. You can use it, but the biggest problem is that you will need to set it to something like 90% or numbers like that (percents), but the top and bottom divs use fixed pixel sizes, and you won't be able to reconcile them.
var minHeight = $(window).height() -
$('#a').outerHeight(true) -
$('#c').outerHeight(true));
if($('#b').height() < minHeight) $('#b').height(minHeight);
I know a and c have fixed heights, but I rather measure them in case they change later.
Also, I am measuring the height of b (I don't want to make is smaller after all), but if there is an image in there that did not load the height can change, so watch out for things like that.
It may be safer to do:
$('#b').prepend('<div style="float: left; width: 1px; height: ' + minHeight + 'px;"> </div>');
Which simply adds an element into that div with the correct height - that effectively acts as min-height even for browsers that don't have it. (You may want to add the element into your markup, and then just control the height of it via javascript instead of also adding it that way, that way you can take it into account when designing the layout.)