bootstrap padding around jumbotrons and navbar? - html

I am trying to learn the basics of bootstrap for responsive websites. When I put elements into the "row" class then there is not any margins or padding to the elements and no free space, but with elements such as jumbotron and the navbar then there seems to be padding i cant get rid of on the left and right side.
Any help would be appreciated.
<nav class="navbar navbar-expand-lg navbar-expand-md">
<a class="navbar-brand" href="#">lorem ipsum</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">about</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">contact</a>
</li>
</ul>
</div>
</nav>
<div class="jumbotron jumbotron-fluid" style="background-image:url(images/hero-image.jpg)">
<div class="container-fluid">
<h1 class="display-4">lorem ipsum</h1>
<p class="lead">lorem ipsum</p>
</div>
</div>
<div class="row newsletter">
<p class="col-lg-6 col-md-6 col-sm-6 col-xs-12">subscribe to our newsletter</p>
<form class="col-lg-6 col-md-6 col-sm-6 col-xs-12 newsForm">
<input type="email" placeholder="enter your email..." class="box">
<button type="submit" class="button">></button>
</form>
</div>

Boostrap by default apply padding on the navbar you can remove right and left padding by simply doing that:
.navbar.custom-navbar {
padding-left: 0rem !important;
padding-right: 0rem !important;
}
apply custom-navbar class on <nav> element.
To remove jumbotron left and right padding remove <div class="container-fluid"> which is inside jumbotron like that:
<div class="jumbotron jumbotron-fluid" style="background-image:url(images/hero-image.jpg)">
<h1 class="display-4">odtom.com</h1>
<p class="lead">a site showcasing everything odt.</p>
</div>
Also to remove horizontal scroll from the page place the row inside conatiner-fluid.
<div class="container-fluid">
<div class="row newsletter">
<p class="col-lg-6 col-md-6 col-sm-6 col-xs-12">subscribe to our newsletter</p>
<form class="col-lg-6 col-md-6 col-sm-6 col-xs-12 newsForm">
<input type="email" placeholder="enter your email..." class="box">
<button type="submit" class="button">></button>
</form>
</div>
</div>

I'm not sure if this will answer your question, but the left and right paddings in the jumbotron element are coming from the ".container-fluid" class. It seems that you are targeting the container with the ".jumbotron-fluid" class, which is the one currently set to padding-left and right to 0px.
Just target this class to remove or amend the paddings if that's what you need.
.container-fluid {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}

Related

How can i put the <hr> closer with the content in header?

I want to put the <hr closer to the content in the header.
I try to use position-absolute but the disappears.
This is my first project with bootstrap.
<!-- Bootstrap-5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!--Body -->
<header class="header row">
<div class="d-flex justify-content-between">
<div id="logo" class="pb-2 ps-2 pe-0 col-2">
<img class="float-start py-2 ps-2 pe-2" src="assets/img/unknown.png">
<a href="#" class="sidebar-toggler flex-shrink-0" id="menu-toggle">
<i class="fa-solid fa-angle-left py-4 pe-2"></i>
</a>
</div>
<div class="col-10 row">
<h2 class="col-9 px-0 text-primary d-flex align-items-center">CHƯƠNG TRÌNH REBATE</h2>
<div class="col-3 px-0">
<div class="float-end d-flex justify-content-between">
<i class="fa fa-bell me-lg-2 d-flex align-items-center"></i>
<div class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
<img class="rounded-circle " src="assets/img/aTu.png" alt="" style="width: 40px; height: 40px;">
<span class="d-none d-lg-inline-flex text-primary">TuNTC23</span>
</a>
<div class="dropdown-menu bg-transparent border-0">
My Profile
Settings
Log Out
</div>
</div>
</div>
</div>
</div>
</div>
<hr style="height:1px;color:#1968B2;">
</header>
<hr style="height:1px;color:#1968B2; margin-top: -4px">
you can adjust the margin top according to your usage
I suggest you do not use the <hr> tag but a new css class or ::after to do that.
<header class="header row hr-bottom">
.hr-bottom {
border-bottom: 1px solid black;
}
OR
.hr-bottom::after {
border-bottom: 1px solid black;
}
The fastest way add class to hr for example bar
<hr class="bar" style="height:1px;color:#1968B2;">
and in CSS add class:
.bar {
transform: translateY(-10px);
}
Values up to you It may take px or procentage

How do I add elements below my navbar using bootstrap?

I have attempted to place elements below the navigation bar I created, however, it keeps distorting the NavBar. I have used bootstrap so I was hoping I could add a form underneath the code below, it's honestly just an issue of spacing and I have read the bootstrap documentation yet I still find it difficult. The code below is fine but could someone try to add a form or some kind of input box below it, please. Thank you, guys.
<! this is where the nav bar starts to be made>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark navbar-fixed-top">
<!this is the length and theme of the navigation bar is set>
<ul class="navbar-nav pl-2">
<! i've added padding left as i need to space out items in the nav bar well>
<li class="nav-item">
District 1
</li>
<! the home button is the name of the store>
<div class="mx-auto">
<form class="mx-auto order-0 col px-md-5">
<! this is the creation of the search bar>
<div class="mx-auto input-group mt-1">
<div class="input-group-prepend" style="margin-left: 380px; margin-top: 5px;">
<button class="btn btn-outline-secondary" type="button" id="button-addon1"><img
src="https://img.icons8.com/pastel-glyph/2x/search--v2.png" alt="Search" class="mx-auto"
width="20" height="20"></button>
<! this is the image for the search button function>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with button addon"
aria-describedby="button-addon1" style="margin-top: 5px;">
</form>
</div>
</ul>
<ul class="navbar-nav ml-auto ">
<li class="nav-item" style="padding-right: 120px;">
<a id="one" href="SignIn.php" class="nav-link" style="font-size: 15px;">Hello, <br> Sign in!</a>
</li>
<! this is the sign in button>
<li class="nav-item mr-5">
<a id="two" href="SignIn.php" class="nav-link"><img
src="https://img.icons8.com/pastel-glyph/2x/shopping-cart--v2.png" alt="Cart" width="40"
height="40"></a>
</li>
<! this is the shopping cart button>
</li>
</ul>
Here are examples of input fields and forms below your nav, is this what you are looking for?
Please see comments in the code to understand better.
Comment if you have more questions.
.flex-c-row {
display:flex;
align-items:center;
margin:25px;
} /* setting the display to flex, which is by default 'row' with items side-by-side; give it align-items:center to align items vertically in the available space */
.flex-c-row > * {
margin:50px; /* space all direct child elements of the outer container by 50px on all sides top bottom right left */
}
.flex-c-col, form {
display:flex;flex-direction:column; /* same as above but set the flexbox direction of elements as a COLUMN so vertical */
}
input {
cursor:pointer;
}
form > * {
margin:25px 0;
}
<nav class="navbar navbar-expand-lg navbar-dark bg-dark navbar-fixed-top">
<ul class="navbar-nav pl-2">
<li class="nav-item">
District 1
</li>
<div class="mx-auto">
<form class="mx-auto order-0 col px-md-5">
<div class="mx-auto input-group mt-1">
<div class="input-group-prepend" style="margin-left: 380px; margin-top: 5px;">
<button class="btn btn-outline-secondary" type="button" id="button-addon1"><img
src="https://img.icons8.com/pastel-glyph/2x/search--v2.png" alt="Search" class="mx-auto"
width="20" height="20"></button>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with button addon"
aria-describedby="button-addon1" style="margin-top: 5px;">
</div>
</form>
</ul>
<ul class="navbar-nav ml-auto ">
<li class="nav-item" style="padding-right: 120px;">
<a id="one" href="SignIn.php" class="nav-link" style="font-size: 15px;">Hello, <br> Sign in!</a>
</li>
<li class="nav-item mr-5">
<a id="two" href="SignIn.php" class="nav-link"><img
src="https://img.icons8.com/pastel-glyph/2x/shopping-cart--v2.png" alt="Cart" width="40"
height="40"></a>
</li>
</ul>
</nav>
<!-- so here we simply add the container div for our 3 input examples -->
<div class="flex-c-row">
<div class="flex-c-col">
<span>This is an input field</span>
<input type="datetime-local">
</div>
<div class="">
<form>
<h3>This is a basic form.</h3>
<input>
<input>
<textarea cols="15" rows="25"></textarea>
</div>
<div class="flex-c-col">
<span>This is a color input field.</span>
<input type="color">
</div>
<div>
Codepen to play with:
https://codepen.io/larrytherabbit/pen/pobjKLw

Bootstrap 4: Footer not at bottom

I know this question was probably asked some hundred times, but sadly no answer that I found in here really helped me.
I tried these answers for example:
Bootstrap footer not at bottom
Flushing footer to bottom of the page, twitter bootstrap
Height not 100% on Container Fluid even though html and body are
But I still have the problem that when my page content is to "small" and doesn't fill out the whole height of the body/page container the footer just floats somewhere above the end of the browser window.
This is the code for my footer:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<footer class="d-flex justify-content-center">
<div class="d-flex justify-content-between col-md-8 col-md-offset-2 mb-3 mt-5">
<div class="align-left">
<a class="font-weight-bold small kf-blue kf-links" href="#">Link1</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link2</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link3</a>
</div>
<div class="align-right small">
Crafted with Love by <a class="font-weight-bold kf-blue kf-links" href="#" target="_blank">Me</a>
</div>
</div>
</footer>
I'm using Bootstrap 4.1 and Chrome, here's also a codepen to my site:
https://codepen.io/anon/pen/oMZVxq
Note: you have to use the sidebar view in codepen to actually see that the footer is not at the bottom, as the view size in codepen is so small that it looks correctly.
You can use built-in bootstrap class to achieve this.
What you need is the container to be a column flex container . class to use are : d-flex flex-column
To set the container to height:100% you can apply the class h-100to html, body and the container or add to the container style height:100vh;
For the footer, a margin-top:auto will do, the class to use is : mt-auto;
example below to run in full page mode
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<html class="h-100">
<body class="h-100">
<!-- Page Container -->
<div id="page-container" class="container-fluid pr-0 pl-0 h-100 d-flex flex-column">
<!-- Header -->
<nav class="navbar navbar-expand-lg navbar-light bg-light pt-3 pb-3 d-flex justify-content-center">
<div class="col-md-8 col-lg-8 col-sm-12 col-xs-12 d-flex justify-content-between">
<div class="d-flex justify-content-start align-items-center">
<a href="/" class="kf-links">
<span class="h5">
<i class="fas fa-paper-plane"></i>
<span class="h4 font-weight-bold kf-dark">
MyPage
</span>
</span>
</a>
</div>
<!-- Main Header Navigation -->
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item">
Link1
</li>
<li class="nav-item">
Link2
</li>
<li class="nav-item">
Link3
</li>
</ul>
</div>
<!-- END Main Header Navigation -->
</div>
</nav>
<!-- END Header -->
<!-- Main Container -->
<div style="background:#5c90d2">
<div class="col-md-12 text-center pt-5 pb-5">
<div class="pt-5 pb-5">
<h1>
<span class="main-text">
Login
</span>
</h1>
<p class="lead"><span class="main-text">
Login Now!
</span></p>
</div>
</div>
</div>
<!-- Content -->
<div class="d-flex justify-content-center fadeIn">
<div class="col-md-8 col-xs-12">
<div class="d-flex justify-content-center">
<div class="col-md-6 pt-5 pb-5 pr-0 pl-0">
<form class="form-horizontal" method="post">
<div class="form-group">
<div class="col-xs-12">
<div class="">
<label for="id_username">E-Mail</label>
<input id="id_username" class="form-control" maxlength="254" name="username" value="" type="text" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<div class="">
<label for="id_password">Password</label>
<input id="id_password" class="form-control" name="password" type="password" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<small class="float-right">
Forgot Password?
</small>
</div>
</div>
<div class="form-group mt-5">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 pl-0">
<button class="btn btn-sm btn-block btn-primary" type="submit">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- END Content -->
<!-- END Main Container -->
<!-- Footer -->
<footer class="d-flex justify-content-center mt-auto">
<div class="d-flex justify-content-between col-md-8 col-md-offset-2 mb-3 mt-5">
<!-- Copyright Info -->
<div class="align-left">
<a class="font-weight-bold small kf-blue kf-links" href="#">Link1</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link2</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link3</a>
</div>
<div class="align-right small">
Crafted with Love by <a class="font-weight-bold kf-blue kf-links" href="#" target="_blank">Me</a>
</div>
<!-- END Copyright Info -->
</div>
</footer>
<!-- END Footer -->
</div>
<!-- END Page Container -->
</body>
</html>
codepen updated https://codepen.io/anon/pen/PBpgNN
reminder for boostrap classes https://getbootstrap.com/docs/4.5/utilities/flex/ about sizing see https://getbootstrap.com/docs/4.5/utilities/sizing/
If you want a fixed footer, just add the class fixed-bottom to the footer tag like shown below.
<footer class="fixed-bottom bg-dark">
<div class="text-center">
<p>Footer</p>
</div>
</footer>
First add display: flex; and flex-direction: column; to #page-container.
Now you have "set the stage" for aligning the footer to the bottom. Set its margin-top to auto (by adding the class mt-auto) and you are done;
<div class="d-flex justify-content-center mt-auto">
Content here
</div>
See this codepen.
So this helped me - if someone is still looking for an answer:
on your <HTML>, <body> and your container div add a class h-100 and your footer will stay on the bottom.
Important
One thing I did to remove the extra height is that on my container div I changed the h-100 styling to height: calc(100% - 200px) !important; (where -200px was the height of my navigation and footer)
if you are not using the bootstrap, here is the styling .h-100{height:100% !important}

Bootstrap 4 Buttons Align-Middle of page

I am quite new to Bootstrap 4. I can't seem to get my 3 buttons centered in the middle of the page. I am using Bootstrap-4. I feel it is something simple I am missing. Also is there a way to extend the buttons a little more outside the text, would I use padding for that? Thanks!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-
beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link rel="stylesheet" href="Sanchez_Bootstrap_index.css">
</style>
<title>Sanchez</title>
</head>
<body>
<!--NAVBAR-->
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">Sanchez</a>
<!--Toggle Button-->
<button class="navbar-toggler"
data-toggle="collapse"
data-target="#navbar"aria-controls="navbarTogglerDemo01" aria-
expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span></button>
<!--Navbar links-->
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" a href="Sanchez_Bootstrap_about.html">About</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="Sanchez_bootstrap_portfolio.html">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link disabled"
href="Sanchez_bootstrap_contact.html">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<div id="content">
<div class="container text-center">
<div class="row">
<div class="col-lg-12">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_about.html">Web
Developer</a>
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_portfolio.html">Portfolio</a>
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_contact.html">Contact</a>
</<div>
</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.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-
beta/js/bootstrap.min.js" integrity="sha384-
h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
crossorigin="anonymous"></script>
</body>
</html>
CSS
body{
background-image: url('images/background3.jpeg');
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-color: #464646;
color: white;
}
#media only screen and (max-width: 767px) {
body {
background-image: url('images/background3.jpeg');
}
html{
height: 100%;
}
#content{
align-items: center;
text-align: center;
}
Please share a screenshot of the web page and the problem to explain it better. Also, there are few points I would like to bring to attention.
Why are you not including jquery.min.js in the head when bootstrap nav depends on it to work? It should be before bootstrap src
You have a typo </<div> please check your code
What do mean by centering the buttons?
You mean centering side by side? like this: or you mean centering as in stacked?
For the former case, I used this code:
<div id="content">
<div class="container text-center" style = "vertical-align:middle;
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12" >
<div class="row" style = "line-height: 20em;">
<div class="col-lg-4 col-sm-4 col-xs-4 col-md-4" style = "vertical-align: middle;">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_about.html" >Web
Developer</a>
</div>
<div class="col-lg-4 col-sm-4 col-xs-4 col-md-4" style = "vertical-align: middle;">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_portfolio.html" >Portfolio</a>
</div>
<div class="col-lg-4 col-sm-4 col-xs-4 col-md-4" style = "vertical-align: middle;">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_contact.html" >Contact</a>
</div>
</div>
</div>
</div>
</div>
For the latter, I used:
<div id="content">
<div class="container text-center">
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<div class="row">
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_about.html" >Web
Developer</a>
</div>
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_portfolio.html" >Portfolio</a>
</div>
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<a class="btn btn-dark btn-lg" a
href="Sanchez_Bootstrap_contact.html" >Contact</a>
</div>
</div>
</div>
</div>
</div>
For bootstrap divs, think about dividing divs in to subdivs and then give them elements. For col-lg-12, we have 12 blocks. If you want three inner elements, divide 12 by 3 which is 4. So wrap each of the three elements in col-lg-4. The width would be: 100/3 = 33.33% Similarly, if you want three elements with each 100% wide, wrap the three in each col-lg-12 div and each will have width of 100/1 = 100%
Its better to have a habit of specifying lg, sm, xs and md when you are writing the code itself and use a mobile first development methodology to think how its gonna look on each mobile devices right away. i.e. specify col-lg-12 col-sm-12 col-xs-12 col-md-12 in each div.
Note: I used your code in an ongoing project, so few css have been inherited form my code, like font width, button coloring, background etc

Responsive Columns Collapsing Too Soon

I am using Bootstrap 3 and I want 3 columns to remain responsive throughout different sized (lg -> xs). I am trying to use the grid system with col-xx-4 for each size, but as soon as I get to <992px the column start collapsing on each other.
example can be see here
I want the red, green, and blue columns within the gray box to be always equal 3 columns. Maybe in xs they can collapse, but at least until 768px viewport they should be 3 columns next to each other.
I used col-xs-4 that should keep things horizontal at all times.
excerpt of some of my code:
<div class="dash-bg">
<div class="" style="background: #d5d5d5; height: 500px;">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4" style="background: red; height: 30px;">
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4" style="background: blue; height: 30px;">
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4" style="background: green; height: 30px;">
</div>
</div>
</div>
Well, you should add class "Row" to Header..
Code snippet here :
<div class="header row">
<div class="logo pull-left" style="background:black;">
</div>
<div class="pull-right" style="margin-top: 6.2%;">
<ul class="nav nav-pills">
<li>COMPANY<span class="arrow-down glyphicon glyphicon-play"></span></li>
<li>FAQ</li>
</ul>
</div>
<!--
<div class="navbar-header dropdown">
<button class="navbar-toggle" data-target=".navbar-collapse" data-toggle="dropdown" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="/page.html"></a>
</div>
-->
</div>
Defining DOM element row will make sure that the maximum height of any child DOM element will be the maximum height of the parent DOM.
Sounds like you need to use a media query OR make your dash-bg {min-width:993px;}
I have something similar and i use
<div class="row">
<div class="col-md-4">Something</div>
<div class="col-md-4">Something</div>
<div class="col-md-4">Something</div>
</div>
You can check an example here