How to add break points for the following scenario? - html

Below image is the mobile view representation of the current scenario -
Here, Orange part represents second div ( DIV 2). Div 3 is a navbar. What I intend to achieve is that in this mobile view, I want that the entire width of div 3 should collapse to the width of a hamburger, sub divs should come in one line and the hamburger icon should come next to it. Something like this -
You can take any random thing in the div to test this scenario ( paragraph, heading etc.)
I am struggling to put the subdivs and the hamburger in one row. Right now I am using bootstrap grid structure to place items. Maybe, I'll need to put the second and third div in a single flexbox. How do I add breakpoints in that?
<div>
<p>DIV1</p>
</div>
<div class="second-div">
<div class="row">
<div class="col-sm-6 justify-content-start">
<p>sub-div1</p>
</div>
<div class="col-sm-6 justify-content-end">
<p>sub-div2</p>
</div>
</div>
<div class="third-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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</div>
</div>
Can anyone please help?

I recommend using CSS-Flexbox to solve your Problem. the following example gives you an overview to get a similar result as you posted in your Question:
body{
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
}
/*for smartphone / mobile*/
#media only screen and (max-width: 600px) {
.wrapper{
width: 100%;
height: 20%;
/*the following 3 lines make your Element behave as a flexbox element, the way it should behave and how it positions the elements inside of it*/
display: flex;
flex-direction: row;
justify-content: space-between;
}
.div1{
display: none;
}
.container-subdivs{
width: 80%;
height: 100%;
/*the following 3 lines make your Element behave as a flexbox element, the way it should behave and how it positions the elements inside of it*/
display:flex;
/*flex-flow is a combination of flex-direction and flex-wrap*/
flex-flow: row nowrap;
justify-content: space-between;
}
.subdiv1{
width: 10%;
height: 100%;
background-color: orange;
}
.subdiv2{
width: 15%;
height: 100%;
background-color: red;
}
.subdiv3{
width: 15%;
height: 100%;
background-color: yellow;
}
.div3{
height: 100%;
width: 15%;
background-color: pink;
}
}
/* for normal desktop, tablet etc.*/
#media only screen and (min-width: 601px) {
.wrapper{
width: 100%;
height: 100%;
}
.div1{
width: 100%;
height: 2%;
background-color: purple;
}
.container-subdivs{
width: 100%;
height: 20%;
/*See above comments*/
display:flex;
flex-flow: row wrap;
}
.subdiv1{
width: 80%;
height: 60%;
background-color: orange;
}
.subdiv2{
width: 20%;
height: 60%;
background-color: red;
}
.subdiv3{
width: 100%;
height: 40%;
background-color: yellow;
}
.div3{
margin-top: 4vh;
height: 20%;
width: 100%;
background-color: pink;
}
}
<div class="wrapper">
<div class="div1">
div1
</div>
<div class="container-subdivs">
<div class="subdiv1">
subdiv1
</div>
<div class="subdiv2">
subdiv2
</div>
<div class="subdiv3">
subdiv3
</div>
</div>
<div class="div3">
div3
</div>
</div>
The key here is how to set the flex-direction and flex-wrap behaviours, also you need enough elements to wrap several other elements to make them behave in the same way. To find your final solution you need to add a few elements and the css for your hamburger-menu, you will eb able to figure this out yourself.
check THIS to understand what is happening here and how to finalize the approach. Good luck and dont be afraid to ask additional questions in the comments.

well. you have to use css3 grid instead. use CSS3 AND MEDIA QUERYIES to develop the layout like this.
checkout the code here
.item1 { grid-area: header; }
.item2 { grid-area: menu; }
.item4 { grid-area: right; }
.item5 { grid-area: footer; }
/* On screens that are 992px or less, set the background color to blue */
#media screen and (min-width: 600px) {
body {
background-color: blue;
}
.grid-container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-template-areas:
"right right header header . . . menu menu menu footer footer";
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
}
/* On screens that are 600px or less, set the background color to olive */
#media screen and (max-width: 600px) {
body {
background-color: olive;
}
.grid-container {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-template-areas:
"right right right right right right header header header header header header"
"menu menu menu menu menu menu menu menu menu menu menu menu"
"footer footer footer footer footer footer footer footer footer footer footer footer";
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
}
.grid-container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px 0;
font-size: 30px;
}

Related

How can I align my navbar items to the left and right side of the centered image?

I'm developing a website in Blazor with Bootstrap version 5.1. So I set an image within that navbar. Now I want to align the other items of the navbar just before and after the image in the center. I tried using the Bootstrap 5.0 ms-auto and me-auto to a div and put the nav items in it, but it only aligned the items to the right or left corner of the navbar.
Here is the code of the website:
#page "/"
<style>
.navbar {
position: relative;
padding-top: 0;
opacity: 80%
}
.navbar-brand {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: block;
}
.img-responsive {
height: auto;
width: auto;
max-height: 156px;
max-width: 250px;
top: 109px;
}
.circle
{
width: 249px;
height: 285px;
border-radius:250px;
font-size:50px;
line-height:500px;
text-align:center;
background:#000
}
body {
background: url(assets/hack2.jpg) no-repeat center center fixed;
background-size: cover;
}
</style>
<div class=bodyContainer>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<div class="circle bg-light navbar-brand">
<a href="#" class="navbar-brand">
<img class="img-responsive navbar-brand" src="assets/logo.png" alt="logo">
</a>
</div>
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<div class="navbar-nav">
Home
Über uns
Aktuelles
Genossenschaft
Nochagfrogt
Kontakt
</div>
<div class="navbar-nav ms-auto">
Login
</div>
</div>
</div>
</nav>
</div>
If it helps (because I created a container class for the body):
.bodyContainer {
height: calc(100vh - 60px);
}
I made your .navbar-nav a font-color black just so I could see it better, and added white-space: nowrap; on your navbar-nav class so your words don't break when resizing. I am not sure if I properly understood what you wanted your end result to be, but I think I got the gist of it.
For this to work with the ease of customization in the future, I suggest splitting each side into two separate divs, as I did below. .left containing the left side nav components, and .right containing the right components. I put a flex-display on your two new divs dividing the components, and spaced them out using gap. Then I nested them in a parent nav element which I called same-line for demonstration purposes.
First, add a flex-display then you can add justify-content: space-around; on your parent nav that allows for the two sides to space evenly to both the left and right sides respectfully. If your logo is truly the size of the .circle class, I added a sample media-query so the font-size of the nav components gets smaller and doesn't overlap the logo.
.navbar {
position: relative;
padding-top: 0;
opacity: 80%;
}
.navbar-brand {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: block;
}
.img-responsive {
height: auto;
width: auto;
max-height: 156px;
max-width: 250px;
top: 109px;
}
.circle {
width: 249px;
height: 285px;
border-radius:250px;
font-size:50px;
line-height:500px;
text-align:center;
background: black;
}
.navbar-nav a {
color: black;
white-space: nowrap;
}
/* additions */
.left {
display: flex;
gap: 20px;
}
.right {
display: flex;
gap: 20px;
}
nav.same-line {
display: flex;
justify-content: space-between;
}
#media only screen and (max-width: 800px) {
.same-line {
font-size: smaller;
}
.left, .right {
display: flex;
gap: 5px;
}
}
/* additions END */
body {
background: url(assets/hack2.jpg) no-repeat center center fixed;
background-size: cover;
}
<div class="bodyContainer">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<div class="circle bg-light navbar-brand">
<a href="#" class="navbar-brand">
<img class="img-responsive navbar-brand" src="assets/logo.png" alt="logo">
</a>
</div>
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<nav class="same-line"> <!-- puts both .left & .right one same line -->
<div class="navbar-nav left">
Home
Über uns
Aktuelles
</div>
<!-- left contains leftside nav components, right = opposite -->
<div class="navbar-nav right">
Genossenschaft
Nochagfrogt
Kontakt
</div>
</nav>
<div class="navbar-nav ms-auto">
Login
</div>
</div>
</div>
</nav>
</div>
Click full-page when testing the snippet, and resize your browser to watch the font-size change just before it overlaps. I would target this same media-query to change your logo size when resizing also.

Can't move my div using float-right inside container

I have a container where i store 2 div's. ".logo" and ".navbar-list" how can I move my ".navbar-list" to the right edge of container.
Previously everything worked but when I switched bootstrap to version 4.3.1 my div's overlapped .I've tried float:right but is not working.
container {
font-family: sans-serif;
height: 100%;
margin-left: auto;
margin-right: auto;
float: none;
padding: 0;
}
.logo {
width: 380px;
margin-right: 0;
position: absolute;
height: 100%;
margin-left: 10px;
}
.navbar-list {
color: white;
width: 300px;
height: 100%;
}
<div class="container">
<div class="logo">
<a class="navbar-brand" href="#"><img src="img/640px-HSV-Logo.png" /></a>
<h1>WITAJ W <span>DOMU!</span></h1>
</div>
<div class="navbar-list ">
<ul>
<li>
<span class=" glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Sklep
</li>
</ul>
<ul>
<li> <button type="button" class="btn btn-danger btn-md ">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Zaloguj się
</button></li>
</ul>
</div>
</div>
There are lots of methods of achieving your desired result! In my opinion, Flexbox would be your best option. You should add display: flex to your .container. You can add the flex to the .logo container as well, if you want the logo and h1 to sit side by side.
You should also avoid using float, as this often makes HTML behave unexpectedly. You can replace this with justify-content: space-between.
I've amended your example above to incorporate my amends:
.container {
font-family: sans-serif;
padding: 0;
height: 80px;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
width: 380px;
/*margin-right: 0; */
/*position: absolute; */
height: 100%;
margin-left: 10px;
display: flex;
align-items: center;
}
.navbar-list {
color: white;
width: 300px;
height: 100%;
}
<div class="container">
<div class="logo">
<a class="navbar-brand" href="#"><img src="img/640px-HSV-Logo.png" /></a>
<h1>WITAJ W <span>DOMU!</span></h1>
</div>
<div class="navbar-list ">
<ul>
<li>
<span class=" glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Sklep
</li>
</ul>
<ul>
<li> <button type="button" class="btn btn-danger btn-md ">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Zaloguj się
</button></li>
</ul>
</div>
</div>
From a high level, the go-to method for this situation is using flexbox instead of floats. Not sure about Bootstrap in your case or why you had that change happen.
.container {
display: flex;
justify-content: flex-end; /* and many more positioning options */
}
just add float: right; to your .navbar-list css then you can move your div to right side
.navbar-list {
color: white;
width: 300px;
height: 100%;
float: right;
}

Increasing width of text bar without moving other elements

I am duplicating the Youtube navigation bar by using flexbox but when I came across the search bar It kept on moving the icons while I was trying to increase the width of the search bar.
I've tried position absolute and align self but it did not work.
* {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
background-color: #f1f1f1;
}
.navigation {
height: 60px;
width: 100%;
box-shadow: 0px 10px 9px #eeeeee;
background-color: #ffffff;
display: flex;
justify-content: space-around;
align-items: center;
}
.stack,
.icon {
width: 100px;
}
/* right corner of nav bar */
.menu {
position: relative;
right: 30px;
width: 23px;
opacity: .6;
}
.youtube-logo {
position: relative;
right: 130px;
width: 90px;
}
.search-bar {
position: relative;
left: 100px;
height: 30px;
}
<nav class="navigation">
<a href="#menu">
<img src="images/menu.svg" alt="menu for the top left, shaped like a hamburger" class="menu">
</a>
<a href="#logo">
<img src="images/youtube.logo.png" alt="youtube logo" class="youtube-logo">
</a>
<input type="text" name="searchbar" placeholder="Search" class="search-bar">
<a href="#video-icon">
<img src="images/video.svg" alt="video icon" class="video">
</a>
</nav>
I wanted the search bar to be the same exact width of YouTube's search bar without moving the other icons.
//you can used a ul li for fixed navbar and this very helpful to don't move other element in navbar
like this :
Navbar
<div class="collapse navbar-collapse">
<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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-
label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
// or use Bootstrap 4 very nice and easy
You're likely looking to use justify-content: space-between and then adjusting the flex property of the input bar. Flexbox items default to a value of flex: 0 1 auto (aka flex-grow: 0, flex-shrink: 1, flex-basis: auto). In this case, you want the input bar by default to grow and take up the rest of the available space in your flex container, so if you set its flex property to flex: 1 (equivalent to flex: 1 1 0) or set flex-grow: 1 you accomplish this.
justify-content: space-around evenly spaces each element, and the empty space before the first item and after the last item in the flex container is set to equal half the space between each adjacent item. Using justify-content: space-between forces the first and last item in the flex container to be flush respectively with the beginning and end of the flex container.
This way, you don't need to use position relative/ absolute (you shouldn't need to use either of these in a flex container anyway) and can use margins to better space between each element.
* {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
background-color: #f1f1f1;
}
.navigation {
height: 60px;
box-shadow: 0px 10px 9px #eeeeee;
background-color: #ffffff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 16px;
}
.stack,
.icon {
width: 100px;
}
/* right corner of nav bar */
.menu {
width: 23px;
opacity: 0.6;
margin: 0 16px 0 0;
}
.youtube-logo {
width: 90px;
height: 40px;
}
.search-bar {
margin: 0 40px;
flex: 1;
}
<nav class="navigation">
<a href="#menu">
<img src="https://via.placeholder.com/23" alt="menu for the top left, shaped like a hamburger" class="menu">
</a>
<a href="#logo">
<img src="https://via.placeholder.com/190" alt="youtube logo" class="youtube-logo">
</a>
<input type="text" name="searchbar" placeholder="Search" class="search-bar">
<a href="#video-icon">
<img src="https://via.placeholder.com/40" alt="video icon" class="video">
</a>
</nav>
More on how justify-content values work: https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
And more on the flex property: https://developer.mozilla.org/en-US/docs/Web/CSS/flex

The navbar does not stick to bottom

<div class="row">
<nav class="navbar navbar-default footer">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"></button>
<a class="navbar-brand" href="#">
<img src="images/Logobott.png" />
</a></div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="foot-stylee">
Apps
</li>
<li>
Gadgets
</li>
<li>
Sience
</li>
<li>
Nature
</li>
<li>
Creative
</li>
</ul>
<ul class="nav navbar-nav navbar-right nav-r">
<li>
© 2016 Great Simple
</li>
</ul>
</div>
</div>
</nav>
</div>
.footer {
width: 100%;
margin-top: 30px;
margin-bottom: 0px;
z-index: 12;
background-color: rgb(134, 147, 158);
}
As you can see my footer does not stick to the bottom. I have the same exact code for other pages and it worked but for this page it does not. Can someone tell me what is wrong? I want it to be at the end of the page.
You can achieve that with positioning. Make the footer position: fixed; and give it bottom: 0; so it will stick to the bottom of the viewport:
.footer {
width: 100%;
height: 200px;
margin-top: 30px;
margin-bottom: 0px;
z-index: 12;
background-color: rgb(134, 147, 158);
position: fixed;
bottom: 0;
}
<div class="row">
<nav class="navbar navbar-default footer">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"></button>
<a class="navbar-brand" href="#">
<img src="images/Logobott.png" />
</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="foot-stylee">
Apps
</li>
<li>
Gadgets
</li>
<li>
Sience
</li>
<li>
Nature
</li>
<li>
Creative
</li>
</ul>
<ul class="nav navbar-nav navbar-right nav-r">
<li>
© 2016 Great Simple
</li>
</ul>
</div>
</div>
</nav>
</div>
Edit
If you want your footer to be on the bottom of your page rather than on the bottom of the viewport, just remove the position: fixed; give the element above the footer a min-width of 100% minus the height of the footer, e.g.:
min-height: calc(100% - 200px);
When you are first having a <html> that may not fill the window's height, and neither the <body> element, also the .container element... if you want to have a sticky footer, you could try
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100px;
}
body {
padding-bottom: 100px;
}
Edit 1 -
There are 2 ways to not use the fixed position, the first one is using the calc function of CSS:
html, body { min-height: 100vh; }
nav { min-height: 10vh; height: auto; }
footer { min-height: 100px; height: 100px; }
main { min-height: calc(90vh - 100px); }
The other way ia using <table>, <tr> and <td> or display: table, display: table-row and display: table-cell with min-height CSS property.
You may want to look at my answer of this question for more info: Sticky footer that extends when at website-bottom and scrolling further
Edit 2 -
I found that this could be done via the display: flex; easily.
body {
display: flex;
flex-direction: column;
flex-wrap: no-wrap;
min-height: 100vh;
}
header { height: 100px; }
content { flex-grow: 1; }
footer { height: 100px; }
Try on: https://jsfiddle.net/89ucrec5/6/
I found a decent solution to this a few months ago... You have to wrap your page content and footer into separate wrappers and do a little bit of CSS magic with :after to get it right.
html:
<html>
<body>
<div class="content-wrapper">
my content
</div>
<div class="footer-wrapper">
my footer
</div>
</body>
</html>
css:
html, body {
height: 100%;
}
.content-wrapper {
min-height: 100%;
margin-botton: -100px; //set to anything as long as it matches footer-wrapper height
}
.content-wrapper:after {
content: "";
display: block;
}
.footer-wrapper, .content-wrapper:after {
height: 100px;
}
html:
<div class="your-container">
<div class="content">
</div>
<div class="footer">
</div>
</div>
css:
.your-container {
min-height: 100vh;
position: relative;
}
.footer {
position: absolute;
bottom: 0px;
right: 0px;
left: 0px;
}
You will need to make proper padding from main content
Another way is setting flex container so your content would take all remaining space
html:
<div class="your-container">
<div class="content">
</div>
<div class="footer">
</div>
</div>
css:
.your-container {
display: flex;
flex-direction: column;
min-height: 100vh;
}
content {
flex-grow: 1;
}

Remove extra white space from top in firefox

Certain portions of the page looks different in firefox than chrome.
This is what it looks like in chrome:
This is what it looks like in firefox:
HTML code:
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
margin-top: 0;
padding-top: 0;
overflow-x: hidden;
}
#media print {
body {
margin-top: 0 !important;
}
}
body {
background-color: white;
color: black;
padding: 0;
margin: 0;
min-height: 100%;
min-width: 100%;
overflow-x: hidden;
}
.rowa {
padding: 10px;
background-color: black;
color: white;
height: 100%;
margin: 0;
}
#title {
font-size: 36px;
display: inline-block;
color: white;
}
<nav class="navbar navbar-inverse " id="navtop">
<div class="container-fluid rowa">
<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="#" id="title">title</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right menu " id="menu1">
<li> Home
</li>
<li> Booking
</li>
<li>Rates
</li>
<li> About us
</li>
<li> Contact us
</li>
</ul>
</div>
</div>
</nav>
I am not able to remove the extra space from top and the extra padding within the nav-bar.
I have set margin and padding to 0 for html and body in css, and min-width and min-height is 100%.
Also there is extra spacing between an image and form in firefox (for small screen devices).
How to I get rid of these extra spaces in firefox? Please help.
Adjust using height rule in CSS to id="menu1".