I have below container with two rows. first row is header and second row has left nav bar and main content on right.
i want the left nav bar shrink to the width of the content. It shrinks to just icons when i press a toggle button of nav bar. in its default position it is expanded to show icons plus labels. When user resizes screen to small devices the nav bar should only show icons.
<div class="row h-100">
<div
class="col-12 w-100 sticky-header"
style="background-color: darkgrey;"
>
<h1>This is top header<h1/>
</div>
<div class="col-2">
<div class="fixed-box col-2">
<h1>SideNavBar</h1>
<ul>
<li>
<router-link class="nav-link" to="/contacts">
<img :src="ContactsImage" />
<span>Contacts</span>
</router-link>
</li>
<li>
<router-link class="nav-link" to="/home">
<img :src="HomeImage" />
<span>Home</span>
</router-link>
</li>
<li>
<router-link class="nav-link" to="/help">
<img :src="HelpImage" />
<span>Help</span>
</router-link>
</li>
</ul>
</div>
</div>
<div class="col-10 bg-warning h-100 no-gutters">
<p>This is main content you see when you click a link on left<p/>
</div>
</div>
</div>
</div>
#media only screen and (max-width: 768px) {
.sidenavbar span {
display: none;
}
.sidenav {
width: 75px !important;
}
}
.sidenav {
width: 150px !important;
}
I could achieve the desired functionality by using css style to apply a different width for side nav bar column. But it leaves out col-2 with space not used by side nav. Is there a way to make col-2 to shrink to the size of its content. And make the main content col-10 to take up .
In bootstrap 4 you can add responsive classes such as d-none, d-md-none etc.
https://getbootstrap.com/docs/4.0/utilities/display/
This will hide the <span></span>, containing the text, on mobile devices.
Here's a codeply example https://www.codeply.com/p/taMk8vmbJl
On mobile it will hide the <span> element and only display icons.
Also by changing col-10 to col-md-10 it'll display content under 'SideNavBar' on mobile.
Related
My footer when full screen adds space to the right and when i use for example mobile view a chunk of my footer disappears. I just want it to stay at the bottom and not cover any content. Even when it shrinks to mobile view.
[![De red line is the extra space im talking about][1]][1]
#footer {
position: absolute;
left: 0;
bottom: 0 !important;
width: 100%;
height: 2.5rem;
padding-right: 0;
background-color: black;
border-top: 4px solid #F2D380;
overflow: auto;
}
#footer a {
color: white;
text-decoration: none;
}
<div id="footer">
<div class="row text-center justify-content-center">
<div class="col-lg-2 ">
Company Information
</div>
<div class="col-lg-2">
Privacy Policy and User Agreement
</div>
<div class="col-lg-2">
About
</div>
<div class="col-lg-2">
©2019 Copyright claim
</div>
<div class="col-lg-2">
<a href="#">
<img src="images/linkedin.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/instagram.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/facebook.png" class=" socialIcon">
</a>
<a href="#">
<img src="images/youtube.png" class="socialIcon">
</a>
</div>
</div>
</div>
So the issue of why the space is added and it covers content is because of the absolute positioning. If you do not want it to cover content you have a couple options. Set the content wrapper to a set height and the footer to the rest of that height so the footer stays visible at the bottom and wont cover content.
If you just want it to act as a footer and be at the bottom on mobile I would just set it to be position relative.
It is hard to envision what you are going for without other content on the page.
By specifying height: 2.5rem, you have given the footer a fixed height and it won't scale according to the content you have provided in it. Try height: auto, or height: max-content, because it seems your content is larger than the footer itself.
Also put margin: 0 to ensure no space is added around it
I have a problem with the navbar-fixed-top item. It hides content form the container.
This is a common problem solved by adding the following css code :
body { padding-top: 70px; }
Now, when I load my page, the container is not hidden by the navbar anymore. The problem is when I want to go to a specific item in the page with a href=#item. In this case, the item is always hidden by the navbar.
I have created a simple code on Codeply which shows this problem. In this example, when I click on "Got to test3", the item <h2 class="font-weight-light">TEST3</h2> is hidden by the navbar.
Here is the code below :
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
HELLO NAVBAR
</nav>
<div class="container py-2">
<div class="row">
<div class="col">
<div class="sidebar-sticky" id="menu">
<ul class="nav flex-column">
<li class="nav-item">
Go to test1
</li>
<li class="nav-item">
Go to test2
</li>
<li class="nav-item">
Go to test3
</li>
<li class="nav-item">
Go to test4
</li>
</ul>
</div>
</div>
<div class="col">
<div id="test">
<h2 class="font-weight-light">TEST1</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test2">
<h2 class="font-weight-light">TEST2</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test3">
<h2 class="font-weight-light">TEST3</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
<div id="test4">
<h2 class="font-weight-light">TEST4</h2>
<p>
This is a Bootstrap starter example snippet.
</p>
<br/><br/><br/><br/><br/>
</div>
</div>
</div>
</div>
Here's the solution
body {
padding-top: 70px;
}
#test{
padding-top:90px;
}
#test2{
padding-top:90px;
}
#test3{
padding-top:90px;
}
#test4{
padding-top:90px;
}
For the current case, you could add the padding to the div elements which have a h2 following them (such as "Test3"). Adding div h2 { padding-top: 70px; } does that for your current structure. However, in order to not depend on the h2 following a div as you further develop your project, you could also create an own class to which the padding-top-rule applies, and add it to those elements for which it is needed.
Hope that helps.
From the question Fixed page header overlaps in-page anchors, the solution is not the accepted answer but is in the answers. So I'll repeat it here.
I have add this class in the css file :
.hreflink::before {
content: "";
display: block;
height: 70px; /* fixed header height*/
margin: -70px 0 0; /* negative fixed header height */
}
and then I have define every element I want to go to with this class, for example :
<div id="test3" class="hreflink">
I am using a media query with Bootstrap's jumbotron. I want to align vertically two divs inside jumbotron to be mobile responsive. The problem is that under a certain width, jumbotron flaps responsively as expected and my photo in the right stays there rather than aligning vertically with the first div.
To prevent this, I added media query to align the photo to the left of its parent div but I did not get a result.
The code and the pictures are attached.
<div class="jumbotron">
<div class="row">
<div id="about2" class="col-md-6">
<h1>About Me</h1>
<p>This page contains a brief information about Mehmet Eyüpoğlu.
</p>
<a href="index.html">
<i id="home-button" class="fas fa-home"></i>
</a>
</div>
<div class="col-md-6">
<img id="about-foto" src="images/unnamed.jpg" alt="profile.photo">
</div>
</div>
</div>
Css Code:
#about2 {
font-size: 35px;
margin-top: 50px;
}
#about-foto {
max-width: 70%;
border-radius: 10px;
margin-left: 60%;
}
//The actual problem starts here:
#media (max-width: 768px) {
#about-foto {
margin-left: 5%;
}
}
Image showing the desktop size
Image showing the mobile size
You just have a syntax error with your media query, try!
#media screen(max-width: 768px) {
#about-foto {
margin-left: 5%;
}
}
You can find a torough explanation of media queries here.
Don't use margin to align stuff like this, especially not when using bootstrap.
Get familiar with the grid system of bootstrap, you can define a width for every breakpoint.
I changed your markup to use a col-md-8 for your text and col-md-4 for your image. Important thing is that the numbers always add up to 12 (because that's the number bootstrap uses for one line)
This means that for screens with medium (md) size and up you side will be divided by a column with md-8 width and md-4 width, for every screen smaller it will be -12 width (100%)
#about2 {
font-size: 35px;
margin-top: 50px;
}
#about-foto {
max-width: 70%;
border-radius: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="jumbotron">
<div class="row">
<div id="about2" class="col-md-8 ">
<h1>About Me</h1>
<p>This page contains a brief information about Mehmet Eyüpoğlu.
</p>
<a href="index.html">
<i id="home-button" class="fas fa-home"></i>
</a>
</div>
<div class="col-md-4 text-left">
<img id="about-foto" src="images/unnamed.jpg" alt="profile.photo">
</div>
</div>
</div>
Here's my HTML:
<div class="navbar navbxar-inverse navbar-fixed-bottom" role="navigation" style="min-width: 320px; height: 51px;">
<div class="container-fluid" style="display: table;">
<div class="row row-mod">
<div class="col-xs-7 col-xs-7-mod" style="background-color: blue;">
<a class="navbar-logo pull-left" href="/"><img class="img-responsive" src="http://s24.postimg.org/intj0mv3l/logo.jpg" /></a>
<span class="navbar-footer-text-container">
<span class="navbar-footer-text">CUSTOMER SERVICES | STORE </br>COPYRIGHT © BRND 2006/2014</span>
</span>
</div>
<div class="col-xs-5 col-xs-5-mod" style="padding-right: auto; background-color: red;">
<img style="margin-left: 1px;" class="pull-right img-responsive" src="http://s4.postimg.org/kus2gqabd/image.jpg" />
<img style="margin-left: 1px;" class="pull-right img-responsive" src="http://s4.postimg.org/kus2gqabd/image.jpg" />
<img class="pull-right img-responsive" src="http://s4.postimg.org/kus2gqabd/image.jpg" />
</div>
</div>
</div>
</div>
My CSS is added to JSFiddle.
Currently the problems are:
1. The bigger yellow image is not centered vertically in the blue div, it is on the bottom of the div
2. The smaller yellow images are not centered vertically in the red div, they are on the top of the div
3. The smaller yellow images are not on the right of the red div. There is a little space, I couldn't find why this space appears
4. The yellow images are set to be responsive. I've set this, because I've also set a rule to resize the navbar under 410px to have only 39px height. This feature is necessary, because then on smaller screens the text doesn't have to go to the next row, so everything fits like on bigger screens. The problem is that it isn't working this currently.
Do you have any clues for these problems?
Edit:
I would like to achieve the following layout:
1. The bigger image (the logo) and the text should be on the left side
2. The text after the logo must be in 2 lines and the space between the two lines should be small
3. The other three images should be on the right
4. The navigation bar should have a width as the window
5. The content on the navigation bar should have a maximum widht of 976px
6. The navigation bar should have a height of 51px
7. The text should have an 8pt size
These settings should be changed a bit when the screen size is lower than 410px. This is necessary, because under 410px the content cannot fit in the space, so in case the navbar is only 39px and also the images will be resized according to this height than everything can fit.
the main issue is your mix of inline and external styles, quite a mess. Within that mess, you have that bottom nav with a display:table declaration. Basically, you're trying to re-invent the wheel. I don't know why are you doing this, but following your logic, I've fixed your code so it works. See fiddle and HTML code below.
<div class="navbar navbxar-inverse navbar-fixed-bottom navbar-bottom" role="navigation">
<div class="container-fluid" style="display: table; padding:0; margin:0 auto">
<div class="row row-mod">
<div class="col-xs-7 col-xs-7-mod" style="background-color: blue; ">
<a class="navbar-logo pull-left" href="/"><img class="img-responsive" style="margin-left: 1px; margin-top:-9px; display:inline; vertical-align:50%; height:47px;" src="http://s24.postimg.org/intj0mv3l/logo.jpg" /></a>
<span class="navbar-footer-text-container">
<span class="navbar-footer-text">CUSTOMER SERVICES | STORE </br>COPYRIGHT © BRND 2006/2014</span>
</span>
</div>
<div class="col-xs-5 col-xs-5-mod" style="padding-right: auto; background-color: red; ">
<img style="margin-left: 1px; margin-top:9px" class="pull-right img-responsive" src="http://s4.postimg.org/kus2gqabd/image.jpg" />
<img style="margin-left: 1px; margin-top:9px" class="pull-right img-responsive" src="http://s4.postimg.org/kus2gqabd/image.jpg" />
<img style="margin-left: 1px; margin-top:9px" class="pull-right img-responsive" src="http://s4.postimg.org/kus2gqabd/image.jpg" />
</div>
</div>
</div>
Now, my suggestion would be for you to use Bootstrap as it is, it really works fine without any reinvention.
How can I hide the side bar in mobile?
CSS:
.sidebar-nav {
padding: 9px 0;
}
.sidebar-nav .nav-header {
font-size: 18px;
color:#FF9900;
}
HTML:
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Content Management</li>
<li>test</li>
<li>test2</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="col-md-9">
<div class="container">
<div class="row">
.....
</div>
</div>
</div>
</div>
</div>
<div class="col-md-3 hidden-xs">
The "mobile" breakpoint default is 767px. To hide something at that size, just put .hidden-xs on it. There is no need to do anything else. If you don't want it to show at the small min width add .hidden-xs .hidden-sm OR you can just add .visible-md .visible-lg
http://jsbin.com/AmaVUcib/1/edit
Put this in your css, preferably at the bottom. This will hide the sidebar for any screen less than 651px. Adjust the number of pixels to how you want.
#media screen (max-width: 650px) {
.well .sidebar-nav {
display: none;
}
}
Here's a link with more info https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
In bootstrap 4, use add the following classes to hide on xs and sm devices
.d-none .d-sm-none .d-md-block
Read more here