1
I am building a Grid System using CSS Grid and I am having a bit of difficulty. I have a shrink class that works as it is supposed to, but I would like the rest of the cells(as I call them) to fit the space in css grid. If I set .cell.shrink to grid-column:auto, is there a way to have the other cells fit the space?
2
Also, if you notice the code below, I have a class for .cell > * {whitespace:nowrap;}. Without it my links are collapsing. Is there a better way to keep it from collapsing? I just want the cell to fit the content without collapsing. I don't want to set a static value in the minmax() function either --- Example of what I DON'T want (minmax(100px, 1fr)). Again, I am trying to use css grid for this. I know flexbox just fits to the content. How can I achieve with css grid?
Below is the code I have tried.
CODEPEN LINK
https://codepen.io/Jesders88/pen/djmwNY
HTML
<div class="container">
<div class="row">
<div class="cell medium-3 shrink">
<nav>
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</nav>
</div>
<div class="cell medium-3">CellCellCellCellCell</div>
<div class="cell medium-3">Cell</div>
<div class="cell medium-3">Cell</div>
</div>
</div>
Grid CSS
.row {
display:grid;
grid-gap:120px;
grid-template-columns:repeat(12, 1fr);
}
TRIED CSS
.shrink {
grid-column:auto !important;
}
.row {
max-width:1600px;
> .cell {
* {
white-space:nowrap;
}
}
}
Related
I hired someone to implement the design of a website. He is using bootstrap 3 (which I've used before in some projects) and it surprised me that he is avoiding the use of .row class in every the grid and subgrid built (he is using clearfix to make the rows). He's code looks something like this...
<div class="container">
<div class="col-md-7">
<ul>
<li><a>item 1</a></li>
<li><a>item 2</a></li>
<li><a>item 3</a></li>
</ul>
</div>
<div class="col-md-5 pull-right">
<ul class="nav nav-tabs">
<li><i class="fa fa-users" aria-hidden="true"></i>Menu item 1</li>
<li class="shop">Item 2</li>
</ul>
</div>
<div class="clearfix"></div>
</div>
From what I've read, .row class is used to
"create horizontal groups of columns." source
"row nullifies the padding set by the container element by using a negative margin value of -15px on both the left and right sides." source
What is the impact of not using this class inside the grid structure? should I make sure he uses .row class?
thanks
From the bootstrap docs
Rows must be placed within a .container (fixed-width) or
.container-fluid (full-width) for proper alignment and padding.
You are also correct in that .row clears the gutters from the container which has a padding of 15px left and right.
.container {
padding-right: 15px;
padding-left: 15px;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
Therefore, I personally would err on the side of caution and follow the requirements set out by bootstrap. In the future, the framework could change and a strong reliance could be created upon the row class and since that is missing from your code, it would require reworking it to update versions... or optionally, you could choose to implement responsive selectors such as .col-xs- which could over or underlap the 12 column grid format.
I have a menu, content and footer. Menu has fixed position. If I scroll it down to the end of page it becomes to overlay the footer. How can I force menu to move up if it starts to overlay the footer?
EDIT:
I use bootstrap classes.
My Html
<div class="container">
<div class="row">
<div class="col-sm-3" id="myScrollspy">
<ul class="nav nav-pills nav-stacked">
<li class="active">Section 1</li>
<li>Section 2</li>
<li>Section 3</li>
...
</ul>
</div>
<div class="col-sm-9">
<div id="section1">
<h1>Section 1</h1>
<p>Try to scroll this section and look at the navigation list while scrolling!</p>
</div>
<div id="section2">
<h1>Section 2</h1>
<p>Try to scroll this section and look at the navigation list while scrolling!</p>
</div>
...
</div>
</div>
Css:
ul.nav-pills {
position:fixed;
}
You should use the bootstrap "affix" plugin.
http://getbootstrap.com/javascript/#affix
You can see an example here of how it works in combination with the scrollspy.
http://codepen.io/SitePoint/full/GgOzwX/ (Not my code)
Essentially what you do is tell it when to start and stop being a 'fixed' element.
$('#nav').affix({
offset: {
top: $('#nav').offset().top,
bottom: ($('footer').outerHeight(true) + $('.application').outerHeight(true)) + 40
}
});
change menu, content and footer to block.
add css :
.clearfix::before, .clearfix::after {
content: "";
display: table;
}
.clearfix::after {
clear: both;
}
and add class clearfix to your footer (highest hierarchy) and to class container.
Here is my css rule together with the markup:
<div style = "height:100%;">
<div style = "width:220px; margin-left: 200px;font-size:16px; height:auto;">
<div class='navbar-inner'>
<div class='container'>
<ul class="nav nav-list">
<div>
<li <?php if($page == 'upload_track'){ echo "class = \"active\""; }?>>Upload a new Track</li>
<li>View all blog post</li>
<li>View all tracks uploaded</li>
</div>
</ul>
</div>
</div>
</div>
<div style = "width:220px; margin-left: 200px;font-size:16px; height:auto;">
as of now I am making them an inline style so that it would be easy for me to change them. since switching texteditors is kind of a hassle for me.
How would I make that div take up all the available height? like the very bottom of the page. as of now it looks something like this
what I wanted to see is that the black div takes up all the available height in the page
Yes it can be done. Check out this example JSFiddle.
Basically I changed your HTML to this:
<div id="navbar">
<div class='navbar-inner'>
<div class='container'>
<ul class="nav nav-list">
<div>
<li>Upload a new Track</li>
<li>View all blog post</li>
<li>View all tracks uploaded</li>
</div>
</ul>
</div>
</div>
</div>
Essentially all I did was remove the outermost div (the one with only the style="height: 100%" on it) and gave the next div an id.
The CSS is as follows:
html, body { height: 100%; }
#navbar {
/* this was moved from being an inline style in the div: */
width:220px; margin-left: 200px;font-size:16px;
height: 100%;
}
Basically, in order for the navbar strip to use up 100% of the height, you need to make sure that the html and body actually take up 100% of the available height. (That is, 100% on #navbar is 100% of the height of the parent element; if the parent element isn't the height of the browser, then it doesn't work.)
Suppose we have the following markup for navigation bar using Twitter Bootstrap 2.0.
<div class="navbar navbar-fixed-top">
<div class="navbar-inner pull-center">
<ul class="nav">
<li class="active">HOME</li>
<li>CONTACT</li>
</ul>
</div>
</div>
What is the best way to center .nav inside navbar-inner?
I only came up with adding my own CSS styles:
#media (min-width: 980px) {
.pull-center {
text-align: center;
}
.pull-center > .nav {
float:none;
display:inline-block;
*display: inline; *zoom: 1;
height: 32px;
}
}
Override the width of the container within the navbar from auto to 960px.
.navbar-inner .container {width:960px;}
To align it in the center with a dynamic width, I used the following:
HTML:
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
....
</ul>
</div>
</div>
CSS:
.navbar .navbar-inner {
text-align: center;
}
.navbar .navbar-inner .nav {
float: none;
display:inline-block;
}
Didn't test it, but I guess only display:inline-block; could be a problem, which is supported in all browsers except for IE7 and lower..
http://caniuse.com/inline-block
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active">Home</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
Just using the container class as per http://twitter.github.com/bootstrap/components.html#navbar is centering my nav; however, it is fixed width and the formatting is off (the height of the nav bar is increased and its very possible something I'm doing wrong).
It would be nice to have the nav centered in a fluid, percentage-based width, with a minimum width, based on some minimum supported device screen size, and nowrap. (I'm a newbie wrt the responsive media queries and perhaps that is the better alternative to percentage based.)
Still investigating the minimum width and nowrap, but another alternative to the bootstrap container class fixed width is to add a child of the navbar-inner. I would like to know if there is a built-in bootstrap solution such as the row-fluid and spanN classes, but I haven't been able to get that formatted correctly within the nav either.
<div style="margin-left: 15%; margin-right: 15%;">
I have found this useful and clean:
<div class="navbar navbar-fixed-top">
<div class="container">
<ul class="nav">
<li class="active">HOME</li>
<li>CONTACT</li>
</ul>
</div>
</div>
where, css is:
.container {left:auto;right:auto}
This will center the div on the base of the width of your current navbar.
Responsiveness is managed apart.
<div id="container">
<div class="category-group">
<h4>title</h4>
<ul>
<li>item</li>
<li>item</li>
</ul>
</div>
<div class="category-group">
<h4>title</h4>
<ul>
<li>item</li>
<li>item</li>
</ul>
</div>
</div>
<style>
.category-group {
display: inline-block;
vertical-align: top;
}
</style>
I want all category-groups to be arranged one after another and fit together in the container. In this case, second category-group would go right under the first category-group, then there would be third on the right of the first and the second and so on.
If I try to give category-group display: inline, all category-groups are then lined in one long column that would break out of the container.
I have faced this problem as well. I ended up using jQuery Masonry to get my div's to stack nicely within a fixed width container.
To my knowledge, there isn't a pure CSS fix that will achieve this effect.