inline-block is the awesomest CSS tag ever. (That mean I only learned how it works last night. But then I threw away dozens of lines of HTML in preference to it.) It lets blocks reflow!
How do we write a banner that collapses into a different order when the screen is too small?
Big screen
[ A ][ B ][ C ]
Small screen?
[ C ]
[ B ]
[ A ]
You'll need some HTML and CSS trickery for the order switching, and then you could simply use media queries, with e.g.:
Demo Fiddle
HTML
<div>D</div>
<div>C</div>
<div>B</div>
<div>A</div>
CSS
div{
display:inline-block;
width:50px;
box-sizing:border-box;
height:50px;
width:25%;
border:1px solid black;
float:right;
}
#media (max-width: 700px) {
div {
display:block;
width:100%;
}
}
By having the elements in reverse order, then using float:right in your CSS, it places them in the order you anticipate- which is then ignored when they are given 100% width on screen resize- so they appear in the DOM (reverse) order.
Tx to whoever first mentioned 'flex'. I still like my previous float: solution, and SW4's will also work - IF you can find a way to float the divs together. But it's flex that allows you to re-order things.
Furtherless, #media & similar systems (such as 50%), reference the current page size (probably A4), not the current window size. I want to be so responsive that we behave like the mobile app, even if we're just a generic browser that someone scrunched up. So we need JS - the arch-nemesis of CSS - to trigger the changes.
The trick is display: flex; enables order:N;. That means switching the container to display: inline-block; will turn on document-order:
<script>
function resizeMe(win) {
var size = $(window).width();
var display = size > 600 ? 'inline-flex' : 'inline-block';
$('#flexMe').css({ display: display });
}
$(window).bind('resize', resizeMe);
$(window).bind('load', resizeMe);
</script>
<div id="flexMe" style="display: flex; width: 100%;" >
<div id="hdrLogo" class="hdrLogo hdrNv" style="order: 3; width: 375px;" >
Logo goes here
</div>
<div id="hdrAuth" class="hdrNv" style="order: 2; width: 375px;">
Login stuff goes here
</div>
<div id="hdrNavBar" class="hdrNv" style="order: 1; width: 375px;">
Record navigator goes here
</div>
</div>
That way the Record Navigator is either upper left, or closest to the records, and the Logo is either upper right, or farthest from the records.
Related
<div id="header">
<div>My</div>
<div>Header</div>
</div>
<div id="content"></div>
In the above markup, how can I get the content to fill the rest of the screen (no-scrolling)?
I know how to do this with absolute positions if the header was of a fixed height, but my header's height is dynamically set by its contents (so the site is responsive on mobile devices.)
Btw: I'm looking for a CSS only solution, because I think JavaScript is not made for this kind of task.
Thanks a lot,
The simpliest way is to draw the background in body and keep #content translucide. DEMO 1.
This way, you do not mind #header nor #content heights.
If you do not mind about IE7 and less, then display:table/table-row/table-cell taken from defaut display of HTML table elements can be what you need , in the case header has unknown height. DEMO 2
Your structure will need a bit of update in order to act as wished and to avoid gaps in layout render from header part to the content part.
If you reset display to be used as table properties, it will do so and can draw cols and rows.
Since it is only the row properties that will be usefull, Structure must be rendering as one single col and multiple rows.
Basic structure needs to turn this way :
<div id="header" class="row">
<div class="single">
<div>My</div>
<div>Header than can grow</div>
</div>
</div>
<div id="content" class="row">
<div class="single">
<p>My Content that will fill remaining space untill page has to scroll</p>
</div>
</div>
And basic CSS turns this way :
html, body {
height:100%;
width:100%;
margin:0;
}
body {
display:table;/* it will allow to grow over initial width specified */
/* table-layout:fixed; only if you want to control width within value specified*/
background:#edc;
}
.row {
display:table-row;/* we want these elements to stack on top of each other, not to become cells aside each other */
}
.single {
display:table-cell;/* this 'buffer' element is used to avoid layout to turn into multiple cols */
}
#content {
height:100%;/* since layout is the one taken from table properties, it means fill all space avalaible that #header doesn't use */
background:#cde;
}
In the case, *#header has a known*** height, it can be set in fixed or absolute position.
#content can be 100% height DEMO 3, better: min-height:100%; DEMO 4
display:flex could be useful too but for real young browser only :).
Example with display:flex;
html {
height:100%;
}
body {
margin:0;
min-height:100%;
background:#edc;
display:flex;
flex-direction:column;
}
#header {
/* nothing needed here */
}
#content {
flex:1;/* since it is the only one getting a flex attitude, it will fill up all space avalaible*/
background:yellow;
}
After coming back to web-development after a four year hiatus, I am having a tough time vertically aligning the contents of a bootstrap 3 column with the next column. I have tried searching this site as well as generic searches in general and have just not come up with the right solution ... or my search terms are poor.
In the HTML/CSS below, I would like to vertically center the "Page Title" text in the left column. I would like to keep the HTML and CSS as concise as possible while using the Bootstrap 3 CSS, so I just think I am completely missing something simple.
HTML
<div class="row page-header-box">
<div class="col-md-2 col-sm-2 col-xs-3 page-header-title">Page Title</div>
<div class="col-md-10 col-sm-10 col-xs-9 page-header-seperator">
<div class="page-header-description"><small>Standard Text Description</small></div>
<div class="page-header-alt"><small>Additional Text Description</small></div>
</div>
CSS
.page-header-box {
background-color:#3D3D3D;
border-bottom:5px solid #b3b5b8;
margin-bottom:10px;
}
.page-header-title { color:#f79239;text-align:right;vertical-align:middle;margin:10px 0; }
.page-header-seperator { border-left:5px solid #4e2f91;margin:10px 0; }
.page-header-description { color:#febe10; }
.page-header-alt { margin-top:5px;color:#0093b2; }
Here is a jsFiddle ... http://jsfiddle.net/E6LcY/8/
This is one of the few times I have ever posted, so pointing me in the right direction would be great.
I considered deleting this question, but thought the answer could be useful to someone else (like me) that is looking for a possible solution.
I wanted to stay within the Bootstrap 3 framework ... and ended up adding some JavaScript to make the "titled" centered. I figured that Bootstrap 3 basically requires jQuery for some functionality so it was OK.
Now, I am sure there may be a better way, but I did not like the other solutions. Thanks to all that attempted to put me on the right paths.
HTML
<div class="row page-header-box">
<div class="col-md-2 col-sm-2 col-xs-3 page-header-title" id="header-title">Page Title</div>
<div class="col-md-10 col-sm-10 col-xs-9 page-header-seperator" id="header-seperator">
<div class="page-header-description"><small>Standard Text Description Standard Text Description Standard Text Description Standard Text Description Standard Text Description Standard Text Description</small></div>
<div class="page-header-alt"><small>Additional Text Description</small></div>
</div>
</div>
CSS
.page-header-box {
background-color:#3D3D3D;
border-bottom:5px solid #b3b5b8;
margin-bottom:10px;
}
.page-header-title { color:#f79239;text-align:right;margin-bottom:10px; vertical-align: middle; }
.page-header-seperator { border-left:5px solid #4e2f91;margin:10px 0; }
.page-header-description { color:#febe10; }
.page-header-alt { margin-top:5px;color:#0093b2; }
JS (using jQuery)
var sep_height = '';
$(window).on("load resize", function(e) {
var seperatorHeight = $('#header-seperator').height();
if (seperatorHeight != sep_height) {
sep_height = seperatorHeight;
var titleHeight = $('#header-title').height();
var difference = ((seperatorHeight - titleHeight) / 2) + 5;
$('#header-title').css('margin-top', difference + 'px');
}
});
Note: the "sep_height" is just so that I don't make unnecessary calculations and only modify the title height when I need to. I am also adding an additional 5px to the top- margin to compensate for the margins on the description text.
Here is the latest fiddle (with a fix for the onLoad event): http://jsfiddle.net/E6LcY/15/
Thanks again to all those who helped.
Add the rule: line-height: 45px; to the col-md-2 class
UPDATED FIDDLE
This is how i do, you can try this:
.Parentdiv{
position:relative;
width:100%;
height:100%;
}
.Parentdiv .childdiv{
position: absolute;
top:0;
bottom:0;
margin:auto;
}
I'm starting to get tired of bootstrap in certain aspects somehow. Sometimes the amount of hacking required to accomplish certain functionalities is not worth the supposed benefits you get from using it.
In this case, I ended archiving the functionality I needed by abandoning bootstrap and using a combination of flexboxes with those properties applied to the parent:
.parent {
display: flex;
flex-wrap: wrap;
align-items: center;
}
those to the children:
.parent > div {
display: inline-block;
vertical-align: middle;
}
and this media query:
#media all and (max-width: 500px) {
.parent {
/* for small screens, we use column direction rather than row */
flex-direction: column !important;
}
}
The html involved is like this:
<div class="parent">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
I used this, for instance, for a responsive footer. Playing with a combination of some fixed width and margin (same for each), they get nicely aligned on top of the others in different quantities per row depending on the width of the screen, until it is narrow enough to just show them in one row.
In my opinion, much clearer, easier, cleaner and less code, with better responsiveness, better layout support, avoids using javascript and without all the overhead and hassle of bootstrap.
Can anyone assist me with the following div layout? I have tried a couple of solutions, however, the only way i have been able to accomplish this is using tables.
I had a look at Holy Grail 3 Column Layout, however, this layoyt is not 100% height, and header is not fixed, i also need only the content to scroll, the sidebars needs to be fixed 100% height
It seems the answers here ignored most of your requirements. I stumbled upon this because I am having a rendering issue with the same layout you are after. I forked the fiddle above to show you:
http://jsfiddle.net/RsRf9/2/
The major difference is that the entire body is scrollable, not just the tiny area in the center (I think this is what you are after).
Aside from cleaning up styles that weren't doing anything (like floats while position fixed), the major change is to the center col - all you should need is this:
.center{margin:100px 200px;}
The other change is how you get that "height 100%" effect on your sidebars - my trick is to do this:
.left,.right{width:200px;top: 100px; bottom: 0px;position: fixed;}
Instead of height 100%, I simply tell it to stretch from top 100 (the bottom of the nav) to bottom 0 (the bottom of the page)
That will push the content bellow the top nav and in between your two fixed side bars.
I have created a working fiddle as per your requirements:
Here is working fiddle - UPDATED to include fixed header ONLY TOP BAR IS FIXED
The important thing to note is the structural layout of the divs... notice that the .center is AFTER the .right
<div class='wrap'>
<div class='head'>Header</div>
<div class='bodywrap'>
<div class='left'>left</div>
<div class='right'>right</div>
<div class='center'>center center center center center center center center center center center center ... blah</div>
</div>
</div>
and the css is:
JUST HEADER FIXED:
html,body{height:100%}
.wrap{width:100%;height:100%;position:relative}
.head{height:100px;position:fixed;top:0;left:0;width:100%} << UPDATED for fixed header
.bodywrap{margin-top:100px;width:102%;margin-left:-1%} << UPDATED - Terrible hack and you may find something more elegant
.left,.right{width:200px;height:100%}
.left,.center,.right,.bodywrap{height:100%}
.left{float:left;}
.center{margin-left:200px; overflow:scroll; overflow-x:hidden;}
.right{float:right;}
.left{background-color:#aaa}
.right{background-color:#ccc}
.center{background-color:#444}
.head{background-color:#777}
HEADER AND SIDEBARS FIXED (Also was able to fix dirty hack for .left and .right undersizing
html,body{height:100%}
.wrap{width:100%;height:100%;position:relative}
.head{height:100px;position:fixed;top:0;left:0;width:100%}
.bodywrap{margin-top:100px;margin-left:-8px}
.left,.right{width:200px;height:100%}
.left,.center,.right,.bodywrap{height:100%}
.left{float:left;position:fixed}
.center{margin-left:200px; overflow:scroll; overflow-x:hidden;margin-right:191px}
.right{position:fixed;right:0}
.left{background-color:#aaa}
.right{background-color:#ccc}
.center{background-color:#444}
.head{background-color:#777}
Here is with top and sides fixed center scroll liquid center column (and no gaps on .left and .right)
It's basic use of floats but the structural markup layout is key ;)
I use the YUI grids style sheet for this kind of layout. It is tried and tested and works in multiple browsers.
This is actually quite easy to do in a rudimentary sense, you don't need tables (or table-cell) but mixing px and % sizes can be problematic. If you stick to % your page will resize better anyway. Handling the cross browser issues takes a bit more CSS tweaking, but there are plenty of grid solutions out there that implement tried and tested solutions even for IE6 and frameworks like twitter's bootstrap will offer a lot more on top.
In other words, this is a solved problem, but here's a quick example of how you can get there by hand;
<div class="container">
<div class="header">
header
</div>
<div class="left">
left
</div>
<div class="main">
content
</div>
<div class="right">
right
</div>
</div>
And the CSS;
html, body, .container
{
height:100%;
}
.container
{
background-color: pink;
}
.header
{
background-color: yellow;
height:50px;
}
.left
{
background-color: red;
float:left;
width:10%;
height:100%;
overflow: hidden;
}
.right
{
background-color: blue;
float:left;
width:10%;
height:100%;
overflow: hidden;
}
.main
{
background-color:#fefefe;
float:left;
height:100%;
width: 80%;
overflow-y:scroll;
}
And of course the Fiddle
Using % sizing will also allow you to approach a more responsive design that works for tablet and mobile. Again, many of the grid frameworks out there are 'responsive' in design.
You can use scrollToFixed plugin for left-sidebar and right-sidebar fixed and center column content only scroll up side and downside.
For demo scroll use below link
http://bigspotteddog.github.io/ScrollToFixed/
And one more thing use Bootstrap for design UI.
Include Bootstrap CSS and JavaScript in your page header part
<div class="container">
<div class="col-md-12">
<div class="col-md-3" id="left-sidebar">
left-content
<div>
<div class="col-md-6" id="center">
center content
</div>
<div class="col-md-3" id="right-sidebar">
right-content
</div>
</div>
</div>
You can modify as per your requirement. I just give you general hint.
Just write below script for scrolling
$(document).ready(function(){
$('#right-sidebar').scrollToFixed({
marginTop: function() {
return 5;
},
limit: function() {
return (
$('#footer-widgets-bg').offset().top - $('#right-sidebar').outerHeight(true)
);
},
zIndex: 1,
removeOffsets: true
});
});
I made a site so when you click the button 30px it changes the font inside the div.
I have a ul inside it with the bottons. When I change the size of font the div expands and the nav buttons move with it as well.
How do i make it so it stays fixed but the fonts can still change.
Try the following css:
#innerbox
{
width:250px; /* or whatever width you want. */
max-width:250px; /* or whatever width you want. */
display: inline-block;
}
This makes the div take as little space as possible, and its width is defined by the css.
// Expanded answer
To make the buttons fixed widths do the following :
#innerbox input
{
width:150px; /* or whatever width you want. */
max-width:150px; /* or whatever width you want. */
}
However, you should be aware that as the size of the text changes, so does the space needed to display it. As such, it's natural that the containers need to expand. You should perhaps review what you are trying to do; and maybe have some predefined classes that you alter on the fly using javascript to ensure the content placement is perfect.
you can give it a max-height and max-width in your .css
.fontpixel{max-width:200px; max-height:200px;}
in addition to your height and width properties
Thats the natural behavior of the buttons. You could try putting a max-width/max-height on the parent container, but I'm not sure if that would do it.
max-width:something px;
max-height:something px;
The other option would be to use the devlopr tools and see if you can remove the natural padding.
padding: 0;
<div>
<img src="whatever it is" class="image-crop">
</div>
/*mobile code*/
.image-crop{
width:100%;
max-height: auto;
}
/*desktop code*/
#media screen and (min-width: 640px) {
.image-crop{
width:100%;
max-height: 140px;
}
Use this style
<div class="form-control"
style="height:100px;
width:55%;
overflow:hidden;
cursor:pointer">
</div>
<div class="ai">a b c d e f</div> // something like ~100px
<div class="ai">a b c d e</div> // ~80
<div class="ai">a b c d</div> // ~60
<script>
function _reWidthAll_div(classname) {
var _maxwidth = 0;
$(classname).each(function(){
var _width = $(this).width();
_maxwidth = (_width >= _maxwidth) ? _width : _maxwidth; // define max width
});
$(classname).width(_maxwidth); // return all div same width
}
_reWidthAll_div('.ai');
</script>
I have a layout where one of my columns holds an ad. See image 1:
The ad image is in a four-column div. The ad is an MREC which is 300px wide. However, on the iPad, since the columns reduce, the ad goes down to 236px which is a no-no. See image 2 below, of course it looks the same here but it is smaller:
I need it to stay at 300px. Also, sometimes the ad server may serve an iframe-based ad (also 300px).
So that div needs to not shrink width.
I tried adding a class to that did and setting css to min-width:300px, but then on the iPad it sticks out the right edge; the other div does not shrink accordingly enough. See image 3:
So, how do I ensure the divs with my ads are not re-sized on the iPad?
EDIT: Also, the problem seems compounded when I reverse the column order with push-pull. I am doing this since I need the ad to come first on the phone but second on other platforms:
<div class="row">
<div class="four columns ad push-eight">
<img src="http://placehold.it/300x300">
</div>
<div class="eight columns pull-four">
<h1>Bacon ipsum dolor sit amet tri-tip shankle chicken leberkas beef pork</h1>
</div>
In order to get this to work, I had to step outside of Foundation a bit. Here's what you'll need.
Example: http://cdpn.io/Kypen
Explained:
I created an ad wrapper .ad and a .container element.
The .ad is 300px wide and floated to the right; while the .container element is given a 320px wide margin. Since Foundation is using border-box sizing the margin is factored in to the width of the overall .container element. As a result, the .ad sits inside the "false margin" (the 20 extra px is for white space). This is an old trick and it works inside Foundation's .row & .column elements just fine, in addition it doesn't affect nested rows from being created either.
I also added a media query, use can use this to change the behavior at low resolution.
.ad
{
float:right;
width:300px;
}
.container
{
position:relative;
margin-right:320px;
}
#media only screen and (max-width: 767px)
{
.ad
{float:none;}
.container
{margin:0;}
}
When I needed to fix the width of my sidebar I ended up doing it with calc(). I wanted to have my sidebar below the main content on smaller devices and this way it was really easy.
My layout in haml
.row
.content.column.large-9
= yield
.sidebar.column.large-3
= render 'sidebar'
Styles
.sidebar{
width: 100%;
}
.content {
width: 100%;
}
#media #{$small} {
.sidebar {
width: 225px !important;
}
.content {
width: 70.2% !important; /* Fallback for older browsers */
width: calc(100% - 240px) !important;
}
}
The media query parameter $small is really confusing as it actually means "larger than small".