I am trying to create a header on a website that consists of a table with two columns.
The column on the left should have an only row with the Logo, instead, the column on the right should have two rows.
The first row should have the contacts of the socials ,
while the second and final row should have a responsive navbar ( aligned on the right obviously ).
Is it possible to obtain this with Bootstrap?
One solution I thought about could be a table with two columns, with the row on the left consisting of the logo, and the row on the right that consists of the socials links.
Then below that table I would implement the usual responsive navbar.
Obviously I rather prefer to implement the first solution, but if a solution with Bootstrap is not possible I will probably go for the second solution.
I would gladly appreciate any advice or comment that is positive toward that goal.
Thank you so much for your time!
This is the code I got so far:
<tc>
<tr>
<th>Image</th>
</tr>
</tc>
<tc>
<tr>
<th>Social</th>
</tr>
<tr>
<td>
<nav class ="navbar navbar-dark bg-dark navbar-expand-sm ">
<button type = "button" class="navbar-toggler" data-toggle="collapse" data-target="#topNav"> <span class="navbar-toggler-icon" ></span> </button>
<div id="topNav" class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active"> Home </li>
<li class="nav-item">I nostri gelati</li>
<li class="nav-item"> La nostra storia</li>
<li class="nav-item"> Perchè così buono</li>
<li class="nav-item"> Trovaci </li>
</ul>
</div>
</nav>
</td>
</tr>
</tc>
</table>
Here's a pure Bootstrap solution to get you started:
https://codepen.io/panchroma/pen/djaNgo
The simplified code showing the grid layout is
<div class="container">
<div class="row">
<div class="col-md-3">logo</div>
<div class="col-md-9">
<div class="container">
<div class="row justify-content-end">social links</div>
<div class="row justify-content-end">
<!-- navbar here -->
</div> <!-- row -->
</div> <!-- container -->
</div> <!-- col-md-9 -->
</div> <!-- row -->
</div> <!-- container -->
As you can probably see, if you want to build this using native Bootstrap classes you would have a row with two columns.
The left-hand column holds the logo, and then in the right-hand column you have a nested container which has rows for your social links and your navbar.
I've used the class of .justify-content-end to right-align the social links and the nav-bar.
I hope this helps!
Related
I've written something of a 'custom' nav bar using Bootstrap 4.5.
Basically, it's two columns/grids with a logo in the right column and a list that acts as a nav bar in the other.
I am really pleased with how it looks on a laptop/computer/tablet etc:
But it looks awful on mobile because the logo is aligned to the left (inherited, not actually using anything to align it left) and the list is aligned to the right (class="... text-right ...").
I'd like to make it so both the logo and list are aligned center on smaller mobile. I've tried a few things, like using an #media attribute in css with float:center;, and the only other way I can think to do this is to make the normal nav bar hidden/invisible on mobile and add a new one that's only visible on mobile, but I really don't want to have to do that as it'd mean I'd have to add links to the list twice etc.
I also tried aligning just the list center with this documentation: https://getbootstrap.com/docs/4.0/utilities/text/, but it didn't work.
My current nav-bar is:
<div class="topsection">
<div class="container">
<div class="row">
<div class="col-sm">
<img class="img-responsive" src="https://cdn.example.com/img/logo2.png" height="50px">
</div>
<div class="col-sm align-baseline">
<p><ul class="list-inline text-right font1">
<li class="list-inline-item active-nb">Home</li>
<li class="list-inline-item">Projects</li>
<li class="list-inline-item">My Work</li>
<li class="list-inline-item">Feed</li>
</ul></p>
</div>
</div>
</div>
</div>
<hr class="main">
(The attributes main and topsection aren't important, they just style the backgrounds of things etc)
Currently, it looks like this on mobile:
Use the Bootstrap utility classes. Alignment is already responsive...
<div class="topsection">
<div class="container">
<div class="row justify-sm-content-between justify-content-center">
<div class="col-sm col-auto">
<img class="img-responsive" src="//placehold.it/120x50" height="50px">
</div>
<div class="col-sm">
<ul class="list-inline text-sm-right text-center py-2 font1">
<li class="list-inline-item active-nb">Home</li>
<li class="list-inline-item">Projects</li>
<li class="list-inline-item">My Work</li>
<li class="list-inline-item">Feed</li>
</ul>
</div>
</div>
</div>
</div>
Demo
.your-class{
display:flex;
place-content:center;
}
should work with basic css.
My web application has some areas placed in the page. Basically:
<body>
<nav> <-- top nav bar
<ol> <-- breadcrumb
<div> <-- row with buttons
<div class="overflow-auto">
<table> <-- run-time growing table
</div>
<footer> <-- sticky footer
</body>
At run-time my scripts add rows to the table.
To get the overflow-auto class working I have to set a max-height value.
If I set it to 100% it just grows like without overflow. It works if I set a px value only.
My goal, instead, is to fill all the available space (so it depends on the browser, width, etc...) between the previous div (row with buttons) and the sticky footer.
In other words, I want the user always sees the footer so when the table reach it, the overflow feature should begin to work.
I don't understand if this can be easily handled with some specific classes or I have to manually compute the available height (if even possible...).
UPDATE
I cannot manage it to work with a sidebar. Complete code:
<body class="vh-100 d-flex flex-column overflow-hidden">
<nav id="nav_top" class="navbar navbar-expand navbar-dark bg-dark static-top">
<ul class="navbar-nav d-none d-md-inline-block form-inline ml-auto mr-0 mr-md-3 my-2 my-md-0">
<li class="nav-item">
<h5>
<span class="badge badge-secondary">BLABLA</span>
</h5>
</li>
</ul>
</nav>
<div id="wrapper">
<ul class="sidebar navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.php">
<span>NAV 1</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php">
<span>NAV 2</span>
</a>
</li>
</ul>
<div id="content-wrapper">
<div class="container-fluid">
<ol class="breadcrumb">
<li class="breadcrumb-item">
Home
</li>
<li class="breadcrumb-item active">Current page</li>
</ol>
<button type="button" class="btn btn-info mb-3">BUTTON</button>
<div id="content" class="row overflow-auto">
<div class="col-12 table-responsive">
<table id="tableParameters" class="table table-sm">
<thead class="thead-light">
<tr>
<th scope="col">COL 1</th>
<th scope="col">COL 2</th>
<th scope="col">COL 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>table</td>
<td>table</td>
<td>table</td>
</tr>
<tr>
<td>table</td>
<td>table</td>
<td>table</td>
</tr>
<tr>
<td>table</td>
<td>table</td>
<td>table</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
It's not clear to me what affect the overflow-auto behavior. I need the row/col divs in order to keep margins.
I think you'd want to use flexbox for this...
<body class="vh-100 d-flex flex-column overflow-hidden">
<nav> <-- top nav bar -->
<ol> <-- breadcrumb -->
<div> <-- row with buttons -->
<div class="overflow-auto">
<table> <-- run-time growing table -->
</div>
<footer class="mt-auto"> <-- sticky footer -->
</body>
vh-100 - makes the entire body viewport height
d-flex flex-column - make the body display:flex, flex-direction:column
overflow-hidden - prevents the body from scrolling
mt-auto - to make the footer stick the the bottom
Demo: https://www.codeply.com/go/FSrBOdRVFG
Basically this has been answered before:
Bootstrap 4 row fill remaining height
How to make the row stretch remaining height
Bootstrap 4: Scrollable row, which fills remaining height
Hi I have a nav into a container and I want to center all elements:
<!-- Main container -->
<div class="container align-content-center">
<!-- Navigation bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top mx-auto">
<!-- Link to home page -->
<a class="navbar-brand" href="#">HOME</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>
<!-- Search bar -->
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
</form>
</nav>
</div>
More specifically I want all nav items to be aligned at the center of the container component
GJCode,
Here is an example of using Bootstrap classes and some HTML wrappers to center align the menu: https://jsfiddle.net/learnwithclyde/sm2bz4kL/
<div class="container">
<div class="col-sm-6 col-sm-offset-3">
<!-- Menu elements like brand and navigation -->
</div>
</div>
The class container is for making the width a narrower than container-fluid.
col-sm-6 is setting the width for the elements in the div, i.e, the width of this div is going to be 6 columns max.
And finally, the col-sm-offset-3 is center align the div. col-sm-offset-3 simply adds a 3-column space before the div and 3-column space after the div. This totals to 6 columns.
Therefore, the total number of columns become 12 (6 from col-sm-6 and 6 from col-sm-offset-3).
Note: depending on the contents of your menu, you might need to adjust the values of col-sm-6 and col-sm-offset-3 but this should help you understand the concept itself.
Grid system
Use mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, five default responsive tiers, Sass variables and mixins, and dozens of predefined classes.
How it works
Bootstrap’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with flexbox and is fully responsive. Below is an example and an in-depth look at how the grid comes together.
New to or unfamiliar with flexbox? Read this CSS Tricks flexbox guide for background, terminology, guidelines, and code snippets.
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>
I just started learning HTML and CSS a week ago, and have been learning using coursera and codeacademy. I wanted to make a simple website using bootstrap, with a navigation bar on top, and a big cover pic below that.
The code looks as follows.
<body>
<header class="container">
<div class="logo"> <!--this is where the logo resides-->
<div class="row"> <!--making a row for header elements-->
<figure class="col-xs-7">
</figure>
<div class="col-xs-5" > <!--adds the 3 buttons on top right-->
<button type="button">
<em class="cogs"> </em>
</button>
<button type="button">
<em class="cogs"> </em>
</button>
<button type="button">
<em class="cogs"> </em>
</button>
</div>
</div>
</div>
</div>
</header>
<div class="jumbotron">
<div class="row">
<figure class="col-xs-12"> </figure> <!--cover pic-->
</div>
</div>
</body>
</html>
When I open the html in the browser (with the style sheet), I get the image attached. enter image description here. I though the cover pic would automatically align within the 12 column grid below the navigation bar on top, cropping out the sides. My questions are:
1. Doesn't adding an image automatically fit it in the 12 grid system?
2. How do I push the 3 icons on top to the right of the navigation bar (i.e to the right of the column)?
Thanks a ton guys! I'm grateful for any advise or suggestions in advance.
I think the jumbotron class is formatted purposely to reach the edges of the page.
If I am understanding your question correctly in that you do not want the jumbotron to extend to the edge of the screen, you may want to Place the jumbotron inside the div class="container" as W3CSchools suggests
Bootstrap v3 is neat because it has already created tools like the nav bar. You could try using an using the "< nav >" tag and an unordered list like so:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<!--- image of your logo -->
</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
</div>
</nav>
I am using Bootstrap3 and using a collapsible element to in my design.
I am using 12 column inside the row as follows
<!-- Search Filter -->
<div id="search-filter">
<div class="container">
<div class="row">
<div class="col-md-5 col-xs-12">
<!-- Collapse Search -->
<button type="button" class="navbar-toggle navbar-toggle-search-filter" data-toggle="collapse" data-target="#searchbar-collapse-set"> <span class="sr-only">Toggle navigation</span> <span class="glyphicon glyphicon-chevron-down"></span> </button>
<!-- /Collapse Search -->
<h3>Showing 345 Results <small>(Hill Stations around Bangalore)</small></h3>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="searchbar-collapse-set">
<div class="col-md-4 col-xs-12">
<div class="distance">
<h5>distance:</h5>
<div id="distance-slider"></div>
<span class="distance-value">250 kms</span>
</div>
</div>
<div class="col-md-3 col-xs-12">
<div class="sort">
<h5>sort:</h5>
<ul class="nav nav-pills">
<li class="active">popular</li>
<li>name</li>
<li>distance</li>
</ul>
</div>
</div>
</div>
<!-- /.navbar-collapse -->
<div class="clearfix"></div>
</div>
</div>
</div>
<!-- /Search Filter -->
Due to the Collapsible element i the third column is shifting to the next row.
I removed the NavCollapse padding to 0 and the content disappears from the drop down as bellow.
By Adding the following code it gets back into place as bellow.
But it Disrupts the full screen view as bellow.
Nomad Link
My suggestion is to use a media query such as
#media (min-width: 1200px) { ... }
so that you can add the padding on a desktop display without effecting the display on smaller devices.