How to fix some divs on top while scrolling using bootstrap? - html

I am using bootstrap in Angular 2 project and I want to freeze couple of divs(with ids as filters and categories in the code) on top always, while user scrolls down the page.
This is the code that I have in jsfiddle here
Code Snippet:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li routerLinkActive="active"><a routerLink="/overview">Overview</a></li>
<li routerLinkActive="active"><a routerLink="/insights">Insights</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
<div id="filters" class="container-fluid" style="margin-top: 60px" >
<div class="row">
<div class="col-md-2 col-sm-4">
<button>Filter 1</button>
</div>
<div class="col-md-2 col-sm-4">
<button>Filter 2</button>
</div>
</div>
</div>
<div id="categories" class="container-fluid" >
<div class="row">
<ul class="nav navbar-nav">
<li><a routerLink="#">Sub Category 1</a></li>
<li><a routerLink="#">Sub Category 2</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-6 col-sm-12 col-xs-12">
<div style="background: blue; height: 800px;">
Trend Chart
</div>
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<div style="background: green; height: 800px;">
Bar Chart
</div>
</div>
</div>
</div>
I have tried using bootstrap's 'affix', but it is breaking the scroll and the margins of 'filters' and 'categories' divs, as can be seen here
Kindly let me know if I am missing anything else that needs to be added for affix to work.

To achieve your goal you need to use position: fixed and z-index: 1030 CSS with your div
Here's the jsfiddle
Use this CSS in your div
<div id="filters" class="container-fluid"
style="margin-top: 60px; position: fixed; z-index: 1030;">
<div class="row">
<div class="col-md-2 col-sm-4">
<button>Filter 1</button>
</div>
<div class="col-md-2 col-sm-4">
<button>Filter 2</button>
</div>
</div>
</div>

Use the style attribute "position:fixed" in both the div you want to be fixed.
Also set z-index value above 100. (this is to show the fixed div over all other div while scrolling).
Example:
<div id="filters" class="container-fluid" style="margin-top: 60px;position:fixed;z-index:999;" >
<div class="row">
<div class="col-md-2 col-sm-4">
<button>Filter 1</button>
</div>
<div class="col-md-2 col-sm-4">
<button>Filter 2</button>
</div>
</div>
</div>
<div id="categories" class="container-fluid" style="position:fixed;z-index:999;" >
<div class="row">
<ul class="nav navbar-nav">
<li><a routerLink="#">Sub Category 1</a></li>
<li><a routerLink="#">Sub Category 2</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-6 col-sm-12 col-xs-12">
<div style="background: blue; height: 800px;">
Trend Chart
</div>
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<div style="background: green; height: 800px;">
Bar Chart
</div>
</div>
</div>
</div>

Related

CSS radial-gradient curve causes glitched one pixel box area

The expected result from the prototype:
My work (so far):
The problem:
1: There is a 1-pixel glitch border in the curvy area. It appears or disappears depending on website size, for example when the developer console is shown/hidden, changed its size, changed window size, or zoom in/out. How can I fix that?
2: The curve exists but it doesn't resemble the one from the prototype. How can I change the code to make the curve look more similar to the one from the prototype?
The code of the footer:
<nav class="navbar navbar-expand-lg">
<div class="container-fluid" style="background-image: linear-gradient(135deg, #3ab3da , #6858a2);">
<div class="row w-100">
<div class="col-md-4 p-0">
<div class="container h-50 d-flex align-items-center" style="background: white;">
<div class="row w-100">
<div class="col-lg-4 p-0">
</div>
<div class="col-lg-8 col-12 p-0">
<img class="img-fluid pb-3" src="<?php echo wp_get_attachment_image_src(25, "thumbnail")[0]; ?>" style="" />
</div>
</div>
</div>
</div>
<div class="col-md-1">
<div class="row h-25" style="background: white">
<div class="col"></div>
</div>
<div class="row h-25" style="background: radial-gradient(farthest-side at top left,white 100.00%, transparent 100.00%) bottom right;">
<div class="col"></div>
</div>
<div class="row h-75">
<div class="col"></div>
</div>
</div>
<div class="col-md-1">
<div class="row h-25" style="background: radial-gradient(farthest-side at bottom right,transparent 100.00%,white 100.00%) top left;">
<div class="col"></div>
</div>
<div class="row h-25">
<div class="col"></div>
</div>
<div class="row h-75">
<div class="col"></div>
</div>
</div>
<div class="col-md-6">
<div class="row mt-3">
<div class="row">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent_b" aria-controls="navbarSupportedContent_b" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-uppercase fw-bold my-5" id="navbarSupportedContent_b" style="font-size: 24px;">
<?php
wp_nav_menu([
"menu" => "Main menu",
"container" => "",
"theme_location" => "primary",
"items_wrap" => '<ul class="navbar-nav text-sm-center me-auto mb-2 mb-lg-0">%3$s</ul>'
]);
?>
</div>
</div>
</div>
<div class="row mt-1 mb-5">
<div class="col-md-4">
<i class="fa-solid fa-location-dot mx-4"></i>xxx
</div>
<div class="col-md-4 border-start border-end">
<i class="fa-solid fa-phone mx-4"></i> (+48) yyy
</div>
<div class="col-md-4">
<i class="fa-regular fa-envelope mx-4"></i> zzz#zz.pl
</div>
</div>
</div>
</div>
</div>
</nav>
Live example:
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid" style="background-image: linear-gradient(165deg, #3ab3da , #6858a2);">
<div class="row w-100">
<div class="col-md-4 p-0">
<div class="container h-50 d-flex align-items-center" style="background: white;">
<div class="row w-100">
<div class="col-lg-4 p-0">
</div>
<div class="col-lg-8 col-12 p-0">
foto
</div>
</div>
</div>
</div>
<div class="col-md-1">
<div class="row h-25" style="background: white">
<div class="col"></div>
</div>
<div class="row h-25" style="background: radial-gradient(farthest-side at top left,white 100.00%, transparent 100.00%) bottom right;">
<div class="col"></div>
</div>
<div class="row h-75">
<div class="col"></div>
</div>
</div>
<div class="col-md-1">
<div class="row h-25" style="background: radial-gradient(farthest-side at bottom right,transparent 100.00%,white 100.00%) top left;">
<div class="col"></div>
</div>
<div class="row h-25">
<div class="col"></div>
</div>
<div class="row h-75">
<div class="col"></div>
</div>
</div>
<div class="col-md-6">
<div class="row mt-3">
<div class="row">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent_b" aria-controls="navbarSupportedContent_b" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-uppercase fw-bold my-5" id="navbarSupportedContent_b" style="font-size: 24px;">
<ul class="navbar-nav text-sm-center me-auto mb-2 mb-lg-0"><li class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-home menu-item-15 mx-4">Strona główna</li>
<li class="nav-item menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-6 current_page_item menu-item-17 mx-4">Sklep</li>
<li class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-20 mx-4">O nas</li>
<li class="nav-item menu-item menu-item-type-post_type menu-item-object-page menu-item-23 mx-4">Kontakt</li>
</ul> </div>
</div>
</div>
<div class="row mt-1 mb-5">
<div class="col-md-4">
<i class="fa-solid fa-location-dot mx-4"></i>adres
</div>
<div class="col-md-4 border-start border-end">
<i class="fa-solid fa-phone mx-4"></i> telefon
</div>
<div class="col-md-4">
<i class="fa-regular fa-envelope mx-4"></i> kontakt
</div>
</div>
</div>
</div>
</div>
</nav>
</body>
</html>

A button which contain a description will be hidden inside mobile view

I am working on an asp.net core MVC >> inside y view i am showing a FAQ section. as follow:-
<div class="container">
<div class="row ">
<div class="col-xl-2 mx-auto d-none d-sm-block">
<div class="service_details_left">
<div class="nav nav-pills" id="v-pills-tab" role="tablist"
aria-orientation="vertical">
</div>
</div>
</div>
<div class="accordion_area col-xl-8">
<div class="faq_ask">
<h3 class="large-heading-3">Frequently Asked Questions</h3>
<div id="accordion">
#foreach (var item2 in Model.OrderBy(a => a.Order))
{
<div class="card">
<div class="card-header" id="#item2.Id+'headingTwoa'">
<h5 class="mb-0">
<button class="btn btn-link collapsed " data-toggle="collapse"
data-target="##item2.Id" aria-expanded="false"
aria-controls="collapseTwo">
<span class="expandable-heading"> #Html.DisplayFor(modelItem => item2.Description)</span>
</button>
</h5>
</div>
<div id="#item2.Id" class="collapse" aria-labelledby="headingTwoa"
data-parent="#accordion" style="">
<div class="card-body">
#Html.Raw(item2.Answer)
</div>
</div>
</div>
}
</div>
</div>
</div>
<div class="col-xl-2">
</div>
</div>
</div>
but on wide screen the FAQ will be shown correctly, as follow:-
while on mobile view the question's description will be hidden as follow!!
any advice on this please?
You can try this snippet.
<div class="container">
<div class="row ">
<div class="col-xl-2 mx-auto d-none d-sm-block">
<div class="service_details_left">
<div class="nav nav-pills" id="v-pills-tab" role="tablist"
aria-orientation="vertical">
</div>
</div>
</div>
<div class="accordion_area col-xl-8">
<div class="faq_ask">
<h3 class="large-heading-3">Frequently Asked Questions</h3>
<div id="accordion">
<div class="accordion" id="accordion">
#foreach (var item2 in Model.OrderBy(a => a.Order))
{
<!-- here -->
<div class="card">
<div class="card-header" id="headingTwoa_#item2.Id">
<h5 class="mb-0">
<button class="btn btn-link collapsed " data-toggle="collapse"
data-target="#collapse_#item2.Id" aria-expanded="true"
aria-controls="#item2.Id">
<span class="expandable-heading"> #Html.DisplayFor(modelItem => item2.Description)</span>
</button>
</h5>
</div>
<div id="collapse_#item2.Id" class="collapse" aria-labelledby="headingTwoa_#item2.Id"
data-parent="#accordion" >
<div class="card-body">
#Html.Raw(item2.Answer)
</div>
</div>
</div>
}
</div>
</div>
</div>
</div>
<div class="col-xl-2">
</div>
</div>
</div>
Note: id needs to start with a letter.

html proof and footer on the bottom

I'm pretty new with bootstrap and css. Firstly, I would like to know if the code I wrote is correct. Working with more containers is fine? I use fluid containers for header and footer (width 100% vw), and a standard container for the contents.
Secondly, I m not sure what is the best way to code my footer. I need it on the bottom of the page, but not fixed with absolute position (I dont want it fixed in the browser window).
I tried different solutions without succeding. Shall I nest all my containers in another one?
Thank you so much, and sorry if I didn't explain perfectly or I missed anything.
<div class="container">
<div class="row">
<div clas="col-xs-12">
<nav class="navbar navbar-default navbar-fixed-top">
<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>
<div class="navbar-brand no_margins">
<img src="images/logo.png" alt="logo">
</div>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a href="#">
About
</a>
</li>
<li>
<a href="#">
Works
</a>
</li>
<li>
<a href="#">
News
</a>
</li>
<li>
<a href="#">
Contacts
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
<!-- close container navbar-->
<!-- header -->
<div class="container">
<div class="row">
<header class="col-xs-12 static_header">
<div class="row">
<div class="col-xs-12 col-sm-3 hidden-xs logo_header">
<img src="images/logo_header.png" />
</div>
<div class="col-xs-12 col-sm-9 title_header">
<h1>
My Title
</h1>
</div>
</div>
</header>
</div>
</div>
<!-- end header -->
<!-- content -->
<div class="container">
<div>
<div class="row">
<div class="col-xs-12" id="content_box">
<h2>
About
</h2>
<p>
my text
</p>
​
</div>
</div>
</div>
</div>
<!-- end content -->
<footer class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4 contact_footer">
info#site.com<br>
+1 234567890
</div>
<div id="footer_social_bar" class="col-xs-12 col-sm-4">
<img src="images/fb.png"/>
<img src="images/linkedin.png"/>
<img src="images/twitter.png"/>
</div>
<div class="col-xs-12 col-sm-4 copyright">
© 2017, company
</div>
</div>
</div>
</div>
</div>
</footer>
If you're concerned about viewers using a screen that is far bigger than the content you have in your website, you can use the following css to make sure that the site is at least as big as their browser.
html{
height:100%;
}
body{
min-height:100%;
background-color:#0C0;
}
<p>I only have a small amount of content. But the body background-color is as big as the screen</p>

how can i make space between two fixed navbar with the container

i don't know if the title of my question is related to my problem because i couldn't get better than this sentence ;
i have problem with this code , i have two fixed navbar one in the top and the other in the left and the real problem is like this image and on jsfiddle
the problem is the top nav is above the other nav and i need the top one to be next the left nav like this
the real problem also when i'm using container the other div come above the left side like this photo
how can i fix this problem ? ?
my code is
<body style="background-color:#F2F2F2">
<div style="position: relative; z-index: 3;">
<div class="navbar-fixed-top" style="background-color:#3e474f;height:643px;width:69px;z-index: 2;">
<ul>
<li><a class="fa fa-th-large fa-2x"href="#"></a></li> <li><a class="fa fa-th-large fa-2x"href="#"></a></li> <li><a class="fa fa-th-large fa-2x"href="#"></a></li> <li><a class="fa fa-th-large fa-2x"href="#"></a></li>
</ul>
</div>
<nav style="z-index: 1"class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header navbar-left">
<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 class="collapse navbar-collapse navbar-right" id="myNavbar">
<ul class="nav navbar-nav ">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
</div>
ass="container">
<div class="row">
<div class="col-sm-6 ">
<div class="panel-group ">
<div class="panel panel-default">
<div class="panel-heading">Panel with panel-default class</div>
<div class="panel-body">Panel Content</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">Panel with panel-default class</div>
<div class="panel-body">Panel Content</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">Panel with panel-default class</div>
<div class="panel-body">Panel Content</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">Panel with panel-default class</div>
<div class="panel-body">Panel Content</div>
</div>
</div>
</div>
</div>
</div>
<!-------->
</body>
and on jsfiddle
So, try add you your .navbar and .row - margin-left value.
.navbar, .row {
margin-left: 69px;
}
Alesha's answer is correct, but I noticed it leaves the panel contents hidden, to fix it add this code instead.
.row{
padding-top:50px;
padding-left:75px;
}
.navbar-brand{
padding-left: 75px;
}

Align responsive text

I am trying to align the my icon's text to be on the same level. However, they are distorted when the window is resized bigger as shown in the fiddle. How can I make them to be beside each other?
Here's my fiddle:
https://jsfiddle.net/whywymam/72qp7c6L/
My HTML:
<div id="btnTopInline">
<ul class= "nav navbar-nav navbar-right hidden-xs">
<div class="col-sm-3 col-md-3 col-lg-3">
<li>
<div class="indivColl">
<a href="signupLogin.php">
<img src="https://i.stack.imgur.com/pBLqM.png" class="indi">
<p class="indit">Job Seeker</p>
</a>
</div>
</li>
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<li>
<div class="empColl">
<a href="signupLoginEmp.php">
<img src="https://i.stack.imgur.com/Dbaoj.png" class="emp">
<p class="empt">Employer</p>
</a>
</div>
</li>
</div>
<div class="clearfix visible-md-block"></div>
<div class="clearfix visible-sm-block"></div>
<div class="clearfix visible-lg-block"></div>
</ul>
</div><!-- end btnTopInline -->
<div class="col-xs-2 col-xs-push-6 padBtnRight">
<button type="button" class="btn btn-login visible-xs">
<a href="signupLogin.php">
Job Seeker<br>Log In
</a>
</button>
</div>
<div class="col-xs-2 col-xs-push-7">
<button type="button" class="btn btn-login visible-xs">
<a href="signupLoginEmp.php">
Employer<br>Log In
</a>
</button>
</div>
<div class="clearfix visible-xs-block"></div>