I'm looking into the whole responsive design thing and finding fluid grids great for that - the only problem is they seem to break when I try to give a fixed width to any column. As you shrink the screen, the columns pop out of float. I'd have expected a fluid column with a percentage width (or no width) just to shrink, leaving the fixed width columns in place. How easy is it to create a hybrid fluid/fixed grid like this? I've seen one solution with inline-block instead of floated blocks, but how good is that across browsers, and is it a clean way of doing things?
Here's an example of the problem: http://jsfiddle.net/andfinally/nJ97q/2/
Thanks!
Fred
Set min-width on the wrapper div to the minimum width of the two fixed columns + a little for the next column. This makes it so it doesn't push.
#row { min-width: 400px; }
The one caveat is that it isn't supported by IE6 and below and can be buggy in IE7.
--------- EDIT -------------
What would work best for you in this situation I think would be a display: table-cell setup. This will allow everything to be locked to the positions that you are looking for.
.main {
padding: 10px;
background: #efefef;
display: table-cell; //this locks to #sideNav
}
#sideNav {
display: table-cell; //this wraps the sidebar and middle and locks to main
width: 280px;
verticle-align: top;
}
.middle {
display: table-cell; //this locks with .sidebar
width: 140px;
padding: 10px;
background: #bbb;
}
.sidebar {
display: table-cell; //this locks with .middle
width: 100px;
padding: 10px;
background: #555;
}
http://jsfiddle.net/nJ97q/73/
There's no clean way of doing this. But who needs clean?
I wouldn't reccomend mixing fixed and fluid widths, but if you are, you might need media queries (plenty of polyfills available for IE). You could then check if the container is smaller than X in which case you rearrange the layout (1/3 for all columns or just everything vertical etc).
The example is a little strange though. What's in all the white space in the middle? Which is the content?
PS. Don't use min-width. That invalidates the whole responsiveness.
I'm wondering why just not to use tables?
Like:
<table class="row">
<tr>
<td class="main">
</td>
<td class="middle">
</td>
<td class="sidebar">
</td>
</tr>
</table>
It become very simple using table layout, there is no JS, same column height, full compatibility with any browser.
Here is the example: http://jsfiddle.net/nJ97q/162/
I know everybody says that using tables is bad practice, but it really solves all this issues.
I think the solution below can probably help you.
Since you are giving the "row" div width in percentage, its resizing itself every time you shrink the window. Give it a width in pixels if you can, if you can't then use min-width so that it will not re-size below min-width and thus your panel will remain intact.
To make it smooth:
You can add javascript to make it smooth. Use window.onresize event to call a function which includes code to make "row" resize slowly by using timed function which increases width of the "row" by 10 pixel or so every 10 miliseconds till the max-length, in this case the window's length is reached. But you can effectively do this if you set the width in pixels, or else an ugly zoom-out, zoom-in effect will be produced.
Hope that helps,
Ashwin
I had a similar issue where I needed to have a fixed width left column (menu structure) but have the right column resize responsively as the browser was reduced.
I ended up implementing a few extra media queries (they already existed to handle other edge cases) and finding the percentage width of the right column that worked for that media query. This does "jump" slightly (I only used 2 "extra" media queries over the standard handheld/tablet/desktop ones) but at all resolutions in between it will not break to the next line. In effect you are adjusting the context in each media query before it can break. More media queries would equal smoother breaks as the browser is resized.
I am ok with the jumps because I am not building for the use case of someone resizing their browser, but rather to make sure it works acceptably on different resolution devices.
One caveat, when figuring the percentage widths of the right column, the base width used is the width of the media query you are in, not the original full width. Also, you have to use min-width and use the size that works at the smallest resolution for each media query section.
/* 641+ */
#media all and (min-width:641px) {
.itemDetailLanding {
width: 58.81435257410296%; /* 377 / 641 */
}
}
/* 725-768 */
#media all and (min-width: 725px) {
.itemDetailLanding {
width: 63.44827586206897%; /* 460 / 725 */
}
}
/* 769+ */
#media all and (min-width: 768px) {
.itemDetailLanding {
width: 65.625%; /* 504 / 768 */
}
}
/* 860-990 */
#media all and (min-width: 860px) {
.itemDetailLanding {
width: 69.18604651162791%; /* 595 / 860 */
}
}
/* 990+ */
#media all and (min-width:990px) {
.itemDetailLanding {
width: 74.04040404040404%;
}
}
Related
I know I can use col-xs-# to keep columns from stacking, but I have inherited a site when everything uses col-md-#. The site looks fine when the browser is full screen, but when you resize it to around 50% of the screen the columns stack even though there is still a lot of screen real estate. How can I redefine the col-md-# classes to not stack, so I don't have to find & replace all of them with col-xs-# ?
Full Screen
Browser width 1100px
You can customize Bootstrap the way you want before download it.
For version 3, take a look at this page https://getbootstrap.com/docs/3.4/customize/#media-queries-breakpoints
The default value of #screen-md param is 992px. Above this viewport width the columns (.col-md-*) will render side by side.
Althought I think this is not a best practice, all you have to do is lower this value to something above 768px (the previous breakpoint).
Important! Don't lower this value to less than 768px or you'll end up into serious grid issues.
I strongly recommend you to find-and-replace all col-md- to at least col-sm for your project.
To answer your question, adding the following CSS should do the trick.
In the first line of the media query, change 600px to the breakpoint where you want to stop the columns stacking.
#media (min-width: 600px){
.col-md-2 {
width: 16.66666667%;
float:left;
}
.col-md-3 {
width: 25%;
float:left;
}
.col-md-4 {
width: 33.33333333%;
float:left;
}
.col-md-6 {
width: 50% !important;
float:left;
}
}
Good luck
i need some CSS only code that will use the flexbox and a media query to change with screen size... I want the comment boxes on my page to be moved to the left while the browser is open on a large screen or window. then when the browser window gets smaller i want the comments to shrink a little only down to about 300px where they wont shrink any more
I have linked below two screenshots of what it looks like now and roughly what I am trying to achieve (preferably with the comment boxes being longer as well)
Thanks
Not sure what your layout is like, but mess around with these properties and feel free to read https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
Flexbox Froggy is also a great game for familiarizing yourself with flexbox
https://flexboxfroggy.com/
main {
display: flex;
justify-content: flex-start'; // this will align the items to the left/start of the parent
}
.comment-box {
width: 33%; // or whatever you want the width to be. Percentages are responsive
}
#media(max-width: 960px){
main {
justify-content: center;
}
.comment-box{
width: 95%
min-width: 300px
}
}
I can use the following CSS to make something happen if the browser width is less than 800px.
#media only screen and (max-width : 800px)
{
#content
{
width: auto;
}
}
Is there a way to make some CSS happen to a certain element if the height of that specific element is greater than a certain value?
My goal is to have special CSS trigger if the contents of an elements starts to wrap because of too narrow browser width, without being dependent on a hard coded max-width.
More specific example
<h2>Long title followed by <span class="subtitle">a subtitle</span></h2>
.subtitle
{
margin-left: .7em;
font-size: .6em;
}
#media only screen and (max-width : 600px)
{
.subtitle
{
vertical-align: super;
&:before
{
content: '\A';
white-space: pre;
}
}
}
What I need is that the .subtitle should get vertical-align: super if it wraps to another line than the rest of the title. I currently do this manually when the browser shrinks to a certain width, but the problem is that some headers are longer than this and I'd like it to happen automatically whenever a header wraps, independent of the browser width.
Media queries unfortunately only work relative to screen size (and a few other screen based properties). What you require is something the lines of the proposed 'Element Query'.
This is a common problem in CSS. One solution is to detect a change in height on the container (the <h1> in your example). It would have to detect against a hard coded pixel value and when greater than that threshold toggle a class.
You have the added complication that the change in CSS you require will affect the height of the very container you are testing against, possibly creating a circular loop of test and change. This is one of the most difficult challenges of 'Queries on Elements'.
http://library.skybundle.com/
I need the two big icons to be horizontally side by side until the window is resized to be smaller (like that of a mobile phone, for example), and then when that happens, the orange one on the right should drop down below the green one to form a vertical layout.
I know I should use media queries, as I have been told, but I am not sure how to do this or which ones to use.
I am not great at CSS, but I am learning. I have done TONS of research, spent weeks trying to figure this out. Please help. Thanks!
Make sure this is below your other rule for .skone-half.
This should work
#media(max-width: 960px) {
.skone-half {
width: 100%;
}
}
Just comment if it doesn't.
Here's a really simplified version of that portion of your site in a fiddle.
DEMO
So according to that fiddle you can tell the code works. If you have problems implementing it let me know or if it just doesn't work for some other reason. You could also adjust the point in px it changes at if you want I just set it to when it breaks the width of the container.
EDIT:
Usually though you would want to change the width of the containing element from a fixed width to 100%, this way the images center, like this.
DEMO
In your case you have two containers with widths that you need to change so it would look like this.
#media(max-width: 960px) {
.skone-half {
width: 100%;
}
#container, #head-content {
width: 100%;
}
}
Add this to your css file:
/*if the screen is 800 pixels or less */
#media only screen and (min-width: 800px) {
.page {width: 100%; } /*set your page class to be 100% width */
}
Here's a starting point for your jsfiddle (which exihibits the side-by-side -> vertical layout!).
http://jsfiddle.net/gjGGw/1/
HTML
<img src="http://library.skybundle.com/wp-content/uploads/2013/10/PRODUCT_TRAINING2.png" />
<img src="http://library.skybundle.com/wp-content/uploads/2013/10/EDUCATIONAL_COURSES2.png" />
CSS
img{width:300px;height:300px;margin:0px 30px;}
I created this site off of a PSD, all relatively elementary CSS. I have unwanted outside padding on a mobile device AND a tablet. I want the left and right edges of the site to be flush with the edges of the browser. Its about 20px of unwanted padding.
Please see my dev site:
http://america.82ndmedia.com/
I have tested removing the "margin: 0 auto" of the container div and it fixes it... however I need that for it to function on a desktop.
.container {
width: $w_total;
margin: 0 auto;
}
Any tips would be greatly appreciated. Thank you!
This is being caused by the rule:
#media (max-width: 450px) {
.header, .columns > .sidebar, .post_box, .prev_next, .comments_intro,
.comment, .comment_nav, #commentform, .comment_form_title, .footer {
padding-right: 13px;
padding-left: 13px;
}
Either remove or override this rule somehow.
I'd recommend using percentages instead of pixels because your current setup won't work and is hard to maintain using hardcoded pixels for a responsive design.
For example, you have your main wrapper div class="container" set to a max-width of 717px on smaller screens (which seems random), but inside of it you have elements like id="blog" set to a width of 1020px, which obviously won't fit.
If you set those inner elements to percentages of their outer container, it'll be a lot easier to make it work and it'll be truly responsive or fluid.