bootstrap 3 - fixed side bar to full column width - html

I have two columns (col-md-8 and col-md-4). The second column contains a fixed side bar. I want the side bar to be 100% width of the col-md-4 column. The black box as seen in the image below is the second column.
I have tried width 100% but it does not work.
Here's my HTML.
.col-md-4 {
border-style: solid;
}
.sidebar-nav-fixed {
height: 100%;
width: 15%;
text-align: center;
}
.well {
height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="">
<h1>Hello, world!</h1>
</div>
</div>
<div class="col-md-4">
<div class="sidebar-nav-fixed affix">
<div class="well" id="world">
<ul class="nav ">
<li class="nav-header">Sidebar</li>
<li class="active">Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li class="nav-header">Sidebar</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li class="nav-header">Sidebar</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
<!--/.well -->
</div>
</div>
</div>
<!--/row-->
</div>

position:fixed element is supposed to define everything (including width) in relation to the viewport.
The only way in css to set width according to it's parent div is width:inherit
or if jquery is allowed you can use following code.
$(document).ready(function() {
var new_width = $('.col-md-4').width();
$('.sidebar-nav-fixed').width(new_width);
})
$(window).resize(function(){
var new_width = $('.col-md-4').width();
$('.sidebar-nav-fixed').width(new_width);
})
.col-md-4 {
border-style: solid;
}
.sidebar-nav-fixed {
height: 100%;
width: 15%;
text-align: center;
}
.well {
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="">
<h1>Hello, world!</h1>
</div>
</div>
<div class="col-md-4">
<div class="sidebar-nav-fixed affix">
<div class="well" id="world">
<ul class="nav ">
<li class="nav-header">Sidebar</li>
<li class="active">Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li class="nav-header">Sidebar</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li class="nav-header">Sidebar</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
<!--/.well -->
</div>
</div>
</div>
<!--/row-->
</div>

Related

How can I make a card with the header fixed in bootstrap 4

I have a type card:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class='card'>
<div class='card-header'>
<div class='row'>
<div class='col'>
<h5 class='mb-0'>Element</h5>
</div>
<div class='col'>
<p class='text-right mb-0'>n</p>
</div>
</div>
</div>
<ul class='list-group list-group-flush'>
<li class='list-group-item'>Item 1</li>
<li class='list-group-item'>Item 2</li>
<li class='list-group-item'>Item 3</li>
<ul>
<div class='card-footer'>
<div class='input-group'>
<input type='text' class='form-control' placeholder='New item'>
<div class='input-group-append'>
<button class='btn btn-outline-secondary' type='button'> + </button>
</div>
</div>
</div>
</div>
The more items are added, the more the header where the number of items comes from is moved.
How can I make it stay in position when the items are more?
I tried sticky-top but it's stuck all the way to the top so it has a margin or padding on top.
that would be my approach:
basicaly: set position:relative to parent element (.card) and position:fixed to child element (.card-header)
.card{
position: relative; /* all child elements gets positioned relative to this element */
}
.card-header{
position: fixed; /* stay fixed on top */
top: 0;
width: 100%;
z-index: 1; /* needed to stay above other elements */
}
.list-group{
padding-top: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class='card'>
<div class='card-header'>
<div class='row'>
<div class='col'>
<h5 class='mb-0'>Element</h5>
</div>
<div class='col'>
<p class='text-right mb-0'>n</p>
</div>
</div>
</div>
<ul class='list-group list-group-flush'>
<li class='list-group-item'>Item 1</li>
<li class='list-group-item'>Item 2</li>
<li class='list-group-item'>Item 3</li>
<li class='list-group-item'>Item 4</li>
<li class='list-group-item'>Item 5</li>
<li class='list-group-item'>Item 6</li>
<li class='list-group-item'>Item 7</li>
<li class='list-group-item'>Item 8</li>
<li class='list-group-item'>Item 9</li>
<ul>
<div class='card-footer'>
<div class='input-group'>
<input type='text' class='form-control' placeholder='New item'>
<div class='input-group-append'>
<button class='btn btn-outline-secondary' type='button'> + </button>
</div>
</div>
</div>
</div>
You need to apply css to your ul for fixed card header when item increase. You can change ul height as suitable as you.
.list-group-flush{height:400px;overflow-y:auto;}
.list-group-flush{height:400px;overflow-y:auto;}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class='card'>
<div class='card-header'>
<div class='row'>
<div class='col'>
<h5 class='mb-0'>Element</h5>
</div>
<div class='col'>
<p class='text-right mb-0'>n</p>
</div>
</div>
</div>
<ul class='list-group list-group-flush'>
<li class='list-group-item'>Item 1</li>
<li class='list-group-item'>Item 2</li>
<li class='list-group-item'>Item 3</li>
<li class='list-group-item'>Item 1</li>
<li class='list-group-item'>Item 2</li>
<li class='list-group-item'>Item 3</li>
<li class='list-group-item'>Item 1</li>
<li class='list-group-item'>Item 2</li>
<li class='list-group-item'>Item 3</li>
<li class='list-group-item'>Item 1</li>
<li class='list-group-item'>Item 2</li>
<li class='list-group-item'>Item 3</li>
<ul>
<div class='card-footer'>
<div class='input-group'>
<input type='text' class='form-control' placeholder='New item'>
<div class='input-group-append'>
<button class='btn btn-outline-secondary' type='button'> + </button>
</div>
</div>
</div>
</div>

hover the sidebar vertical menu display a submenu in bootstrap material design

How to make a display of three columns as one submenu while hovering each menu.
<div class="container">
<div class="row">
<div class="col-sm-4">
<ul class="vertical-nav">
<li>Link 1</li>
<li>Link 2
<ul class="sub-menu">
<li>Sub Link 1</li>
<li>Sub Link 2</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
I want to make the menu like this below image
Please see below. Hope this helps.
$('.vertical-nav li a').mouseover(function() {
$(this).parent().find('.sub-menu').show();
})
.mouseout(function() {
$(this).parent().find('.sub-menu').hide();
});
.sub-menu {
display:none;
}
.vertical-nav li, .sub-menu li {
list-style:none;
}
.column {
float:left;
width: 100px;
}
.title {
padding-bottom: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-4">
<ul class="vertical-nav">
<li>Link 1</li>
<li>Link 2
<ul class="sub-menu">
<div class='column'>
<li class='title'>Style</li>
<li>Sub Link 1</li>
<li>Sub Link 2</li>
</div>
<div class='column'>
<li class='title'>Subject</li>
<li>Sub Link 3</li>
<li>Sub Link 4</li>
</div>
<div class='column'>
<li class='title'>Medium</li>
<li>Sub Link 5</li>
<li>Sub Link 6</li>
</div>
</ul>
</li>
</ul>
</div>
</div>
</div>

How to center text vertically within bootstrap container

I'm trying to center text vertically within a div bootstrap container. This is my sample HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
.vcenter {
display: inline-block;
vertical-align: middle;
float:none;
}
</style>
</head>
<body>
<div class="container">
<nav class="navbar navbar-default vcenter ">
<ul class="list-inline vcenter" >
<li class="menuFont">Menu 1</li>
<li class="menuFont ">Menu 2</li>
<li class="menuFont ">Menu 3</li>
<li class="menuFont ">Menu 4</li>
<li class="menuFont ">Menu 5</li>
<li class="menuFont ">Menu 6</li>
<li class="menuFont ">Menu 7</li>
</ul>
</nav>
</div>
</body>
</html>
I would like the menu text centered vertically within the container, but they are hugging the top. How would I do this?
I worked on this last night and this is what I came up with:
My goal using Bootstrap, was to have a series of menu links running horizontally across the page. For some reason, doubtless due to my ignorance, this proved rather difficult. I did come up with a solution. At least this seems to work, OK. HOWEVER, in order to make the horizontal menu items appear vertically centered within the container, I had to add margin-top: 3px to the class view. This feels kind of fake to me, but whatever works works, I guess. Any comments are appreciated.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TEST</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"> </script>
<style>
.view {
margin-left: auto;
margin-right: auto;
overflow: hidden;
margin-top: 3px;
}
</style>
</head>
<body>
<div class="container">
<div class="Jumbotron">
<h1 class="text-primary text-center">Using Bookstreap.js</h1>
<hr>
</div>
<nav class="navbar navbar-default view ">
<div class="container-fluid view">
<div class="row">
<div class="col-lg-10 col-lg-offset-10 view" >
<ul class="list-inline view" >
<li class="view">Menu 1</li>
<li class="view">Menu 1</li>
<li class="view">Menu 2</li></li>
<li class="view">Menu 3</li>
<li class="view">Menu 4</li>
<li class="view">Menu 5</li>
<li class="view">Menu 6</li>
</ul>
</div>
</div>
</div>
</nav>
<div>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
{
display: inline-block;
vertical-align: middle;
float:none;
}
</style>
</head>
<body>
<div class="container">
<nav class="navbar navbar-default vcenter " >
<div class="container-fluid vcenter">
<div class="col-lg-5 col-lg-offset-5" >
<ul class="list-inline vcenter" >
<div>
<li class="menuFont">Menu 1</li>
<li class="menuFont ">Menu 2</li>
<li class="menuFont ">Menu 3</li>
<li class="menuFont ">Menu 4</li>
<li class="menuFont ">Menu 5</li>
<li class="menuFont ">Menu 6</li>
<li class="menuFont ">Menu 7</li>
<div>
</ul>
</div>
</div>
</nav>
</div>
</body>
</html>

Dropdown menu problems

I got this problem that when I hover on my dropdown menu, the background changes and the color does also. But i can't get it to white..
What to do?
http://hcl.konggulerodhosting.dk/index.html
<nav>
<div id="topBar" data-toggler="is-active" class=" top-bar row ">
<button type="button" data-toggle="topBar" class="mobile__close hide-for-large"> </button>
<div class="small-12 columns">
<div class="top-bar-left">
<div class="site-logo"><img src="assets/images/logo.svg" alt=""></div>
</div>
<div class="top-bar-right">
<p class="mobile__headline hide-for-large">Menu</p>
<ul data-responsive-menu="drilldown large-dropdown" data-back-button="<li class="js-drilldown-back drilldown-back"><a>Back</a></li>" class="menu">
<li class="active">Forside</li>
<li>Undersøgelser
<ul class="menu">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
</ul>
</li>
<li>Tilskud</li>
<li>Høreapparat</li>
<li>Information</li>
<li>Om os</li>
<li class="search__toggler">
<button type="button" data-toggle="search" id="search-toggler"></button>
</li>
</ul>
</div>
</div>
</div>
</nav>
.is-dropdown-submenu-item {
color:white;
}
is not working. So i dont know what to do..
Please don't link your site as it's bad for archiving purposes.
You need to change the link colour.
.is-dropdown-submenu-item a:hover {
color:#fff;
}
Check this image.............................................

How to center text in lists?

I'm trying to make a website footer inspired by the w3schools 4 column footer, however, the text in the li tags go off to the right a little (compared to the headings).
CSS:
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 100px;
}
footer {
position: absolute;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
}
#footer {
width: 100%;
margin: auto;
}
.footerFloat {
width: 100%;
}
#media all and (min-width: 950px) {
#footer {
width: 980px;
margin: auto;
}
.footerFloat {
width: 25%;
float: left;
display: block;
}
}
#wrapper {
width: 100%;
overflow: hidden;
}
ul {
list-style: none;
}
.center {
text-align: center;
}
HTML:
<header></header>
<footer>
<div id="wrapper">
<div id="footer">
<div class="footerFloat">
<h4 class="center">Header 1</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
<div class="footerFloat">
<h4 class="center">Header 4</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
<div class="footerFloat">
<h4 class="center">Header 3</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
<div class="footerFloat">
<h4 class="center">Header 4</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
</div>
</div>
</footer>
Here is a picture of the problem.
Does anyone know how I could fix this, and centre the text with the headings in the footer?
Any help would be greatly appreciated, thanks.
—ItzJavaCraft
Remove the padding which is built into the ul by default.
.footerFloat {
width: 25%;
float: left;
}
#wrapper {
width: 100%;
overflow: hidden;
}
ul {
list-style: none;
padding: 0; /* here---add this */
}
.center {
text-align: center;
}
<footer>
<div id="wrapper">
<div id="footer">
<div class="footerFloat">
<h4 class="center">Header 1</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
<div class="footerFloat">
<h4 class="center">Header 4</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
<div class="footerFloat">
<h4 class="center">Header 3</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
<div class="footerFloat">
<h4 class="center">Header 4</h4>
<ul>
<li class="center">Line 1</li>
<li class="center">Line 2</li>
<li class="center">Line 3</li>
<li class="center">Line 4</li>
</ul>
</div>
</div>
</div>
</footer>