Is it necessary for nested Bootstrap 3 rows to be enclosed within a col-sm-*?

Is it necessary for nested Bootstrap 3 rows to be within a col-sm-* or can they also be nested within a col-md-, col-xs-, etc?

The documentation specifies col-sm-* but does not clearly state if nesting within other col sizes is not allowed.

http://getbootstrap.com/css/#grid-nesting

Answer №1

The col-sm-* example you mentioned is just for demonstration purposes. In reality, it should be col-*-* (xs, sm, md, lg).

If you scroll down a bit, you will see examples of pushing and pulling columns using .col-md-push-* and .col-md-pull-*. This is also just a representation, as any column can be pushed and pulled as needed.

Additionally, a nested row does not have to be directly inside the parent column. The key point to remember is that each row must be immediately followed by a column, but nested rows can be enclosed by any element.

For instance:

<div class="row">
    <div class="col-xs-12">This is okay</div>
</div>

<div class="row">
    <div class="foo">
        <div class="col-xs-12">This is not okay</div>
    </div>
</div>

<div class="row">
    <div class="col-xs-12">
        <div class="row">
            <div class="col-xs-6">This is okay</div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-xs-12">
        <div class="foo">
            <div class="row">
                <div class="col-xs-6">This is okay</div>
            </div>
        </div>
    </div>
</div>

Answer №2

Utilize multiple classes simultaneously and let Bootstrap determine the most suitable one for the screen.

You have the option to nest classes within different types based on your specific requirements.

Answer №3

The classes in TWBS3 like .col-xx-x only determine width based on percentages, for example, .col-sm-4 { width: 25% }, .col-md-4 { width: 25% }, and .col-md-4 { width: 25% }.

Although they all achieve the same result, you only need to specify one.

So why have multiple options? There are two main reasons:

  1. These variants allow you to adjust column widths at different screen resolutions. For instance, .col-sm-4 .col-md-3 will display as 1/4 width on small screens and 1/3 width on medium, large, and extra-large screens.

  2. Once the screen size decreases below the chosen width, the column will revert to its 'mobile first' variant. For example, .col-sm-4 will be 1/4 width on small, medium, large, and extra-large screens, but full width on extra small screens. Similarly, using only .col-md-4 will be 1/4 width on medium, large, and extra-large screens, but full width on small and extra small screens. This is why a class combination like .col-sm-4 .col-md-4 is unnecessary.

Therefore, in response to your question: No, you only require one declaration, but remember to choose the size carefully as the column will expand to full width (width: 100%) when the screen size is smaller.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery to compare input with the current select optgroup choices

I'm struggling with looping through options within a form select. The options are grouped into optgroups, and I believe this is where my issue lies as I can't seem to find the correct syntax. My objective is to compare the value entered using .v ...

Having difficulty aligning ListItem to the right within a List

I am working with an array that contains objects which I need to display in ListItems of a List. My goal is to show these ListItems from the array Objects in a layout where odd numbers are on the left and even numbers are on the right. However, I am facing ...

Selection pseudo selectors for tooltips are a great way to provide additional

Can someone explain how tooltips change on Medium.com when you double click a word or sentence to reveal options like share and edit? https://i.stack.imgur.com/0EVmH.png ...

Invisible and Unrestricted automatic playback

Why is auto play muted in both Firefox and Chrome? How can we code it so that browsers don't block it? Here's the code I'm using: <audio id="audio1" src="https://notificationsounds.com/storage/sounds/file-sounds-1217-relax ...

What is the best way to change the size of a background image

I recently discovered a helpful tutorial on resizing background images that I found very insightful. If you're interested, you can check it out here. After attempting to apply this method to a 900px width div in order to resize only vertically, I enc ...

The footer navigation in CSS shifts position when it is hovered over

My attempt to add a <nav> at the footer was unsuccessful. The navigation bar in this fiddle is completely wrong as the entire nav moves when hovered, even though I did not include any animations. I want the items in the <nav> to stay fixed. ...

The Power of Bootstrap and Jquery Unleashed through Ajax Button

Apologies for the confusion in my previous explanation, let me clarify my question. I have a table row with a button, and when the user clicks on it, an ajax call is made to a web service. Upon successful completion of the call, I want to change the text d ...

Use jQuery to swap out every nth class name in the code

I am looking to update the 6th occurrence of a specific div class. This is my current code <div class="disp">...</div> <div class="disp">...</div> <div class="disp">...</div> <div class="disp">...</div> < ...

Click on a div to smoothly scroll to the top, then automatically scroll to the bottom if already at the top position

I've implemented a JQuery code on my website that allows the page to scroll to the top when clicking on a div with the class of .bottom. The code is working perfectly fine, here it is: function scrollToTop(){ $('.bottom').click(function ...

Issue with Inline JavaScript in `href` tag not functioning correctly in Firefox

I am encountering an issue with this inline JavaScript not working in Firefox. I need to figure out how to make it function correctly in Firefox. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style> ...

Customize the look and feel of your website using jQuery's

Is there a way to use an icon from the jQuery Themeroller as a toggle button in a Ruby on Rails project? I want the icon to switch colors when clicked, but I'm not sure how to accomplish this. Any advice on how to achieve this functionality? ...

What is the best method for aligning buttons in a row with all the other buttons?

I have been attempting to display two buttons, id="strength" and id="minion", when a certain button, id="expandButton", is clicked. I want these two buttons to be positioned on either side of the button that triggers their cre ...

Creating and adding nested div elements with the power of JavaScript

My goal is to utilize JavaScript for updating the CSS layout as the webpage loads. Below is the code I have been working on: var container = 0; // Total UI Container var containerTitle = 0; // Title Container var article = 0; var articleTitle = 0; var ...

Different dimensions of the <select> element with the help of Ryan Fait's jQuery design script

New to java and struggling on my own, I am seeking advice on how to customize Ryan Fait's jQuery input styles to accommodate 2 unique types of elements. For the code reference, please visit: While the code is efficient, I am unsure how to create two ...

Angular Material Sidenav fails to cover the entire screen while scrolling

https://i.stack.imgur.com/32kfE.png When scrolling, the Sidenav is not expanding to take up 100% of the screen and it continues to scroll along with the page content. <div layout="column"> <section layout="row" flex> <!-- siden ...

Displaying elements upon checkbox selection in React

Hello, I'm new to React and I am facing an issue with checkbox click handling in React. My goal is to display a div when a checkbox is checked and hide the div when the checkbox is unchecked. The current implementation only shows the div when the che ...

CSS: Struggling with Div Alignment

Here is a visual representation of the issue I am facing: View the screenshot of the rendered page here: http://cl.ly/image/0E2N1W1m420V/Image%202012-07-22%20at%203.25.44%20PM.png The first problem I have encountered is the excessive empty space between ...

Adjust the contents of a div to automatically fit within a hidden overflow div

Trying to fit the contents of a div (including an image, search bar, and three buttons stacked on top of each other) into another div with CSS styling that hides overflow has been a challenge. The CSS code for the div in question is: .jumbotron { overfl ...

As the cursor moves, the image follows along and rotates in sync with its

Can anyone help me figure out how to create a moving image that follows the mouse cursor? I have a radial pie menu with an image in the middle, and I want it to spin and rotate as the mouse moves. Any ideas on how I can achieve this effect? I would greatl ...

What steps can be taken to hide empty items in a list from being shown?

When I map over an array of books to display the titles in a list, I encounter an issue with the initial empty string value for the title. This causes the list to render an empty item initially. Below is my book array: @observable books = [ {title:" ...