I want to get my black navbar div to stretch completely across the screen. However, using width: 100% does change anything.
If anyone could give me advice on how to improve the way I created the navbar, it would be much appreciated.
https://codepen.io/vegetablecook/pen/qVgOPJ
HTML
<div class = "container">
<div class = "span12 text-center">
<h1>Bill Gates</h1>
</div>
</div>
<div class = "container" id = "nav-container">
<nav class = "navbar navbar-default">
<ul class = "navbar-nav flex-row ">
<li class = "nav-item"><a id = "special" href = "#"> Business Magnate</a></li>
<li class = "nav-item"> Investor</li>
<li class = "nav-item"> Philanthropist</li>
</ul>
</nav>
</div>
CSS:
body {
margin-top: 60px;
}
.navbar-nav > li{
padding-left: 30px;
padding-right: 30px;
}
.navbar-nav > li > a {
font-size: 40px;
color: white;
text-decoration: none;
}
#nav-container{
background-color:black;
width: 100%;
top: 0px;
width: 100%;
height: 100px;
}
#billgates-headshot{
width:40%;
}
#row2{
padding-top: 50px;
}
#billgates{
padding-left: 50px;
}
#billgates-midspeech{
width: 70%;
}
The "container" class in bootstrap isn't made to be 100%. You want to use the "container-fluid" class to span across the viewport. I've made some small changes which can be found at https://codepen.io/anon/pen/LeeMGy.
Documentation reference: https://getbootstrap.com/docs/3.3/css/#overview-container
Use .container for a responsive fixed width container.
<div class="container">
...
</div>
Use .container-fluid for a full width container, spanning the entire width of your viewport.
<div class="container-fluid">
...
</div>
It's your use of the container class - if you inspect the element using your developer tools you'll see that the child container is being padded by the parent container.
Remove the nested containers or move your nav outside of the scope of your parent container to fix this.
Related
I have this layout for an HTML page with :
Top menu
Left menu
Content div
HTML:
<div class='body-content app'>
<div class="top">
<div class="info"><div _ngcontent-c17="">Version:1.05.20.20 </div></div>
<div _ngcontent-c17="">
<a _ngcontent-c17="" class="ui link ng-star-inserted">Setup 1</a>
| <a _ngcontent-c17="" class="ui link custom-setup-link">Setup 2</a>
| <a _ngcontent-c17="" class="ui link logout-link"> Log out </a>
</div>
</div>
<div class="side-menu">
<div *ngFor="let item of items; let i = index">
Menu # {{i}}
</div>
</div>
<div class="content">
<div *ngFor="let item of items; let i = index">
Menu # {{i}}
</div>
</div>
</div>
CSS:
.top {
height: 44px;
background-color: #0078bf;
position: fixed;
top: 0;
width: 100%;
z-index: 3;
color:white;
}
.side-menu {
width:70px;
position: fixed;
top: 44px;
height: calc(100% - 44px);
background-color: #0078bf;
z-index: 2;
color:white;
}
.content
{
margin-left: 80px;
margin-top: 54px;
}
.content div{
padding-left: 80px;
height: 300px;
background-color:black;
margin:10px;
}
A demo of init code. I have a task to add font resizing via setup on UI. But I am having problems doing it, because menus are position fixed and top and height is constant in styles.
I can do it by recalculating it and changing using [style.top], [style.height] or [ngStyle] directive. But I want to get common solution with CSS and HTML, if it is possible.
I was also trying to change height, width and margin to em units, but it's not working for all scenarios with different size of fonts from 10px to 40px; I tried to remove some styles from the CSS that helped me with font-resizing.
height from .top class,
top and width from .side-menu class
margin-top and margin-left from .content class
padding from children divs of .content div
But I have an artifact during scrolling. A demo of what I have.
Using Sticky is not best solution you can try
position :relative;
Position sticky is something you use when you want a element to sticky while scrolling
for example refer this
I'm trying to teach myself how to effectively center things using bootstrap. Centering is something I really struggle with, even after reading a ton of other SO posts asking the same question.
Why do we have to wrap the cols in a row, and then wrap that row in a container? What does this actually do?
body {
background-color:pink;
}
.container {
overflow: hidden;
background-color: yellow;
}
.col-sm-6 {
float: left;
height: 100px;
width: 100px;
background-color: blue;
padding: 10px;
margin: 1%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class = "container">
<div class = "row">
<div class = "col-sm-6"></div>
<div class = "col-sm-6"></div>
</div>
</div>
JSFiddle
1 row have 12 cols for you're first code :
<div class = "container">
<div class = "row">
<div class = "col-sm-6"></div>
<div class = "col-sm-push-6"></div>
</div>
</div>
That means you're second div is after the first who takes 6 cols. So you push the second after the first (col-sm-push-6)
This is for the web-responsive, when you're website is on a computer or in a mobile phone, the screen have different size. Bootstrap adapt you're div to the screen.
They're is sm : for small screen, lg : for large screen and md : for middle screen like a tab for exemple.
Let me explain for you. I love to teach beginners :-)
Firstly when we use column of bootstrap it adds '15px' padding from
right and left. in this way our column looks like '15px' inside from
wall of container.
Secondly we use row to overcome the first situation given upper paragraph.
Thirdly if you are trying to align Centre 2 columns of 6 and 6 then it is impossible to do this because 2 col-sm-6
occupy whole container space.
Fourthly do r&d about bootstrap offset and push properties. also check bootstrap row and columns properties by using code inspector. thanks
If you use bootstrap, there is class ready made to build your layout :
https://getbootstrap.com/docs/4.0/utilities/flex/
Flex
Quickly manage the layout, alignment, and sizing of grid columns, navigation, components, and more with a full suite of responsive flexbox utilities. For more complex implementations, custom CSS may be necessary.
If you need cols of a fixed width, you might need to create your own class here .
example:https://jsfiddle.net/cLw2ajro/7/
body {
background-color: pink;
}
.container {
overflow: hidden;
background-color: yellow;
}
.mycol {
background-color: blue;
height:100px;
flex:0 0 100px
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row d-flex flex-nowrap justify-content-center">
<div class="mycol m-2 p-4"></div>
<div class="mycol m-2 p-4"></div>
</div>
</div>
Try this
CSS:
body {
background-color:pink;
}
.row-centered {
display:block;
text-align:center;
}
.col-centered {
display:inline-block;
float:none;
/* reset the text-align */
text-align:left;
/* inline-block space fix */
}
.container {
overflow: hidden;
background-color: yellow;
}
.col-sm-6 {
height: 100px;
max-width:100px;
background-color: blue;
padding: 10px;
margin: 1%;
}
HTML
<div class = "container">
<div class = "row row-centered">
<div class = "col-sm-6 col-centered">-</div>
<div class = "col-sm-6 col-centered">-</div>
</div>
</div>
Fiddle
Source: This question
I have a task to build a sidebar, whose height is equal to the content one.
The more content is, the bigger sidebar is.
In reality, my sidebar is equal to the window size, not content. If I scroll the page down, there is no sidebar on it.
That's me code:
HTML:
<div class = "container" style = "height :100%">
<div class = "row" style = "height:100%">
<div class = "col-md-3 hidden-xs hidden-sm" style = "height:100%">
<div class = "sidebar">
.........
</div>
</div>
</div>
</div>
CSS:
html .sidebar,
body .sidebar {
height: 100%;
width: 100%;
background: black;
}
Why? What to do to make it work?
If I get what you mean properly, then you want the sidebar to be fixed?
In order to do this you can do something a bit like this in the css..
.sidebar {
width: 250px;
height: 100vh;
position: fixed;
top: 0;
left: 0;
background: black;
}
<div class="sidebar">
</div>
This question has been asked a couple of times, but all are at least 4-5 years old from what I see. So I am wondering if there is a new better/easier way to do this.
I got a menu with a button in it, the menu will change in size according to the logo that is posted in it. So when I upload a large logo the menu is stretched in height, but the button stays the same height. The menubar has no specified height so height:100% will not work.
Image for more clarity:
The white bar is my menu, and the grey area my button.
The html markup:
<nav class="navbar navbar-default navbar-static-top m-b-0">
<div class="navbar-header">
<a class="navbar-toggle hidden-sm hidden-md hidden-lg " href="javascript:void(0)" data-toggle="collapse" data-target=".navbar-collapse"><i class="ti-menu"></i></a>
<div class="top-left-part"><a class="logo" href="index.php"><img style="height:100%;" src="logo.png" alt="home" /></a></div>
<ul class="nav navbar-top-links navbar-left hidden-xs">
<li><i class="icon-arrow-left-circle ti-menu"></i></li>
</ul>
<ul class="nav navbar-top-links navbar-right pull-right">
<li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#"><b class="hidden-xs"><i class="fa fa-user"></i> User</b> </a>
<ul class="dropdown-menu dropdown-user animated flipInY">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
</ul>
</div>
</nav>
Relevant css:
.navbar-default {
position: relative;
width: 100%;
top: 0;
}
.navbar-header {
background: #fff !important;
width: 100%;
border: 0;
}
.nav {
padding-left: 0;
margin-bottom: 0;
list-style: none;
}
.navbar-top-links > li > a {
color: #1f7db1;
padding: 0 12px;
line-height: 60px;
min-height: 60px;
}
.navbar-top-links > li > a:hover {
background: rgba(0, 0, 0, 0.1);
}
using CSS this could be down with display:table on parent and display:table-cell on the children. but i don't suggest you use that in your current situation because you have a bunch of divs there, navbars etc.
so i made a JQ solution. i hope you don't mind. it's very easy to understand and easy to modify if needed.
let me know if it helps
see fiddle here > Jsfiddle
JQ code :
var newHeight = $(".top-left-part").height()
$(".pull-right > li.dropdown > a.dropdown-toggle").height(newHeight)
to align the text vertically i added
a.dropdown-toggle {
display:flex
align-items:center;
}
Here is a proof-of-concept solution that may help. This solution uses CSS only and does not require JavaScript.
Let .wrap be the parent container that contains your navigation, logo and so on.
In .wrap, create a protected area to the right that will contain your button. Do this by specifying padding-right: 100px (for example) and then specify position: relative.
You can now define an element called .right-panel that will contain your button and so on. For .right-panel, specify position: absolute and set the offsets as top: 0 and bottom: 0 to force it to keep to the height of the parent block, and then right: 0 to pin it to the right of the parent and then set the width: 100px (for example).
As you change the content in the parent container, the .right-panel will take on the height of the parent in a responsive manner.
The limitation here is that you need to specify a width for the right-hand side panel/element, which may not be too limiting since you know something about the design of the button (such as its dimensions).
You might need to specify a min-height for the parent .wrap for cases where you have either no logo or a logo whose height is less than that of the intrinsic height of the button.
Note: If you are using a CSS framework like Bootstrap, you may need to do some more work fit this into a floated parent, but I have not tried it.
.wrap {
border: 1px dotted blue;
position: relative;
padding-right: 100px;
}
.right-panel {
border: 1px dashed gray;
position: absolute;
right:0;
top: 0;
bottom: 0;
width: 100px;
}
<div class="wrap">
<h1>Some header that can be text or a logo.</h1>
<p>Some content and so on.</p>
<div class="right-panel">
<p>A button or whatever.</p>
</div>
</div>
I've tried to move the address to far left corner but it didn't work at all.
This is what I tried to move the address to far left corner but so
far it didn't work at all.
<!-- Page Content -->
<div class="container">
<!-- Column address below -->
<div class="column">
<div class="row">
<div class="col-md-6">
<p class="example">
Baylight Construction LLC 1022 boyle street
<br>Tel- (232)233-4323 Fax-(232)233-2323
</p>
</div>
</div>
</div>
</div>
css:
.nav a {
color: white;
font-size: 15px;
font-weight: bold;
padding: 40px 35px;
text-transform: uppercase;
}
nav li {
display: inline;
}
img {
height: 175px;
width: 175px;
}
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
width: 100%;
height: 165px;
background-color: green;
}
//I've tried that class example and row and none of didn't move to
//far left corner
.example {
text-align: left;
float: left;
margin-left: 5px;
padding-left: 10px;
}
.row {
float: left;
}
I has try out this, try this and see click here
<div class="container">
<!-- Column address below -->
<div class="col-md-6 row col-md-pull-1">
Baylight Construction LLC 1022 boyle street
<br>Tel- (232)233-4323 Fax-(232)233-2323
</div>
</div>
Looking at your code example i'm guessing you're trying to use bootstraps own classes to position the adress. In that case the problem you're having is not that your elements with the class "example" isn't positioning themselves to the left inside their containers.
It's that the container class you're using has a fixed-width depending on the width of the screen, aswell as being centered in the screen. In your case the container class will have a width of:
Screen: < 768px : Width of container: (auto)
Screen: ≥ 768px : Width of container: 750px
Screen: ≥ 992px : Width of container: 970px
Screen: ≥ 1200px : Width of container: 1170px
In order for your container to take up the full width of the screen change the container class to container-fluid, wich is bootstraps class for a full width container.
Now instead of taking up a fixed width, the container will always take up 100% of the screens width, thus your adress bar will be placed to far left.
See your edited example
here or in the snippet down below.
//I've tried that class example and row and none of didn't move to
//far left corner
.example {
text-align: left;
float: left;
margin-left: 5px;
padding-left: 10px;
}
.row {
float: left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Page Content -->
<div class="container-fluid">
<!-- Column address below -->
<div class="column">
<div class="row">
<div class="col-md-6">
<p class="example">
Baylight Construction LLC 1022 boyle street
<br>Tel- (232)233-4323 Fax-(232)233-2323
</p>
</div>
</div>
</div>
</div>