Bootstrap container, grid rows width and a padding issue - html

I'm creating my first bootstrap frontend, and I'm experiencing some issues which I'm not able to solve:
The row expanding to the whole width of the container, the max column width (12 units) will not extend to this width:
Further on, why is within the container writing over the padding:
Any hints appreciated!
I already tried to use container-fluid class, but the row seems not to get the max width.
Whole HTML:
<!DOCTYPE html>
<html>
<head>
<title>Snoo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="app.css">
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Snoo!</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">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Reddit!</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="container">
<div class="row">
<div class="col_xl-12">
<div id="content">
<h1>Snoo!</h1>
<hr>
<h3>A chatbot based on a million reddit comments, quiet salty!</h3>
<button class="btn btn-primary btn-lg">Learn more!</button>
</div>
</div>
</div>
</div>
</body>
<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.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</html>
css:
#content {
text-align: center;
padding-top: 25%
}

your class name wrong col_xl-12 to change class name col-xl-12
https://v4-alpha.getbootstrap.com/layout/grid/

I'm seeing a typo, try to change:
col_xl-12 to -> col-xl-12

Remove container from your coding. Then the row will have full width
your class should be col-*-*, but you used col_xl-12
The HTML Structure Will be:
<div class="row">
<div class="/* Container or Container-fluid or Col-* */">
</div>
</div>

Related

Why is flex box not working even in chrome?

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
</head>
<style type="text/css" href="style.css"></style>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Magic Notes</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<div class="container my-3 mx-10" style="max-width:70vw;margin:0 auto;">
<h1>Welcome To Magic Notes</h1>
<div class="card">
<div class="card-body">
<h5 class="card-title">Add a Note</h5>
<textarea class="form-control" id="addTxt" style="height: 100px"></textarea>
<button class="btn btn-primary" style="margin-top:1em;"" id= " addBtn">Add Note</button>
</div>
</div>
<hr>
<h1>Your Notes</h1>
<hr>
<div class="container">
<div>HI</div>
<div>HI</div>
<div>HI</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.2/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.min.js"
integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT"
crossorigin="anonymous"></script>
<!-- <script src="app.js"></script> -->
</body>
In the code below I have used very little CSS just to experiment with some things(I will be adding the CSS file below). However, My target class container is not showing stuff horizontally even after changing it to flex. I have used some bootstrap classes and am very new to this stuff what is the possible reason for this incomprehensible behavior.
The CSS code:
*{
margin:0;
padding: 0;
box-sizing: border-box;}
.container{
display:flex;
flex-direction:row;
flex: 1;}
<style type="text/css" href="style.css"></style>
This is your problem. When connecting your CSS file, you need to use a link tag instead of a style tag. Try this:
<link rel="stylesheet" href="style.css">

Bootstrap 4 Sticky footer adding a lot of padding

I am trying to create a website with Bootstrap 4 on Apache (Ubuntu Linux), the footer is sticky as expected, but if only have a small amount of information on the page I have to scroll past a lot of white space to see the footer.
I don't understand how to get the footer to behave more like the demo on the website, the only difference is that I have a navbar as well as a footer.
Advice would be greatly welcomed please, I am pulling my hair out over this.
Minimum working code
<!doctype html>
<html lang="en" class='h-100'>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" >
<style>
.footer
{
margin: 0;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 22px;
background-color: #13294a;
}
body
{
min-height: 75rem;
padding-top: 5rem;
}
</style>
<title>Secure Shed Project</title>
</head>
<body class="d-flex flex-column h-100">
<header role="banner">
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample04" aria-controls="navbarsExample04" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample04">
<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>
</ul>
</div>
</nav>
</header>
<main role="main" class="flex-shrink-0 pb-2">
<div class="container">
<h1>Website coming soon</h1>
</div>
</main>
<footer class="footer mt-auto">
<div class="container-fluid text-center text-md-left text-white">
<div class="text-center">
<p class="copyright m-0">© 2020 Copyright A.N.Other</p>
</div>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>
The problem in your code is this min-height on the body element. First, you will remove that. Then you will see that your footer is not sticky anymore. There are many solutions for that and I will recommend you this one:
Instead of using 75rem, you should use this min-height: 100vh;.
The thing is you are forcing a minimum height for your body
Remove this line in your style:
min-height: 75rem;

Bootstrap - Positioning within the navigation bar

this code shows my attempt at creating a navigation bar but I can find a way to position everything correctly. I have tried using col-md-3 for several elements but yet I am not able to position them. I was wondering if you would be able to put the search bar in the middle with the links aligned to the right.
What I would like to acheive
The Faulty code is below.
Thank you!
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<title>NavBar</title>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<ul class="navbar-nav ">
<li class="nav-item">
Home
</li>
<li class="nav-item">
<form class="mx-auto order-0">
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary" type="button" id="button-addon1">Button</button>
</div>
<input type="text" class="form-control" placeholder="" aria-label="Example text with button addon"
aria-describedby="button-addon1">
</li>
<li class="nav-item">
Link
</li>
<li class="nav-item">
Link2
</li>
</form>
</li>
</ul>
</body>
</html>
I would recommend reviewing Bootstrap's excellent documentation on their Navbar component as it will better equip you to truly personalize your Bootstrap layout. It wouldn't hurt to also review their utility documentation as several utility classes are well-suited for achieving your layout.
There are several ways you might go about achieving your desired layout, below is how I would approach it while still keeping the built-in Navbar functionality:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand pr-lg-5" href="#">Shopping District 1</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">
<form class="flex-fill my-2 my-lg-0 mx-lg-4">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search" aria-label="Search">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="button-addon1">Button</button>
</div>
</div>
</form>
<ul class="navbar-nav mr-auto ml-lg-5">
<li class="nav-item">Link</li>
<li class="nav-item">Link2</li>
</ul>
</div>
</nav>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
In the above code sample I've included Bootstrap's class requirements to make your navigational menu collapse on smaller screens, along with the additional components to allow the toggle behavior.
I've also separated the .navbar-brand, form and .navbar-nav items as there is no reason to force them into the same list; Navbar uses Flexbox for its layout so each child element will already align itself accordingly.
For more fine-tuned structure I've declared a couple of margin and padding utility classes (pr-lg-*, mx-lg-* etc) to help create the spacing your illustration suggests you were looking for. By using the -lg- variant these will only apply on larger devices.
So, I was able to modify it to give somewhat of a result similar to what I was looking for!
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="navbar.css">
<title>NavBar</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<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;">
<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">
</form>
</div>
</ul>
<ul class="navbar-nav ml-auto ">
<li class="nav-item" style="padding-right: 120px;">
<a id="one" href="" class="nav-link">Link</a>
</li>
<li class="nav-item mr-5">
<a id="two" href="" class="nav-link">Link2</a>
</li>
</li>
</ul>
</body>
</html>

CSS background-image code does not show up image

Hi I am trying to build a small website using HTML, bootstrap and css (I am a newbie). However in the css background-image does not work. I have checked the path and the file format and it is fine (infact am using brackets ide and it shows a thumbnail of the image when I hover the mouse over the path). Here is my code:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="styles.css">
<meta charset="UTF-8">
<title>My First Web Project</title>
</head>
<body>
<!-- NAVIGATION HEADER -->
<div class="header" id="topheader">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container text-uppercase p-2">
<a class="navbar-brand" href="#">MY WEBSITE</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 ml-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="#">ABOUT US</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">SERVICES</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">CONTACT US</a> </li>
</ul>
</div>
</div>
</nav>
<!-- BODY SECTION -->
<section class="header-section">
<div class="center-div">
<h1 class="font-weight-bold">Lorem ipsum dolor sit</h1>
<p>Hello we are developing this site</p>
</div>
<div class="header-buttons">
EXPLORE
CONTACT
</div>
</section>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
CSS:
*{padding:0; margin:0; box-sizing: border-box;}
.header
{
background: url('../images/background.jpg');
}
Please help!
Have you checked your browser DevTools (right click on page and hit Inspect or CTRL+SHIFT+I in Chrome) to see if there is anything overriding your CSS?
It could also be the URL needs to change.. try changing it to the following:
background-image: url('images/background.jpg');
If you've tried to put in a URL directly from the web as mentioned and it still didn't work, then I suggest checking out if something is overriding the code, maybe declare !important in your CSS line to see if that makes a difference.
I've also experienced a few cases where the image was a JPEG and had to change it from JPG in the CSS. Check your browser Dev Tools to see what's going on. Hope this helps!
Change your CSS code to this and try it out:
.header
{
background: url('images/background.jpg');
}
you should give width and height to div that has a background image with background-size: cover
.header
{
background: url('images/background.jpg');
height:auto;
width:100%;
background-size:contain
}

"connect" dropdown box and input form in bootstrap

So I have the HTML below. If you click on the search (in the top right), you'll see a dropdown box appear in the top left. I want to "connect" these, so that the dropdown box is properly below the search box and the whole thing behaves like how a button connected to a dropdown would.
I'm not really a web guy and I don't really "know" Bootstrap (this is my first time using it) so please bear that in mind!
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" href="/static/css/style.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js"></script>
<script src="https://use.fontawesome.com/6e0448e881.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<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">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0" method="get">
<input name="q" id="qbox" data-toggle="dropdown" type="search" class="form-control" placeholder="Search" autofocus="autofocus" autocomplete="off"/>
<div id="search_results" class="dropdown-menu" role="menu">
<div>a</div>
<div>b</div>
<div>c</div>
</div>
</form>
</div>
</nav>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</body>
</html>
You have to override the class applied to the dropdown menu, which is called .dropdown-menu.
In your css:
.dropdown-menu{
left: initial;
}
Depending on how your css structure looks you may call this rule with an !important behind the inital statement.