Offset Columns In Bootstrap - Stack Overflow

    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs Offset columns in Bootstrap Ask Question Asked 7 years, 11 months ago Modified 2 months ago Viewed 138k times 39

This is the idea of what I want to do:

<div class="container-fluid"> <div class="row"> <div class="col-sm-2"></div> <div class="col-sm-4"></div> <div class="col-sm-4"></div> <div class="col-sm-2"></div> </div> </div>

How would it work using offset?

Share Improve this question Follow edited Dec 10, 2018 at 12:22 Philipp Kief's user avatar Philipp Kief 8,6035 gold badges35 silver badges43 bronze badges asked Jan 13, 2017 at 1:15 sumguy's user avatar sumguysumguy 3911 gold badge3 silver badges5 bronze badges Add a comment |

6 Answers 6

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 57

The offset works like a blank column that will stay before your column. For example, if you want a column that will have half of the size of the screen and will be exactly in the middle, you will have to do:

<div class="col-sm-6 col-sm-offset-3"></div>

A full row has 12 columns. This way you will have 6 columns (half of the row) and a offset of 3 columns. It will be exactly in the middle of the screen.

Take a look on Bootstrap documentation.

Share Improve this answer Follow answered Jan 13, 2017 at 1:24 Luiz Henrique's user avatar Luiz HenriqueLuiz Henrique 9578 silver badges27 bronze badges 4
  • 1 Thank you very much! That explained the concept well :) – sumguy Commented Jan 13, 2017 at 1:25
  • You are welcome! can you vote and accept the answer, please? – Luiz Henrique Commented Jan 13, 2017 at 1:31
  • 29 In Bootstrap 4 use offset-sm-3 instead of col-sm-offset-3 – Ricardo D. Quiroga Commented Jul 24, 2018 at 1:59
  • 1 such an underrated answer for people who were using the previous versions of bootstrap – Grijan Commented Jan 11 at 18:23
Add a comment | 30

In Bootstrap 3, like this..

<div class="container-fluid"> <div class="row"> <div class="col-sm-4 col-sm-offset-2"></div> <div class="col-sm-4"></div> </div> </div>

http://codeply.com/go/7wofwfzrH3

In Bootstrap 4, like this..

<div class="container-fluid"> <div class="row"> <div class="col-sm-4 offset-sm-2"></div> <div class="col-sm-4"></div> </div> </div>

https://codeply.com/go/t5DTGwero8

Share Improve this answer Follow edited Apr 11, 2023 at 13:26 answered Jan 13, 2017 at 1:20 Carol Skelly's user avatar Carol SkellyCarol Skelly 362k91 gold badges733 silver badges645 bronze badges 2
  • Thank you!! How come the second col-sm-4 didn't need an offset if I was trying to do "2 4 4 2"? – sumguy Commented Jan 13, 2017 at 1:28
  • @sumguy Offset columns add margins to left so in this case, first there is margin/space of col-2 then two div's of col-4 and then the remaining col-2 is the remaining space. Consider a parent of 100% and a child of 70%(random), so now you have 30% of free space/ empty column to right side. – divy3993 Commented Jan 13, 2017 at 3:12
Add a comment | 9

The above doesn't work for me as I think the bootstrap classes have changed slightly.

<div class="col-md-4 offset-md-2">

Does work for me.

Hope this helps

Dave

Share Improve this answer Follow answered Dec 6, 2018 at 9:51 demsley's user avatar demsleydemsley 3273 silver badges6 bronze badges 0 Add a comment | 3

An example for Bootstrap 5 is below.

But note that offset is used for margin-left alignment. If you want to align items with margin-left, you can use offset classes. There are two types of offsets in Bootstrap 5: First is offset from 1-12 and second is responsive classes like offset-sm, offset-lg, offset-md.

It looks like this:

<div class="container-fluid"> <div class="row"> <div class="col-sm-2 offset-sm-2"></div> <div class="col-sm-4 offset-sm-4"></div> </div> </div> Share Improve this answer Follow edited Dec 28, 2022 at 0:25 Michael M.'s user avatar Michael M. 11.1k11 gold badges21 silver badges43 bronze badges answered Dec 26, 2022 at 3:49 IMRAN H's user avatar IMRAN HIMRAN H 1267 bronze badges 1
  • Offset Bootstrap 4: getbootstrap.com/docs/4.0/layout/grid/#offset-classes Offset Bootstrap 5: getbootstrap.com/docs/5.0/layout/columns/#offset-classes – Bang Andre Commented Nov 23, 2023 at 7:51
Add a comment | 1

I am using bootstrap 3. Below code is worked for me to shift div right.

<div class="col-lg-4 offset-lg-4"></div> Share Improve this answer Follow answered Feb 19, 2021 at 9:29 Akash Pawar's user avatar Akash PawarAkash Pawar 91 bronze badge Add a comment | 0

In bootstrap 5 + check order column

<div class="col-lg-4 offset-lg-4"></div> Share Improve this answer Follow answered Oct 16 at 8:15 Ridha Rahmi's user avatar Ridha RahmiRidha Rahmi 1 Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • Why do developers love clean code but hate writing documentation?
  • This developer tool is 40 years old: can it be improved?
  • Featured on Meta
  • The December 2024 Community Asks Sprint has been moved to March 2025 (and...
  • Stack Overflow Jobs is expanding to more countries
2 Twitter Bootstrap: offsetting columns? 0 Bootstrap column offsetting 0 Offsetting columns in Bootstrap 2 Bootstrap 3 1.5 column offset 1 Offsetting columns in bootstrap doesn't work for second row 5 Bootstrap: how to add vertical offset in columns? 0 Bootstrap Grid and column offset 0 column offset in bootstrap 3 is always on the right 22 Offsetting columns is not working (Bootstrap v4.0.0-beta) 0 Why isn't BootStrap column offset working?

Hot Network Questions

  • Is it important that my dishwasher's cabinet seals make contact with the opening?
  • If you are working remotely as a contractor, can you be allowed to applying as a business vistor to Australia?
  • Is it possible to translate/rotate the camera in geometry nodes?
  • C++ code reading from a text file, storing value in int, and outputting properly rounded float
  • Does a rise in hourly wage (not unearned income) have an income effect, or just a substitution effect?
  • Will a 10-speed Tiagra shifter work with 9-speed sora drivetrain
  • PSE Advent Calendar 2024 (Day 21): Wrap-Up
  • Under epistemological pluralism, how can one determine the most suitable epistemology to apply in a given context?
  • How is the associator defined in the Eilenberg-Moore category of a monoidal monad?
  • Noisy environment while meditating
  • How to read this old French speed gauge?
  • Suspension spectrum functor
  • Help in identifying this dot-sized insect crawling on my bed
  • Prove that the space of square integrable vector valued functions is separable
  • Why do many PhD application sites for US universities prevent recommenders from updating recommendation letters, even before the application deadline?
  • Translation of "Nulla dies sine linea" into English within Context Given
  • Kodaira-Thurston manifold
  • Copyright on photographic reproductions of old paintings
  • A prime number in a sequence with number 1001
  • Grounding isolated electrical circuit from a floating source (EV V2L)
  • What does negative or minus symbol denote in a component datasheet?
  • Is "Bich" really Latin for "generosity"?
  • Should parameter names describe their object type?
  • How was fraud by false representation charged in this case?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Col-md-offset-4