Hello I'm using kind of standard bootstrap code from tutorials and such trying to get my head around bootstrap. However I've searched everywhere and I can't find code that actually solves my problem.
<header>
<!-- Toggler/collapsible Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark navbar-default fixed-top">
<div class="container">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
</div>
</nav>
</header>
<section id="home" class="carousel slide" data-ride="carousel">
<div id="container">
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#home" data-slide-to="0" class="active"></li>
<li data-target="#home" data-slide-to="1"></li>
<li data-target="#home" data-slide-to="2"></li>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="la.jpg" alt="Los Angeles">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>We had such a great time in LA!</p>
</div>
</div>
<div class="carousel-item">
<img src="chicago.jpg" alt="Chicago">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
</div>
<div class="carousel-item">
<img src="ny.jpg" alt="New York">
<div class="carousel-caption">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#home" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#home" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</section>
This is a navbar with a standard carousel under.
The problem is I want a sticky navbar that always stays on top.
But as it is now it overlaps the carousel so I would like it to start below the navbar. I've tried adding padding-top and such with no lucky Ive also tried the codes that handle smaller resolution and ended up with big white spaces in between no matter how much padding I added. My navbar seems to be 56px in height.
I'm guessing this is easy if you have soem basic knowledge about Bootstrap.
There is also other questions I mark these with number if you are able to help.
Home link doesnt go all the way to the top. Is there anyway to fix this.
How do you handle so that multiple pages doesnt show up on one page. Is there a way to make f.ex have a min-height of display height?
add this to your css or download bootstrap.min.css from https://bootswatch.com/
1. for sticky navbar
.fixed-top {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1030;
}
2.
<header id="top">
<a class="nav-link" href="#top">Home</a>
#navbar {
overflow: hidden;
background-color: #333;
}
#navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px;
text-decoration: none;
}
.content {
padding: 16px;
}
.sticky {
position: fixed;
top: 0;
width: 100%
}
.sticky + .content {
padding-top: 60px;
}
add new class in section for identification not-navbar
<section id="home" class="carousel slide not-navbar" data-ride="carousel"> </section>
add CSS for not-navbar class, default height Bootstrap navbar is 50px (without padding) and 70px (with padding). translateY(56px) because your navbar height is 56px.
.not-navbar {
transform: translateY(56px);
}
So, your content will be exactly below navbar, without overlap with your top content.
Related
I'm looking to have the 'non-collapsed' navbar menu overlayed on the `. basically a navigation overtop a large main image. However, when the menu is collapsed, I want it to push all the content from the top of the page. Where the default nav pushes the content from below the navbar.
html
Navbar
<div class="collapse navbar-collapse" id="navbarToggleExternalContent">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div id="bg-img" class="container-fluid px-0">
<div id="main-wrap" class="container">
</div>
</div>
css
#bg-img {
background-color: red;
min-height: 75vh;
width: 100%;
}
i want navbar Bootstrap 4 over all element,
now can over all element but when use Carousel in Body navbar-collapse
NAVBAR - HTML
<nav class="navbar navbar-expand-md navbar-dark bg-main">
<a class="navbar-brand d-md-none order-1" style="font-size:26px;line-height:0" href="#">【K】【S】【J】</a>
<button class="navbar-toggler" type="button">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex flex-column flex-row flex-lg-row flex-xl-row justify-content-lg-end bg-main p-3 p-lg-0 mt-5 mt-lg-0 mobileMenu" id="navbarSupportedContent">
<ul class="navbar-nav d-flex d-flex justify-content-around text-right px-3" dir="rtl">
<li class="nav-item active" style="">
<a class="nav-link" href="#">
<span>Home</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span>Anout</span>
</a>
</li>
</ul>
</div>
</nav>
NAVBAR - CSS
/* Mobile Menu */
#media only screen and (max-width: 992px) {
.mobileMenu {
position: fixed;
top: 70px;
bottom: 0;
right: -100rem;
margin: auto;
transform: translateX(-100);
transition: all ease .25s;
}
.open-nav {
right:0;
}
.body-blur{
filter: blur(5px)
}
}
Carousel - HTML
<div id="mainCarousel" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
<li data-target="#demo" data-slide-to="3"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="~/Content/documents/shared/dev1.jpg" alt="Los Angeles">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>We had such a great time in LA!</p>
</div>
</div>
<div class="carousel-item">
<img src="~/Content/documents/shared/dev2.jpg" alt="Chicago">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
</div>
<div class="carousel-item">
<img src="~/Content/documents/shared/dev7.jpg" alt="New York">
<div class="carousel-caption">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</div>
</div>
<div class="carousel-item">
<img src="~/Content/documents/shared/dev6.jpg" alt="New York">
<div class="carousel-caption">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</div>
</div>
</div>
#*<a class="carousel-control-prev shadow-lg" href="#mainCarousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next shadow-lg" href="#mainCarousel" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>*#
</div>
Carousel - CSS
.carousel-inner img {
width: 100%;
height: 600px;
}
Open Nav
$('.navbar-toggler').on('click',function () {
$('.mobileMenu').toggleClass('open-nav');
$('.app-content').toggleClass('body-blur');
});
Use Bootstrap 4, ASP.NET MVC5
Open Nav and
Close Nav
When Remove Carousel code nav bar work and open success
Remove Carousel
if use any div not problem and work but when use Carousel nav hidden back Carousel.
**Thanks for all suggestions **
Try it:
.mobileMenu {
z-index: 9999999;
}
Im trying to learn Bootstrap and get a little bit into web development, so I challenged myself to build a existing page.
This is the link to the website that I'm trying to rebuild/"copy":
https://www.fahrradhaus-griesmann.de/
Now my question is, how do I format the right side with "Kontakt Impressum Datenschutz" etc. correctly to get the alignment and responsiveness?
Part of my HTML Code:
<div class="row">
<div class="sliderL col-xs-9">
<div id="slider" class="carousel slide" data-ride="carousel">
<!-- indicators dot nav -->
<ol class="carousel-indicators">
<li data-target="#slider" data-slide-to="0" class="active"></li>
<li data-target="#slider" data-slide-to="1"></li>
<li data-target="#slider" data-slide-to="2"></li>
<li data-target="#slider" data-slide-to="3"></li>
<li data-target="#slider" data-slide-to="4"></li>
</ol>
<!-- wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block w-100" src="img/slideshow1.jpg" alt="slideshow1">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/slideshow2.jpg" alt="slideshow2">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/slideshow3.jpg" alt="slideshow3">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/slideshow4.jpg" alt="slideshow4">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/slideshow5.jpg" alt="slideshow5">
</div>
<!-- navigation controls -->
<a class="carousel-control-prev" href="#slider" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#slider" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<div class="sliderR col-xs-3">
<div class="col-xs-12" id="sliderLink">
<nav class="navbar navbar-expand-md">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="#">Kontakt</a></li>
<li class="nav-item"><a class="nav-link" href="#">Impressum</a></li>
<li class="nav-item"><a class="nav-link" href="#">Datenschutz</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
My CSS Code:
.header-container {
background-color: #055dae;
padding-top: 35px;
}
.header-inner {
padding-top: 15px;
background-color: #ffffff;
}
.row {
margin-left: -15px;
margin-right: -15px;
}
.header-adresse {
text-align: right;
}
.header-adresse p {
margin: 0;
}
.sliderL {
max-width: 70%;
}
.sliderR {
background-color: #055dae;
max-width: 30%;
float: right;
}
.div#sliderLink.col-xs-12 {
margin: 0;
padding: 0;
}
If you want to mimic how that section (or row) behaves with alignment and responsiveness, this requires bootstrap classes to be applied to both the slider and right side section.
So lets first analyze the behavior. Looking at the site and source, I confirm the following behavior on the 3 main view sizes:
Desktop - slider takes 9 columns, right side takes 3 columns
Tablet - slider takes 8 columns, right side takes 4 columns
Mobile - slider takes 12 columns and right side is hidden
So taking your HTML mark up, you could do something similar to the following which is entirely bootstrap powered:
<div class="row">
<div class="sliderL col-lg-9 col-md-8 col-xs-12">
...
...
</div>
<div class="sliderR col-lg-3 col-md-4 hidden-sm hidden-xs">
...
...
</div>
</div>
I am tring to make a carousel fill all the space in a section. But it is flowing out of the section. I need to position my carousel inside first section.
I am using twitter bootstrap3 and html5.
CSS
#section1 {
height: 500px;
color: #fff;
background-color: #1E88E5;
background-image: url("http://i.stack.imgur.com/2OrtT.jpg");
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
}
img {
height: 50px;
}
HTML
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li>Section 1</li>
<li>Section 2</li>
<li>Section 3</li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Section 4 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Section 4-1</li>
<li>Section 4-2</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</nav>
---------------------------------------------------------------------------
<div id="section1" class="container-fluid">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="1.jpg" alt="Los Angeles" style=" height=20px ">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>LA is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="2.jpg" alt="Chicago">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
</div>
<div class="item">
<img src="3.jpg" alt="New York">
<div class="carousel-caption">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
jsFiddle
first of all if you are dealing with responsiveness then your style will be as following:
#section1 {
min-height: 500px; //according to your background image size
color: #fff;
background-color: #1E88E5; // no need if you are setting background image on whole div
background-image: url("http://i.stack.imgur.com/2OrtT.jpg");
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
}
img {
height: 50px; // Don't hardcoded the height of image untill you deal with some specific div width.
}
In your case the <div> has class called container-fluid.
In your carousel <div> you have to add your <img> as follow:
<div class="item active">
<img class="img-responsive" src="1.jpg" alt="Los Angeles" style="display:inline-block;">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>LA is always so much fun!</p>
</div>
</div>
And to clear this plz provide the snippet of your code to proper understanding.
My carousel from Bootstrap won't display my images or react to the controls.
This is my HTML:
<!DOCTYPE HTML>
<html>
<head>
<title>Skates R Us</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/global.css">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">
Skates R Us
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">
Home
</li>
<li>
Contact / About
</li>
<li>
Shop
</li>
<li>
New Products
</li>
<li>
Media
</li>
</ul>
</div>
</div>
</div>
<div id="carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="carousel" data-slide-to="0"></li>
<li data-target="carousel" data-slide-to="1"></li>
<li data-target="carousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item">
<img src="img/slide_1.png" alt="Slide 1">
</div>
<div class="item">
<img src="img/slide_2.png" alt="Slide 2">
</div>
<div class="item">
<img src="img/slide_3.png" alt="Slide 3">
</div>
</div>
<a href="#carousel" class="left carousel-control" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a href="#carousel" class="right carousel-control" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$("#carousel").carousel();
</script>
</body>
</html>
My CSS:
#carousel {
margin-top: 50px;
}
.carousel {
height: 500px;
margin-bottom: 60px;
}
/* Since positioning the image, we need to help out the caption */
.carousel-caption {
z-index: 10;
}
/* Declare heights because of positioning of img element */
.carousel .item {
width: 100%;
height: 500px;
background-color: #777;
}
.carousel-inner > .item > img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: 500px;
}
#media (min-width: 768px) {
.carousel-caption p {
margin-bottom: 20px;
font-size: 21px;
line-height: 1.4;
}
}
img {
background: red;
}
There are no errors in the Chrome console and the code is pretty much the exact same as that from the Bootstrap examples.
This is what the site looks like on my end:
There are just two minor things here.
The first is in the following carousel indicator list items:
<li data-target="carousel" data-slide-to="0"></li>
You need to pass the data-target attribute a selector which means the ID must be prefixed with #. So change them to the following:
<li data-target="#carousel" data-slide-to="0"></li>
Secondly, you need to give the carousel a starting point so both the carousel indicator items and the carousel inner items must have one active class. Like this:
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<!-- Other Items -->
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="https://picsum.photos/1500/600?image=1" alt="Slide 1" />
</div>
<!-- Other Items -->
</div>
Working Demo in Fiddle
Here is the changes you need to be done
just replace the carousel div with the below code
You have missed the '#' for data-target and add active class for the first item
<div id="carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="img/slide_1.png" alt="Slide 1">
</div>
<div class="item">
<img src="img/slide_2.png" alt="Slide 2">
</div>
<div class="item">
<img src="img/slide_3.png" alt="Slide 3">
</div>
</div>
<a href="#carousel" class="left carousel-control" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a href="#carousel" class="right carousel-control" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
Well, Bootstrap Carousel has various parameters to control.
i.e.
Interval: Specifies the delay (in milliseconds) between each slide.
pause: Pauses the carousel from going through the next slide when the mouse pointer enters the carousel, and resumes the sliding when the mouse pointer leaves the carousel.
wrap: Specifies whether the carousel should go through all slides continuously, or stop at the last slide
For your reference:
Fore more details please click here...
Hope this will help you :)
Note: This is for the further help.. I mean how can you customise or change default behaviour once carousel is loaded.
Recently I was helping a friend to find why their carousel was not working. Controls would not work and images were not transitioning. I had a working sample on a page I had used and we went through all the code including checking the items above in this post. We pasted the "good" carousel into the same page and it still worked. Now, all css and bootstrap files were the same for both. The code was now identical, so all we could try was the images.
So, we replaced the images with two that were working in my sample. It worked. We replaced the two images with the first two that were originally not working, and it worked. We added back each image (all jpegs) one-by-one, and when we got to the seventh image (of 18) and the carousel failed. Weird. We removed this one image and continued to add the remaining images until they were all added and the carousel worked.
for reference, we were using jquery-3.3.1.slim.min.js and bootstrap/4.3.1/js/bootstrap.min.js on this site.
I do not know why an image would or could cause a carousel to malfunction, but it did. I couldn't find a reference to this cause elsewhere either, so I'm posting here for posterity in the hope that it might help someone else when other solutions fail.
Test carousel with limited set of "known-to-be-good" images.
For me, the carousel wasn't working in the DreamWeaver CC provided the code in the "template" page I am playing with. I needed to add the data-ride="carousel" attribute to the carousel div in order for it to start working. Thanks to Adarsh for his code snippet which highlighted the missing attribute.