I'm trying to create a portfolio in which when the user scrolls, a small bar icon is visible and fixed. On clicking, it should display the tools in navigation bar like "about me, contact me".
I tried using position: fixed; but it isn't working.
and I can't seem to get this bar icon to the left side of the page. Tried giving it different margin and padding and the drop down isn't working either.
.fa {
transform: scale(0.5,0.5);
}
.dropdown{
position: fixed;
}
<div class="container">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle pull-left" type="button" id="menu1" data-toggle="dropdown"><i class="fa fa-bars" aria-hidden="true"></i></button>
<span class="caret"></span></button>
<nav role="navigation">
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Home</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">About</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Contact</a></li>
</ul>
</nav>
</div>
</div>
.dropdown not must be child another elem, except body
body {
position: relative;
}
.dropdown{
position: fixed;
}
Example:
body {
position: relative;
height: 200vh;
background: linear-gradient(orange 0, red 50%, pink 100%);
}
.dropdown{
position: fixed;
width: 140px;
height: 180px;
background-color: blue;
}
<div class="dropdown">
</div>
Related
I have a div here which contains 3 dropdowns:
<div class="text-center container">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" id="make" type="button" data-toggle="dropdown"> Subject
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="makein">
<li>bmw</li>
<li>mercedes</li>
<li>mazda</li>
<li>ford</li>
<li>lada</li>
<li>audi</li>
<li>skoda</li>
<li>fiat</li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" id="year" type="button" data-toggle="dropdown"> Year
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="yearin">
<li>2016</li>
<li>2015</li>
<li>2014</li>
<li>2013</li>
<li>2012</li>
<li>2011</li>
<li>2010</li>
<li>2009</li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" id="level" type="button" data-toggle="dropdown"> Level
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="levelin">
<li>luxury</li>
<li>ordinary</li>
</ul>
</div>
</div>
I use the following to center the div in the middle of the screen centered:
.container{
width: 300px;
height: 300px;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.dropdown{
display: inline-block;
}
It also aligns my drop downs horizontally.
I locate my div in the middle of the screen using this custom css. I am wondering if there is a way to avoid using the custom css and do this same thing just purely using Bootstrap.
My aim is:
1: Locate the container in the center in the middle of the page.
2: Horizontally align the dropdowns.
Bootstrap shipped with container and text-center classes then why you are defining your own container class? Just include bootstrap files properly in your code and no need for this custom CSS.
text-center class will align your drop down in middle of screen and container class has fixed width with auto margin. Check jsFiddle
To achieve expected result , use below CSS to container
.container{
width: 300px;
height: 60%;
position: absolute;
top:20%;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
http://codepen.io/nagasai/pen/LkoLGw
There are no way in bootstrap to locate div in the middle of the screen.
you may check below custom css code:
.container {
position: absolute;
width: 100%;
top: 45%;
}
.dropdown {
display: inline-block;
}
I want the dropdown on the right.
In such a way it doesn't clip the right side of the browser.
No matter what something goes wrong.
Why can't things not just work in css? (sry i'm really frustrated)
There is always some special case why things have to be done different.
Anyway, how can I get the dropdown to the right side?
<div id="footer">
<div class="share">
<ul class="nav nav-pills">
<li class="nav-item dropup">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Share</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Facebook</a>
<a class="dropdown-item" href="#">Twitter</a>
</div>
</li>
</ul>
</div>
</div>
#footer {
position: fixed;
bottom: 0;
}
.share {
float: right;
}
add a width to your footer. The dropdown is floating right, the footer just isnt as wide as you think it is by default.
#footer {
position: fixed;
bottom: 0;
width: 100%;
}
stuff like this can easily be diagnosed using dev tools that chrome or firefox provide :)
What i am creating is similar to this. I found this while researching on stackexchange.
However, i want the dropdown to open on mouseover. I am able to create a bootstrap navbar with mouseover dropdowns, but unable to add mouseover action to the example given above. Any ideas?
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" data-target="#" href="/page.html">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<ul class="nav nav-tabs">
<li class="active"><a data-target="#home" data-toggle="tab">Home</a> </li>
<li><a data-target="#profile" data-toggle="tab">Profile</a></li>
<li><a data-target="#messages" data-toggle="tab">Messages</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="home">HOME asdfasdfsda</div>
<div class="tab-pane" id="profile">PROFILE asdfafas</div>
<div class="tab-pane" id="messages">MESSAGES asdfdas</div>
</div>
</ul>
</div>
http://jsfiddle.net/pv2Lc/7/
How about this?
http://jsfiddle.net/70ytg4yf/
HTML unchanged
No JS
CSS:
.dropdown:hover {
/* so that no mouseout is triggered when moving to the menu */
padding-bottom: 5px;
}
.dropdown-menu {
/* move up since default is lower because of padding */
margin-top: -5px;
}
.dropdown:hover .dropdown-menu {
display: block;
}
I am using Bootstrap in my project and I have navigation bar in my home page. I want the scroll bar exactly shown in the below link.
http://www.little-neko.com/switcher/?theme=FatCatz
The scroll bar should not come where the navigation/top bar and it should start from the rest of content.
Please let me know, how to apply the css style to get partial scroll bar, which was shown in the above link. I hide the scroll bar by using the css style "body { overflow: hidden }", but not able to put the scroll bar in the child DOM node(div element).
It is an iframe, which is not recommended now a days.
<html>
<head>
<style>
.fixed{
z-index: 99999; //some very high value
position: fixed;
}
</style>
</head>
<body>
<div class="fixed">Fixed Content</div>
<iframe src="anyURL" frameborder="0" width="100%"></iframe>
</body>
</html>
Related question : Make fixed footer work with fixed header
Demo : http://jsfiddle.net/virendrachandak/cF2Fv/show/
I have solved my problem by using the below sample:
*
{
margin: 0;
padding: 0;
}
html, body, .Container
{
height: 100%;
}
.Container:before
{
content: '';
height: 100%;
float: left;
}
.Header
{
margin-bottom: 10px;
background-color: #6ea364;
}
.Content
{
position: relative;
z-index: 1;
}
.Content:after
{
content: '';
clear: both;
display: block;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.Wrapper > div
{
height: 100%;
}
.LeftContent
{
background-color: purple;
overflow: auto;
}
.RightContent
{
background-color: orange;
float: right;
margin-left: 10px;
}
http://jsfiddle.net/avrahamcool/QMsuD/
Half fixed, half scrollable layout that can be scrolled... CSS
Never use a i-frame for a website structure such as a header footer or anything for that matter. If you would like to accomplish a "sticky" header you need to use the proper bootstrap code for fixed to top.
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
...
</div>
</nav>
You can ready more about this at www.getbootstrap.com you can also look at the code here and see how they have accomplished this.
<!-- Fixed navbar -->
<div class="navbar navbar-default 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 class="navbar-brand" href="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Default</li>
<li>Static top</li>
<li class="active">Fixed top</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
You can see the working example here http://getbootstrap.com/examples/navbar-fixed-top/.
I have a top bar dropdown-menu in my bootstrap homepage.
The dropdown-menu starts under each menuitem.
I want to center the dropdownmenu on the page. (should start on the left side and end on the right side of my content-area which is 1280px)
HTML:
<div class="navbar">
<div class="navbar-inner">
<div class="container" style="width: 1280px;">
<ul class="nav" role="navigation">
<li class="dropdown">
<a id="drop1" href="#" class="dropdown-toggle menuitem" data-toggle="dropdown">nav1</a>
<ul class="dropdown-menu" aria-labelledby="drop1" style="width:1180px;">
<li role="presentation"><a role="menuitem" tabindex="-1" href="http://google.com">Action</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#anotherAction">Another action</a></li>
</ul>
</li>
</div>
</div>
</div>
you can get your container to be relative, get your li.dropdown to be absolute with left:0.
CSS:
.container{
position:relative;
}
li.dropdown ul.dropdown-menu{
position:absolute;
left: 0;
top: 0 /*according to your menu height */
width: 1280px;
}
hope this helps.