I am having difficulties with stacking my divs alongside one another when the screen size is smaller, then stack on top of one another once I hit phone size.
I am using Foldy Grids by Paravel, On full desktop size, there are 3 divs that are side by side, but I want this to shrink to 2 side by side and then on phone, just 1 on top of one another. However I feel as though I am applying the media queries to the incorrect <div>'s. Any guidance would be much appreciated. Within the CSS the reason I put 33% in is due to the divs being divided into 3 on full desktop mode.
CSS:
#media screen and (max-width: 900px) {
.dashboardIconsMod {
width: 50%;
}
}
#media screen and (max-width: 600px) {
.dashboardIconsMod {
width: 100%;
}
}
.dashboardIconsMod {
color: pink;
border-style: solid;
border-color: red;
}
HTML:
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="cf show-grid">
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 1st Div -->
<p> 1st Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 2nd Div -->
<p> 2nd Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 3rd Div -->
<p> 3rd Grid </p>
</div>
</div>
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 4th Div -->
<p> 4th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 5th Div -->
<p> 5th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 6th Div -->
<p> 6th Grid </p>
</div>
</div>
</div>
</section>
</div>
</section>
I am not sure about Foldy Grids by Paravel as never worked with it and don't have much time to read documentation, but you can fix it by giving different size on media query, just make sure your media query need to be below to your desktop code.
For now, 3 items on the desktop, on smaller screens like iPad there are 2 items and on the smaller screen below 600px, there is a single item.
.dashboardIconsMod {
color: pink;
border-style: solid;
border-color: red;
width:33.33%;
}
* {box-sizing: border-box;}
.show-grid .row {display:flex; flex-wrap: wrap;}
#media screen and (max-width: 900px) {
.dashboardIconsMod {
width: 50%;
}
}
#media screen and (max-width: 600px) {
.dashboardIconsMod {
width: 100%;
}
}
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="cf show-grid">
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 1st Div -->
<p> 1st Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 2nd Div -->
<p> 2nd Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 3rd Div -->
<p> 3rd Grid </p>
</div>
</div>
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 4th Div -->
<p> 4th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 5th Div -->
<p> 5th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 6th Div -->
<p> 6th Grid </p>
</div>
</div>
</div>
</section>
</div>
</section>
Related
I have a simple Bootstrap layout:
<div class="row">
<div class="footer_column col-md-4">
<div class="footer_item">
ABOUT
</div>
<div class="footer_item">
Contact Us
</div>
<div class="footer_item">
Terms & Conditions
</div>
<div class="footer_item">
Privacy Policy
</div>
</div>
<div class="footer_column col-md-4">
<div class="footer_item">
SITE RESOURCES
</div>
<div class="footer_item">
General Rules
</div>
<div class="footer_item">
Scoring
</div>
<div class="footer_item">
Game Coins
</div>
<div class="footer_item">
<a class="store-show">Store</a>
</div>
<div class="footer_item">
Account Types
</div>
</div>
<div class="footer_column col-md-4">
<div class="footer_item">
MORE FANTASY FOOTBALL
</div>
<div class="footer_item">
<div class="footer_item">
Fantasy Game
</div>
</div>
</div>
</div>
In Chrome and Firefox it looks like it's supposed to (a 3 column layout):
But in Safari the 3rd column ends up in a new line below the other. When I inspect it, it has the correct width (exactly 1/3 of the total row width) in both Chrome and Safari.
I am seeing this when I inspect the element:
.col-md-4 {
flex: 0 0 33.3333333333%;
max-width: 33.3333333333%;
}
When I remove the max-width attribute, each column spreads out to 100%. This is expected I suppose. But when I add width: 20% for example, the width of each column remains the same as it was!
How can I make Safari behave?
If you're using a container around the row then add a helper class to remove the before content.
<div class="container before-fix"><!-- content --></div>
.before-fix::before {
content: none;
}
I fixed this here. The problem was the flex was overriding the default width.
This is what the CSS is now:
.col-md-4 {
flex: none;
max-width: 33.3333333333%;
width: 20%;
}
It successfully sets the width of the columns to 20% instead of 33.3%.
Here's a really clean way using grid instead of bootstrap...
.three-columns {
display: grid;
grid-template: 1fr 1fr 1fr;
}
<div class="three-columns">
<div>column 1</div>
<div>column 2</div>
<div>column 3</div>
</div>
I would like to align three div in one line with a little space between first div and second div and last div using bootstrap as you see in the picture :
I try with this code :
<div class="row">
<div class="col-md-2">
<img src="img/emo_positif.png')}}">
</div>
<div class="col-md-7">
<div class="square1"></div>
</div>
<div class="col-md-3">
<img src="img/emo_negative.png')}}">
</div>
</div>
but it shows me a big space between the div
Using Bootstrap 3:
.row {
height: 24px;
}
.row > div {
height: 100%;
}
.square {
background: pink;
}
.square1 {
background: #01a8ff;
height: 100%;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" >
<div class="row">
<div class="col-xs-2 square">
</div>
<div class="col-xs-8">
<div class="square1"></div>
</div>
<div class="col-xs-2 square">
</div>
</div>
Check this Pen.
Read the docs.
For making the three division in same line . There are many ways. For better UX use display:flex in css for the parent division
Thanks
I am new to bootstrap. Why is the second row with 3 columns (col-sm-3, col-sm-6 and col-sm-3) being indented, the other two rows have a wider width? How can I make all rows the same width?
.header {background-color: #9933cc;}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li {
background-color :#33b5e5;
margin-bottom: 7px;
}
.aside {background-color: #33b5e5;}
.footer {background-color: #0099cc;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class='container'>
<div class='row'>
<div class='header'>
<h1>China</h1>
</div><!--end header-->
</div>
<div class='row'>
<div class='menu col-sm-3'>
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div><!--end menu-->
<div class='col-sm-6'>
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
<div class='col-sm-3'>
<div class='aside'>
<h2>What?</h2>
<p>Chania is a city on the island of Crete.</p>
<h2>Where?</h2>
<p>Crete is a Greek island in the Mediterranean Sea.</p>
<h2>How?</h2>
<p>You can reach Chania airport from all over Europe.</p>
</div>
</div>
</div>
<div class='row'>
<div class='footer'>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div><!--end footer-->
</div>
</div><!--end container-->
Because .col-sm-3 and .col-md-6 adds padding to the div elements.
Wrap the header and footer in col-sm-12
HTML
<div class="col-md-12">
<div class='header'>
<h1>China</h1>
</div><!--end header-->
</div>
<div class="col-sm-12">
<div class='footer'>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div><!--end footer-->
</div>
Working Fiddle
Adding .col-sm-12 class to .footer and .header div's don't change because, background-color property is applied on .header and .footer and color is applied including the padding.
Wrapping these elements (footer and header) divs in .col-sm-12 adds padding to parent elements.
I'm building a Carousel-type component, but am having some difficulty getting it to work just right.
My basic approach is a div (wrapper) with lots of other divs (items) in it. I want to display 4 items on the carousel at any one time. The items have various content heights, but the heights of the items should be equal (to the largest required).
I can't work out the CSS combination I need to get this to work correctly.
With this setup (HTML + CSS at bottom of post), the width: 25%; on each item-container is ignored.
If I add a fixed with to .item, then the 25% kicks in, but the item width is unknown -- it depends on the browsers size. Setting it to 1000px means you lose content from the item. Setting it to ~210px works, but when you start shrinking your browser, you lose content. On a large browser, you have excessive spacing.
Curiously, if I add flex-wrap: wrap to the CSS, then the 25% width is applied correctly -- but I can't do that, because then it's not a carousel! Example
The scenario is simple:
An unknown amount of items in a div with overflow: auto, which are equal heights should be displayed, with 4 of the children divs on the screen at any one time.
My HTML is structured as follows:
<div id="container">
<div id="wrapper">
<div class="item-container">
<div class="item">
<p>
Carousel Item #1 with some quite long text.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #2.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #3.
</p>
</div>
</div>
...
</div>
</div>
My CSS:
#container {
width: 100%;
background: #0f0;
overflow: auto;
}
#wrapper {
display: flex;
}
.item-container {
border: 1px solid #f00;
width: 25%;
}
Note, this is my MCVE. On my real component, I have buttons for scrolling left and right, the content is significantly more complex and stuff like that.
All you need is to add flex: 0 0 auto to .item-container elements.
* {
box-sizing: border-box;
}
#container {
width: 100%;
background: #0f0;
overflow: auto;
}
#wrapper {
display: flex;
}
.item-container {
border: 1px solid #f00;
flex: 0 0 auto;
width: 25%;
}
<div id="container">
<div id="wrapper">
<div class="item-container">
<div class="item">
<p>
Carousel Item #1 with some quite long text.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #2.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #3.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #4.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #5.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #6.
</p>
</div>
</div>
<div class="item-container">
<div class="item">
<p>
Carousel Item #7.
</p>
</div>
</div>
</div>
</div>
I am just starting with responsive webdesign. I have a 2 column layout (sidebar and content).
<div class="main-container">
<div class="main wrapper clearfix">
<div class="con1">
<header>
<h1>container 1 h1</h1>
<p>text1</p>
</header>
<section>
<h2>overview section h2</h2>
<p> test</p>
</section>
</div>
<div class="con2">
<header>
<h1>container 2 article header h1</h1>
<p></p>
</header>
<section>
<h2>article section h2</h2>
<p>text</p>
</section>
</div>
<aside>
<h3>aside</h3>
<p>text</p>
</aside>
</div> <!-- #main -->
</div> <!-- #main-container -->
The content got 2 div container. On a small screen I want
Div1
Div2
On a large screen I want them swapped,
Div2
Div1
In my CSS I now got the following Media Query:
#media only screen and (min-width: 768px) {
.main div.con1 {
float: right;
width: 57%;
}
.main div.con2 {
float: right;
width: 57%;
}
Is it possible to swap the order around and if so, how can I do it? Anyone got maybe a link to a good tutorial?
Thanks a lot in advance !
The method used in the StackOverflow question "CSS positioning div above another div when not in that order in the HTML" seems to be your best bet.
with js:
//on load
responsive_change_box_order();
//on resize
window.addEventListener('resize', responsive_change_box_order );
function responsive_change_box_order() {
if (window.matchMedia("(max-width: 1118px)").matches) {
jQuery("#block-menu-block-1").remove().insertBefore(jQuery("#content"));
}
else{
jQuery("#block-menu-block-1").remove().prependTo(jQuery(".region-sidebar-second .region-inner"));
}
}
This snippet uses flexbox and related properties to meet your end requirement.Also kindly note that you use use appropriate vendor prefixes for flexbox when you implement or use something like autoprefixer or prefixfree.
.main{
display:flex;
flex-direction:column
}
.con1{
order:2;
background-color: green;
}
.con2{
order:1;
background-color: red;
}
/*For Large screen only*/
#media(min-width:1200px){
.con1{
order:1;
}
.con2{
order:2;
}
}
<div class="main-container">
<div class="main wrapper clearfix">
<div class="con1">
<header>
<h1>container 1 h1</h1>
<p>text1</p>
</header>
<section>
<h2>overview section h2</h2>
<p> test</p>
</section>
</div>
<div class="con2">
<header>
<h1>container 2 article header h1</h1>
<p></p>
</header>
<section>
<h2>article section h2</h2>
<p>text</p>
</section>
</div>
<aside>
<h3>aside</h3>
<p>text</p>
</aside>
</div>
<!-- #main -->
</div>
<!-- #main-container -->