Horizontal tabs html placed in a Moodle book, when you view this it doesnt show you the content i have placed in it, its just blank, when you click on the tab then you can see the content, but its like the initial view as the page is opened shows nothing, and once the tab is clicked on its viewable, but that is very annoying. Any help?
<!-- Start of horizontal tabs -->
<ul class="nav nav-pills mb-0" id="pills-tab" role="tablist">
<li class="nav-item">
<a class="nav-link active show" id="h-tabs-t1-tab" data-toggle="pill" href="#h-tabs-t1" role="tab" aria-controls="h-tabs-t1" aria-selected="true">ONE</a>
</li>
<li class="nav-item">
<a class="nav-link" id="h-tabs-t2-tab" data-toggle="pill" href="#h-tabs-t2" role="tab" aria-controls="h-tabs-t2" aria-selected="false">TWO</a>
</li>
<li class="nav-item">
<a class="nav-link" id="h-tabs-t3-tab" data-toggle="pill" href="#h-tabs-t3" role="tab" aria-controls="h-tabs-t3" aria-selected="false">THREE</a>
</li>
</ul>
<div class="tab-content card" id="pills-tabContent">
<div class="tab-pane p-3 fade active show" id="h-tabs-t1" role="tabpanel" aria-labelledby="h-tabs-t1-tab">
<h4>ONE</h4>
<p>Nisl vel pretium lectus quam id leo. Dolor purus non enim praesent elementum facilisis leo vel. Sit amet nulla facilisi morbi tempus. Facilisis volutpat est velit egestas dui id ornare. Est lorem ipsum dolor sit amet.</p>
</div>
<div class="tab-pane p-3 fade" id="h-tabs-t2" role="tabpanel" aria-labelledby="h-tabs-t2-tab">
<h4>TWO</h4>
<p>Sollicitudin ac orci phasellus egestas tellus rutrum. Commodo odio aenean sed adipiscing diam donec adipiscing tristique risus. </p>
</div>
<div class="tab-pane p-3 fade" id="h-tabs-t3" role="tabpanel" aria-labelledby="h-tabs-t3-tab">
<h4>THREE</h4>
<p>Aliquet enim tortor at auctor urna nunc id. Sem integer vitae justo eget magna fermentum.</p>
</div>
</div>
<!-- End of horizontal tabs -->
Did you include the jquery library script in the html?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
Also adding 'show' class in the divs wrapping the content of each tab too
<div class="tab-pane p-3 fade show"
id="h-tabs-t2"
role="tabpanel"
aria-labelledby="h-tabs-t2-tab">
<h4>TWO</h4>
<p>
Sollicitudin ac orci phasellus egestas tellus rutrum. Commodo odio
aenean sed adipiscing diam donec adipiscing tristique risus.
</p>
</div>
Related
I am developing a asp.net core MVC web application, using bootstrap and am trying to create a sidebar and main content area. I have created the code below within a partial view which is then referenced in _Layout.cshtml. This working as expected however I wish for my main content (currently placeholder text) to be positioned next to this, instead of what is seen in the image below where it is pushed below the sidebar.
This I the look I am trying to achieve:
Essentially a design with the sidebar on the left with main content on the right, however as can be seen the main content currently shows below the sidebar.
The HTML for the Sidebar:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="d-flex flex-column text-white bg-dark" style="width: 280px; height: 100vh;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<img class="img-fluid m-auto pt-sm-2" src="~/assets/img/Config.png" alt="Logo" style="height: 60px; width: 150px;" />
</a>
<div class="d-flex align-items-center text-light text-decoration-none">
</div>
</div>
<div class="container d-flex flex-column">
<main role="main" class="pb-3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lacus viverra vitae congue eu consequat ac felis donec. Eros in cursus turpis massa tincidunt. Mattis enim ut tellus elementum.
Facilisi cras fermentum odio eu feugiat. Neque volutpat ac tincidunt vitae semper. Nulla pharetra diam sit amet nisl suscipit adipiscing. Lobortis feugiat vivamus at augue eget. At augue eget arcu dictum varius duis at consectetur. Et netus et malesuada
fames ac. Morbi tristique senectus et netus et. Et pharetra pharetra massa massa ultricies mi quis hendrerit dolor.</p>
</main>
</div>
How can I position the main placeholder content next to the sidebar instead of below it?
Your problem could be easily solved by using flexbox rightfully. Here is the code for you.
HTML:
<div class="wrapper d-flex justify-content-between">
<div class="item d-flex flex-column text-white bg-dark">
<a class="d-flex align-items-center justify-content-center text-white text-decoration-none" href="/">
<img alt="Logo" class="img-fluid m-auto pt-sm-2" src="~/assets/img/Config.png" style="height: 60px; width: 150px;"/>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
</ul>
<hr>
<div class="d-flex align-items-center text-light text-decoration-none justify-content-center">
<ul class="nav-item d-flex">
<li class="navbar-footer-list px-2">
<a class="btn navbar-btn-circle text-muted" href="#">
<i class="fas fa-paint-roller">
</i>
</a>
</li>
<li class="navbar-footer-list px-2">
<a class="btn navbar-btn-circle text-muted" href="#">
<i class="far fa-question-circle">
</i>
</a>
</li>
<li class="navbar-footer-list px-2">
<a class="btn navbar-btn-circle text-muted" href="">
<i class="fab fa-github">
</i>
</a>
</li>
</ul>
</div>
</div>
<div class="item d-flex flex-column">
<main class="p-5" role="main">
<h2>Home</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lacus viverra vitae congue eu consequat ac felis donec. Eros in cursus turpis massa tincidunt. Mattis enim ut tellus elementum. Facilisi cras fermentum odio eu feugiat. Neque volutpat ac tincidunt vitae semper. Nulla pharetra diam sit amet nisl suscipit adipiscing. Lobortis feugiat vivamus at augue eget. At augue eget arcu dictum varius duis at consectetur. Et netus et malesuada fames ac. Morbi tristique senectus et netus et. Et pharetra pharetra massa massa ultricies mi quis hendrerit dolor.
</p>
</main>
</div>
</div>
CSS:
<style type="text/css">
body, html {
height: 100%;
}
.wrapper {
width: 100%;
height: 100%;
}
.wrapper .item:nth-child(1) {
flex: 0.25;
}
.wrapper .item:nth-child(2) {
flex: 0.7;
}
</style>
The problem is that I want the navigation menu to be 100% height of bordered div and I don't really know where is the issue.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<div class=" mt-5 border rounded h-100">
<div class="d-flex flex-column navbar-dark bg-dark rounded-start float-start h-100">
<div class=" flex-column px-2" style="">
<ul class="navbar-nav justify-content-center me-auto mb-2 mb-lg-0 flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
<div class=" d-flex flex-column content p-3">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel lacus a sem hendrerit lobortis. Vestibulum vel nulla non velit rhoncus eleifend. Suspendisse molestie nec nisl cursus fringilla. Morbi aliquet turpis sit amet pulvinar bibendum. Curabitur
non nunc in tellus vehicula volutpat molestie malesuada ante. In lobortis quam sed maximus scelerisque. Duis imperdiet mollis ornare. Morbi aliquet turpis sit amet pulvinar bibendum. Curabitur
non nunc in tellus vehicula volutpat molestie malesuada ante. In lobortis quam sed maximus scelerisque. Duis imperdiet mollis ornare.
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
Can you please check the below code? Hope it will work for you. You have to remove height(h-100) from navbar-dark and please give d-flex to the parent element.
Please refer to this link: https://jsfiddle.net/yudizsolutions/1j87zkqb/
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<div class="d-flex mt-5 border rounded h-100">
<div class="d-flex flex-column navbar-dark bg-dark rounded-start float-start">
<div class=" flex-column px-2" style="">
<ul class="navbar-nav justify-content-center me-auto mb-2 mb-lg-0 flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
<div class=" d-flex flex-column content p-3">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel lacus a sem hendrerit lobortis. Vestibulum vel nulla non velit rhoncus eleifend. Suspendisse molestie nec nisl cursus fringilla. Morbi aliquet turpis sit amet pulvinar bibendum. Curabitur
non nunc in tellus vehicula volutpat molestie malesuada ante. In lobortis quam sed maximus scelerisque. Duis imperdiet mollis ornare. Morbi aliquet turpis sit amet pulvinar bibendum. Curabitur non nunc in tellus vehicula volutpat molestie malesuada
ante. In lobortis quam sed maximus scelerisque. Duis imperdiet mollis ornare.
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
I'm having difficulty getting my columns to spread out.
According to the docs (https://getbootstrap.com/docs/5.0/layout/columns/#horizontal-alignment), justify-content-between should be what I need.
But I end up with my columns in their default position, not pushed outwards.
Basic code example:
https://codepen.io/6a0a49af-a3f9-4e78-8ccf-91d8d1b1f102/pen/QWKYJqM
I have changed your code a little to get the desired effect.
On <div class="row"> i removed some unneeded styles.
and on the <div class="col"> i changed it to col-4 to set the width.
Since bootstrap works in a frame of 12. 4 + 4 leaves 4 short so thats the space thats being filled with justify-content-between.
I also deleted your css since it was not needed.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<body class="d-flex flex-column min-vh-100">
<!-- -->
<nav class="navbar navbar-light navbar-expand-md bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="img/logo.svg" alt="">
</a>
<!-- -->
<div class="navbar-nav d-none d-md-flex">
<a class="nav-link active" aria-current="page" href="#">Home</a>
<a class="nav-link" href="#">A</a>
<a class="nav-link" href="#">B</a>
<a class="nav-link" href="#">C</a>
<a class="nav-link" href="#">D</a>
<a class="nav-link" href="#">E</a>
</div>
<!-- -->
<span>
<a href="https://twitter.com/" rel="nofollow noopener noreferrer"><i
class="fab fa-twitter mx-2 gstwitterblue"></i></a>
<a href="https://www.linkedin.com/"
rel="nofollow noopener noreferrer"><i class="fab fa-linkedin mx-2 gslinkedinblue"></i></a>
</span>
</div>
</nav>
<main class="flex-fill">
<div class="container d-none d-md-flex flex-md-row">
<div class="row justify-content-between">
<div class="col-4">
<div class="card">
<div class="ratio ratio-16x9">
<iframe src="https://www.youtube-nocookie.com/embed/wm48_VrbB4Q?rel=0" allowfullscreen></iframe>
</div>
<div class="card-body">
<p class="card-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam efficitur orci malesuada sem lacinia, vitae tempor tellus auctor. Sed elementum iaculis quam ac consectetur. Nam ac laoreet est, ut placerat arcu. Ut viverra, quam vitae gravida ornare, arcu felis elementum elit, a pulvinar lacus augue ac nisl. Nunc tincidunt ultricies luctus. Donec et congue ex. Curabitur lacinia scelerisque imperdiet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean ultricies, mauris at ultricies dapibus, urna nisl ullamcorper libero, ac dictum ex neque sed ante. Pellentesque luctus nibh libero, consequat vulputate eros porttitor vitae.</p>
</div>
</div>
</div>
<div class="col-4">
<div class="card gscustomwidth">
<div class="ratio ratio-16x9">
<iframe src="https://www.youtube-nocookie.com/embed/wm48_VrbB4Q?rel=0" allowfullscreen></iframe>
</div>
<div class="card-body">
<p class="card-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam efficitur orci malesuada sem lacinia, vitae tempor tellus auctor. Sed elementum iaculis quam ac consectetur. Nam ac laoreet est, ut placerat arcu. Ut viverra, quam vitae gravida ornare, arcu felis elementum elit, a pulvinar lacus augue ac nisl. Nunc tincidunt ultricies luctus. Donec et congue ex. Curabitur lacinia scelerisque imperdiet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean ultricies, mauris at ultricies dapibus, urna nisl ullamcorper libero, ac dictum ex neque sed ante. Pellentesque luctus nibh libero, consequat vulputate eros porttitor vitae. </p>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- Standard Footer -->
<footer class="bg-light py-3 d-none d-md-flex">
<div class="container d-flex justify-content-between">
<span class="text-dark fw-lighter">Copyright © 2020 Foobar Ltd. All rights reserved.</span>
<span class="text-dark fw-lighter"><a href="#" class="text-reset text-decoration-none">Legal
Information</a></span>
</div>
</footer>
</body>
The reason what you want doesn't happen is because you're not giving the row div a full width. From your code, add w-100 to the following div:
<div class="row row-cols-1 row-cols-md-2 justify-content-between">
I have a question regarding using scrollspy, adding a button inside the navbar, and having that button jump to its intended target section. I added a tag to be more semantic, and used a with the class of form-inline to put it next to the navbar links. The nav links work fine, but the button doesn't.
I was trying different ways to add the href to the button tag, or to substitute the tag with an tag and removing the tag, but nothing works. I was trying to find a scrollspy that used the tag, but no luck. Here's my code:
<body data-spy="scroll" data-target="#navbar">
<nav class="navbar fixed-top navbar-expand-md navbar-dark" id="navbar">
<a class="navbar-brand" href="index.html" id="navbarBrand">Unexpected Friends</a>
<!--navbar toggler is the hamburger icon that appears when in smaller screens-->
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarNav" class="collapse navbar-collapse">
<!--ml-auto moves the links to the right-->
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#ourStory">Our Story<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#gallery">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#blog">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
<form class="form-inline" id="button">
<button type="button" class="btn btn-outline-light" role="button" id="waysToHelp" href="#waysToHelp">Ways to Help</button>
</form>
</ul>
</div><!--navbarNav-->
</nav>
<section id="waysToHelp">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<img src="img/uf_10.jpg" class="img-fluid float-right ml-4">
<h1 class="text-center">Ways To Help</h1>
<p>Pretium vulputate sapien nec sagittis aliquam malesuada bibendum arcu. Lacinia quis vel eros donec ac. Arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque. Faucibus turpis in eu mi bibendum. Massa ultricies mi quis hendrerit. Bibendum ut tristique et egestas quis. Nisi vitae suscipit tellus mauris a. Lobortis feugiat vivamus at augue eget. Placerat vestibulum lectus mauris ultrices eros in cursus turpis massa. Pellentesque elit ullamcorper dignissim cras. Pellentesque sit amet porttitor eget dolor morbi non arcu risus. Tellus id interdum velit laoreet id donec ultrices tincidunt. Et egestas quis ipsum suspendisse ultrices gravida dictum fusce. Adipiscing diam donec adipiscing tristique risus. Mattis vulputate enim nulla aliquet porttitor lacus luctus accumsan tortor. Dictum sit amet justo donec enim diam. Porttitor lacus luctus accumsan tortor posuere ac ut consequat. Ultricies tristique nulla aliquet enim.<br><br>
Congue nisi vitae suscipit tellus mauris a diam maecenas sed. Risus in hendrerit gravida rutrum quisque. Tristique et egestas quis ipsum suspendisse ultrices gravida dictum. Ipsum consequat nisl vel pretium lectus quam id. Ut sem viverra aliquet eget sit amet. Sed euismod nisi porta lorem mollis aliquam ut porttitor leo. Semper quis lectus nulla at volutpat diam ut. Risus at ultrices mi tempus. Eu feugiat pretium nibh ipsum consequat nisl. Eu scelerisque felis imperdiet proin fermentum. Lorem sed risus ultricies tristique nulla aliquet enim tortor at. Sit amet mauris commodo quis imperdiet massa. Urna porttitor rhoncus dolor purus. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper velit.</p>
</div><!--column-->
</div><!--row-->
</div><!--container-->
</section>
</body>
Kindly read the documentation properly :
The data-spy attribute will be on the div outside the the nav with a data-target to indicate the selected nav
It has to be a tag because of href. It converts hash url,which is also accessible when entered in the url directly. That is the fundamentals of how it works.
You can do it like -
<button type="button" class="btn btn-outline-light" role="button"
id="waysToHelp">ways to help</button>
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#ourStory">Our Story<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#gallery">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#blog">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#waysToHelp">ways to help</a>
</li>
<form class="form-inline" id="button">
<button type="button" class="btn btn-outline-light" role="button" id="waysToHelp">ways to help</button>
</form>
</ul>
Example - https://jsfiddle.net/cvwrfau0/
I would my Bootstrap 4 webpage to have max width of 960px, including the top navbar. I have tried to enclose everything within the body with a div with max-width set. However, then this "body div" is left aligned. I would like the "body div" to be in the middle with whitespace around when the view port width is larger than 960px.
How would this be best achieved?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Max body width</title>
</head>
<body>
<div id= "body-div">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<button class="btn btn-primary" onclick = "toggle();">Toggle max-width</button>
<script type="text/javascript">
function toggle(){
var div = $('#body-div');
if(div.css('max-width') !== "960px"){
div.css('max-width', '960px');
}
else{
div.css('max-width', '');
}
}
</script>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tristique, dui vitae pharetra sollicitudin, felis metus dignissim sapien, at sodales libero massa condimentum dui. Maecenas sem diam, porttitor eget lacus at, vulputate facilisis leo. Nulla ut nisi sem. Nunc sapien neque, maximus fermentum mi ut, dapibus fermentum nunc. Phasellus dignissim laoreet dictum. </p><p>Sed egestas sem ut viverra dignissim. Sed blandit rhoncus turpis, ac feugiat tortor venenatis id. Ut ac fermentum enim. Integer vitae malesuada sem, nec ultrices mi. Fusce mattis ante vel lacinia convallis. Integer posuere nisi sit amet augue ultrices, quis elementum ante consequat. Sed et ornare lectus. Phasellus rutrum luctus ipsum non vestibulum. Etiam efficitur nulla at erat blandit, sit amet tristique ante gravida. Proin tortor purus, eleifend vel metus hendrerit, tincidunt tristique sapien. Donec lacinia aliquam lacus, in efficitur velit facilisis ac.</p>
</div>
</div>
</body>
</html>
https://jsbin.com/towapid/1/edit?output
To center align a div like that, all you need to do is add a margin:auto; to the #body-div. The margin is calculated based on the width of the div.
So in your css, you just need to add this:
#body-div{
margin:auto;
}
Here's a way to do it in Bootstrap 4:
Note: this solution doesn't use your body-div or any other hacks because there's no need for any hacks. This can all be done with native Bootstrap classes alone.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row no-gutters">
<div class="col col-lg-10 offset-lg-1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tristique, dui vitae pharetra sollicitudin, felis metus dignissim sapien, at sodales libero massa condimentum dui. Maecenas sem diam, porttitor eget lacus at, vulputate facilisis leo. Nulla ut nisi sem. Nunc sapien neque, maximus fermentum mi ut, dapibus fermentum nunc. Phasellus dignissim laoreet dictum. </p>
<p>Sed egestas sem ut viverra dignissim. Sed blandit rhoncus turpis, ac feugiat tortor venenatis id. Ut ac fermentum enim. Integer vitae malesuada sem, nec ultrices mi. Fusce mattis ante vel lacinia convallis. Integer posuere nisi sit amet augue ultrices, quis elementum ante consequat. Sed et ornare lectus. Phasellus rutrum luctus ipsum non vestibulum. Etiam efficitur nulla at erat blandit, sit amet tristique ante gravida. Proin tortor purus, eleifend vel metus hendrerit, tincidunt tristique sapien. Donec lacinia aliquam lacus, in efficitur velit facilisis ac.</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
Here's an alternative version (you might like this better):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col mx-5">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tristique, dui vitae pharetra sollicitudin, felis metus dignissim sapien, at sodales libero massa condimentum dui. Maecenas sem diam, porttitor eget lacus at, vulputate facilisis leo. Nulla ut nisi sem. Nunc sapien neque, maximus fermentum mi ut, dapibus fermentum nunc. Phasellus dignissim laoreet dictum. </p>
<p>Sed egestas sem ut viverra dignissim. Sed blandit rhoncus turpis, ac feugiat tortor venenatis id. Ut ac fermentum enim. Integer vitae malesuada sem, nec ultrices mi. Fusce mattis ante vel lacinia convallis. Integer posuere nisi sit amet augue ultrices, quis elementum ante consequat. Sed et ornare lectus. Phasellus rutrum luctus ipsum non vestibulum. Etiam efficitur nulla at erat blandit, sit amet tristique ante gravida. Proin tortor purus, eleifend vel metus hendrerit, tincidunt tristique sapien. Donec lacinia aliquam lacus, in efficitur velit facilisis ac.</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>