How do I set a center container to stay responsive? - html

I have three containers (div), the third div has a set width but I need the other two to be responsive. Current html setup:
<div id="page-type">
<div id="type-container">
<div>
<p id="type-title">Events</p>
</div>
</div>
<div class="type-options">
</div>
<div id="type-back">
Back to Explore
</div>
</div>
Current css:
#page-type {
float: left;
width: 100%;
background: #D2D3D5;
height: 60px;
}
#type-container {
float: left;
width: auto;
}
#type-options {
height: 60px;
width: auto;
overflow: hidden;
}
#type-back {
border-left: 1px #BDBEC1 solid;
float: right;
width: 160px;
}
I can get type-container and type-options to be on the same line and responsive but I can't keep type-back on the same line.
visual example:
----- EDIT -----
To clarify more:
type-container adjusts to fit it's content
type-back is a set width
type-option fills in the space between type-container and type-back regardless of content
type-containerand type-options fill up the whole row pushing type-back to the next line. I need type-back to stay to the right of the line while the other two are responsive.

Put a wrapper around your first two columns and then you can use CSS3's calc().
#wrapper {
width: calc(100% - 161px); /* extra px for 1px border */
float: left;
}
Demo here
IE8 Workaround - Use border-box:
#wrapper {
margin-right: -161px;
padding-right: 161px;
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
IE8 Demo

In CSS3 you can use calc(X% - 160px) to reduce the width of a percentage based container by a number of pixels.
A quick example could be: http://jsfiddle.net/e3vC4/

There isn't a need to use calc for this, even though its a nice feature to have (+1) — sadly its support is still patchy in places and despite much research it's still difficult to say exactly which browser versions will work as expected (fine if you assume all modern browser users auto-upgrade however).
Depending on what your prerequisites are, you have two other options that I'm aware of:
1. Position absolute the last column
This is a simple solution, however something to be wary of is that certain older mobile devices may treat position absolute in odd ways.
In order to get this to work, all you need to do is place position: relative on your container, and position: absolute; right: 0; top: 0; on your third column... and to keep the centering of your central column correct, add margin-right: 161px.
Pos. Abs. example on JSFiddle
CSS ~ markup is as per your example
#page-type {
display: block;
position: relative; /* added */
width: 100%;
background: #D2D3D5;
height: 60px;
overflow: hidden;
}
#type-container {
display: block;
float: left;
text-align: center;
}
#type-options {
display: block;
height: 100%;
text-align: center;
overflow: hidden;
margin-right: 161px; /* added */
}
#type-back {
display: block;
position: absolute; /* added */
right: 0; /* added */
top: 0; /* added */
border-left: 1px #BDBEC1 solid;
width: 160px;
height: 100%;
}
2. Float right, and/or left, before sibling without hasLayout / shrinkwrap
This works on the basis that a floated element takes up space in the document, and a block element, by default, auto-expands to fill the remaining area that it can — as long as it hasn't been forced to rigidly define its edges with the likes of float, overflow or other hasLayout or shrinkwrap tricks.
This option is only open to you if you can re-arrange your DOM ordering i.e. place #type-back before #type-options. This won't affect the visual order, but it makes a big difference to how the layout is calculated, and is one of the reasons why you were encountering problems with your attempts. You need to have the floated elements in place before leaving the other elements to calculate their dimensions.
Float example on JSFiddle
NOTE: Changing the order of DOM elements can be of benefit, but it can also be a hindrance; it all depends on what the markup is, and who will be viewing it. For example, sometimes having actionable links higher up the DOM can be useful to tabbing and screen-reader users, but the opposite can also be true depending on the context.
MARKUP ~ note the rearranged DOM order
<div id="page-type">
<div id="type-container">
<p id="type-title">Events</p>
</div>
<div id="type-back">
<p>Back to Explore</p>
</div>
<div id="type-options">
<p>Options</p>
</div>
</div>
CSS
#page-type {
display: block;
width: 100%;
background: #D2D3D5;
height: 60px;
overflow: hidden;
}
#type-container {
display: block;
float: left;
text-align: center;
}
#type-options {
display: block;
height: 100%;
text-align: center;
overflow: hidden;
}
#type-back {
float: right;
border-left: 1px #BDBEC1 solid;
width: 160px;
height: 100%;
}
NOTE: It should be stated this version does break on to the next line when "responsed" down to a very minimal size. However, I tend to prefer to design items to disappear when space is tight, and this method lends well to that thinking.
Summary
These are just two other possible options. If you are developing for a progressive client, or yourself, then I personally would stick with the calc method. It's easier to work out what is going on, and far easier for a future developer to change.
However, sometimes often frequently all the blasted time clients want to support the widest range of devices possible (without investing the extra time and money that would be required), and in this instance you are better off with an alternative method (one that isn't going to randomly break on a manager's less than contemporary laptop, running IE 7.5? or 8.33333??? or even Netscape 4.7¿).
Unless of course, you have any leeway to fight for using the more progressive approach, which does seem to be getting easier of late.

I sat down with the designer for more clarification and to discuss alternate solutions. I'm making the third did responsive as well allowing me to use two containers: one holds page-type and type-options set to x% and another holds type-back set to y%. Doing this allows me to keep all elements responsive.

Related

Keeping image size fixed

I have an img that I want to not cross over into the below section. It only crosses over when i drag the viewport out and makes the window bigger.
I would like the restrict the image movement.
That probably doesn't explain my issue very well so I have attached two images to explain:
Smaller window:
Larger window:
The first image (smaller window) is what I want the image to look like, however as the larger window shows once the window becomes bigger it moves down as the page is responsive and crosses over into the references section. I would like to be able to stop it from doing this?
General images CSS:
img {
display: block;
margin: auto;
height: auto;
margin: auto;
max-width: 80%;
padding-bottom: 1em;
}
.bassportrait CSS:
.bassport {
float: right;
overflow: hidden;
padding-left: 1em;
padding-right: 1em;
padding-top: 1em;
height: 20%;
width: 20%;
}
Hope that makes sense and I have shown you the relevant code - I'm a beginner!
Since your .bassport is floated right, that float will need to be cleared on the element below to prevent the overlap. There are lots of ways to do this, but the most common is to add a clearfix to its parent element.
.parent-element:after {
content: "";
display: table;
clear: both;
}
Notional markup
<div class="parent-element"><!-- Clearfix applies to this element -->
<p>Ulrika's work...</p>
<p>Bass died...</p>
<img class="bassport" src="..."><!-- Floated element that needs to be cleared -->
</div>
Alternatively, if you're using a framework that has a clearfix utility class, you could just add that class to the parent div and it would have the same effect.
Reference: https://css-tricks.com/snippets/css/clear-fix/

Auto Align of button

Hi
On our website I have a page where there are Buy Now buttons
https://www.nutricentre.com/m-300-herbs-hands-healing.aspx
The styling that controls this is
.item .price {
color:#8c9c54;
font-size:14px;
font-weight: bold;
/*
position: absolute;
bottom: 48px;
left: 0px;
width: 150px;
*/
text-align: center;
margin-bottom: 45px;
}
.item a.blue_btn {
position: absolute;
bottom: 10px;
left: 15px;
cursor: pointer;
}
Any idea how I can get this aligned in a straight line regardless of the text above?
You don't have to change the css of the button, but from the whole item:
just add:
.item{
height: 380px;
}
Of course, you have to care about the maximum item-height: your value must not be less, or the price won't be visible anymore.
In this case, min-height would be the better alternative.
I would recommend setting a min-height: 370px; for the easiest solution.
You do not want to set a static height for this because if you have an item with a longer description it will not automatically add space but just cram everything in.
Add a static height to .item
height:375px;
The height:auto; declaration tells .item to expand as big as it needs to be to fit everything in, so the tops of the divs line up, but since they are different heights, the bottoms are staggered.
As some of my co-responders have noted, min-height is also an acceptable option, until you have an item with enough text that item expands past the min-height value, at which point they will begin to expand and stagger again.
This should point you in the right direction: http://jsfiddle.net/v9grm/
Create a grid and with the help of display: table make the columns the same height. Then place the button at the bottom of the column with position: absolute.

Is there a cross-browser solution to height: calc(100%-70px)

Is it ok yet to use this? How do I bullet proof it for older browsers?
height: -moz-calc(100% - 70px);
height: -webkit-calc(100% - 70px);
height: calc(100% - 70px);
Here is specifically what I'm trying to accomplish.
A Full Width / Fixed Height Header
A Slider that stretches full width and full height - minus the height of the header.
A headline block that is centered vertically and horizontally in the slider
A Controls block that is always a fixed height from the bottom of the slider
Here's an image of what I have been able to achieve so far. It's ALMOST perfect, except for the part in bold above. The slider (black area) currently stretches 100% height and flows behind the header, which isn't ok for images.
If I add padding or margin, it extends the slider height beyond 100% and I get a scrollbar. Using the height calculation above seems to fix it, but from my understanding, calc() isn't compatible with IE 7, IE 8, iOS 5 or lower, or Android.
Is there a better fix for this problem? jQuery is ok, but I'd prefer a CSS solution if one exists.
Here's my HTML:
<div class="header">
<h1>Header - Full Width + 70px Height</h1>
</div>
<div class="slider">
<div class="headline">
<div class="headline-container"><!-- for table-cell vertical centering -->
<h1>Headline Block</h1>
<p>Centered Horizontally & Vertically in the Slider Block</p>
</div>
</div>
<div class="controls">
<h2>Controls - Centered Horizontally & 40px from bottom of container</h2>
</div>
</div>
Here's my CSS:
html, body {
width: 100%;
height: 100%;
margin: 0; padding: 0;
}
h1, h2, p {
margin: 0;
padding: 0;
}
.header {
position: absolute;
width: 100%;
height: 70px;
background-color: #888;
z-index: 9999;
}
.header h1 {
color: #fff;
text-align: center;
}
.slider-desc {
color: #fff;
text-align: center;
margin: 15px 0 0;
}
.slider {
width: 100%;
height: 100%;
background-color: #000;
}
.headline {
display: table;
width: 100%;
height: 100%;
}
.headline-container {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.headline-container h1, .headline-container p {
background-color: #fff;
}
.controls {
position: absolute;
width: 100%;
bottom: 40px;
text-align: center;
background-color: yellow;
}
Finally, I made a fiddle in case you want to play around with it. Thanks for the help!
I don't like JavaScript functions to handle sizing/resizing of my HTML elements, but sometimes it's the only possible way.
You could try with a tabular structure, setting:
height: 100% to the table itself;
height: <what you want> to the table header (first row);
height: auto to the table content.
It should work as a fill-parent directive.
Hope it helps! :)
A simple vanilla JS piece could work for this (jQuery is too much of a hassle to load for such a small task):
document.getElementsByClassName("slider")[0].style.height = window.innerHeight - 70;
And obviously you need to position it 70px from the top.
Also remember to listen for window resize:
window.onresize = function () {
// Code above
}
If you really want jQuery,
$(".slider").height($(document).height() - 70);
$(window).resize(function () {
// Code above
});
Calc() is not supported by older browsers, such as IE7 or IE8, but can be emulated in older versions of IE using the non-standard expression() syntax.
Check out the browser support here: http://caniuse.com/calc
I'm a little late to this party, but for anyone looking for a way to get calc() into IE8, there isn't really any alternative to a polyfill. Microsoft removed support for the non-standard expression() statement:
Important Dynamic properties (also called "CSS expressions") are no longer supported in Internet Explorer 8 and later, in IE8 Standards mode and higher. This decision was made for standards compliance, browser performance, and security reasons.
Source here
This polyfill is tested in IE8
<musing>
I'm not entirely sure why MS decided for performance and 'security reasons' to remove the expression statement from IE8, they never really seemed to be concerned with performance before. Of course, it wouldn't even be an issue if they didn't make it necessary for organisations to build apps specifically for and reliant on it. You'd have thought they would have learned their lesson with IE6. Elaboration would be good.</musing>

How to get a div to stretch right down to a fixed footer

I wish the two sections of my design (see attached image) to extend the whole height of the page. I have tried to create a Fiddle but it just won't work in there, so I've put up a link here to demo what I mean.
I have set the height of the div that holds the results to 100%. However, it doesn't stretch right down to the fixed footer.
#found-results {
height: 100%px;
margin-bottom: 50px;
background: #CCC;
}
I also want the green box to stretch down to the footer. The CSS is:
.main {
width: 606px;
float: left;
padding: 15px 0 0 16px;
position: absolute;
background: green;
margin-left: 383px;
}
Now, if I add height: 100%; to it, it seems to work, but if one of the tabs contains a lot of text, it doesn't stretch far enough.
Any help will be much appreciated.
Equal-height columns
In a way, the tricky part isn't the fixed header and footer, or the 100% height; the tricky part is the equal-height columns. Often, it's better to fake equal-height columns (e.g., adding a grey-green background image to the parent container). Doing so typically allows the code to be simpler, more flexible, and more stable, compared to true equal-height columns. If the layout for this website proves too unwieldy, try faking the equal-height columns instead (as shown in this demo), and see if that helps the layout to become more manageable.
With that being said, the basic options for true equal-height columns are as follows:
HTML tables
CSS tables
CSS3 flexbox
CSS3 grids
JavaScript or jQuery
Here's a JSFiddle demo with true equal-height columns using CSS tables. The left column has very-tall content, and the right column has short content. The demo tested fine in IE10, Firefox, Chrome, Safari, and Opera; however, this may only work for relatively-simple layouts.
Here's a similar demo using HTML tables, in case support for IE8 is needed.
Faking the equal-height columns
Here's another demo that fakes the equal-height columns by adding a 2-color background image. This demo also tested fine in IE10, Firefox, Chrome, Safari, and Opera; however, unlike the previous ones, it's much more likely to support complex page layouts.
HTML
<div id="header">...</div>
<div id="content" class="clearfix">
<div class="column1">...</div>
<div class="column2">...</div>
</div>
<div id="footer">...</div>
CSS
html, body {
height: 100%;
...
}
#header {
position: fixed;
top: 0;
height: 120px;
...
}
#footer {
position: fixed;
bottom: 0;
height: 60px;
...
}
#content {
min-height: 100%;
padding: 120px 0 60px 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: url(some-two-color-background.png) repeat-y 53.6% top;
...
}
#content .column1 {
float: left;
width: 250px;
}
#content .column2 {
float: left;
width: 350px;
}
Note: The apparent column widths for the background image are controlled by setting the background-position property. This allows two columns of any explicit width (px or %) to be faked using the same generic background image. Alternately, a custom background image with the exact column sizes could be used, to simplify the CSS.
I think you are after something like this? jsFiddle
I have made it a bit easier for myself by only copying the markup I needed from your website, the class's, id's and the elements used are exactly the same as on your website, that should make it fairly easy for you to implement this solution on your website.
This layout will always at least fill the whole screen, and both sections will be the same height and touch the fixed footer. When the content is to high for one of the sections, a scroll bar will appear and you can scroll down until you have reached the bottom of both sections. Both sections will always be the same height. I have added some buttons in the header which will add and remove content inside the columns, this makes it easy to see what happens when the content is taller than than the height of the document.
Edit
I realised you probably want your header to be fixed as well (as this seems to be the case on your current website), here's a version with a fixed header. jsFiddle.
Edit2
I have added some buttons to the fiddles to make it easier to see what happens when the content inside the columns is forcing the columns to be taller than than the height of the document.
HTML
<header></header>
<div id="container">
<section class="results"></section>
<section class="main"></section>
</div>
<footer></footer>
CSS
html, body {
height: 100%;
margin: 0px;
padding: 0px;
}
header {
position: fixed;
top: 0px;
height: 60px;
width: 100%;
background-color: #FFF;
}
#container {
height: 100%;
overflow:auto;
padding-top: 60px;
padding-bottom: 60px;
display: table;
width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
footer {
position: fixed;
bottom: 0px;
height: 60px;
background-color: #333333;
width: 100%;
}
.main {
display: table-cell;
background-color: #008000;
}
.results {
display: table-cell;
background-color: #EFEFEF;
width: 383px;
}
body:before {
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;
}
I think your problem sits here: #found-results { height: 100%px; ...
...and further I think you have to add this too:
html, body {height: 100%}
you can set the height with jquery according to height of sidebar after loading page
$(document).ready(function(){
$('#main').height($('#sidebar').height());
});
You can use Jquery to achieve this.
$(document).ready(function() {
var window_height = $(window).height();
var footer_h = $("#footer").height();
var container_height = window_height - footer_h ;
$("#container").hide();
$("#container").css('min-height', container_height + "px");
$("#container").show();
});

<div> wrapper dynamic height

I have a wrapper that contains all the elements of an html page.
#wrapper {
width: 1000px;
height: auto;
min-height: 100%;
margin: auto;
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#4488ff), to(#4422ff));
[...]
background-attachment: fixed;
-moz-border-radius:20px;
-webkit-border-radius:20px;
border-radius:20px;
}
Here's the HTML code sample
<div id="wrapper">
<div id="uppermenu">
<div id="container">
<div id="logo"> <img src="images/logo.png" height="100%"> </div>
<div id="banner"> <br></div>
</div>
</div>
<div class="sidemenu"> [...] </div>
<div id="guide"> [...] </div>
</div>
I want this wrapper to change its height depending on the content it has to contain, but as I do this is not happening.
If I try to use
overflow: hidden;
the wrapper is shifted down by the uppermenu div (which it should be containing) and using
clear: both;
at the end of the contents doesn't change anything.
I've tried at least 5 different question answered correctly here but none worked well for me.
Last thing: the wrapper set as I wrote (with min-height at 100%) fits perfectly the screen of my browser, but that clearly not what I want it to look!
Any help???
EDIT: here's the CSS of sidemenu class
.sidemenu {
float: left;
margin-left: 20px;
margin-top: 20px;
height: 200px;
width: 150px;
background-color: #4488ff;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
z-index: 3;
}
and of the guide id
#guide {
float: left;
margin-top: 20px;
margin-left: 50px;
height: 100%;
width: 760px;
background-color: #4488ff;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
z-index: 3;
}
uppermenu and container
#uppermenu {
position: fixed;
top: 0px;
width: 1000px;
height: 100px;
margin: auto;
background: #004465;
z-index: 5;
}
#container {
width: 1000px;
min-height: 100%;
margin: auto;
}
Solution one: clear: both
Adding a block element with the style clear:both; onto it will clear the floats past that point and stop the parent of that element from collapsing. http://jsfiddle.net/TVD2X/1/
Pros: Allows you to clear an element and elements you add below will not be effected by the floated elements above and valid css.
Cons: Requires the another tag to clear the floats, bloating markup.
Note: To fall back to IE6 and for it to work on abstinent parents (i.e. the input element) you are not able to use :after.
Solution two: display: table
Adding display:table; to the parent to make it shrug off the floats and display with the correct height. http://jsfiddle.net/h9GAZ/1/
Pros: No extra markup and is a lot neater. Works in IE6+
Cons: Requires invalid css to make sure everything plays nice in IE6 and 7.
Note: The IE6 and 7 width auto is used to prevent the width being 100%+padding, which is not the case in newer browsers.
A note on the other "solutions"
These fixes work back to the lowest supported browser, over 1% usage globally (IE6), which means using :after does not cut it.
Overflow hidden does show the content but does not prevent the element from collapsing and so does not answer the question. Using an inline block can have buggy results, children having strange margins and so on, table is much better.
Setting the height does "prevent" the collapse but it is not a proper fix.
Invalid css
Invalid css never hurt anyone, in fact, it is now the norm. Using browser prefixes is just as invalid as using browser specific hacks and doesn't impact the end user what so ever.
In conclusion
I use both of the above solutions to make elements react correctly and play nicely with each other, I implore you to do the same.
get rid of min-height: 100%. this means that the minimum height of the div is 100% of your browser height. eliminating this should make it fit to the content