I'm trying to put a button in between bootstrap columns using position absolute.
My problem is that once my button enters another column, the button goes under the column instead going over it.
What I want to Achieve
What I have
My Html code:
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-3">
<ol>
<li>
Option
<button class="btn btn-default feedback-option--feedback-button">PressMe</button>
</li>
<li>
Option
<button class="btn btn-default feedback-option--feedback-button">PressMe</button>
</li>
<li>
Option
<button class="btn btn-default feedback-option--feedback-button">PressMe</button>
</li>
</ol>
</div>
<div class="hidden-xs col-sm-9">
Main Body
</div>
</div>
</div>
my CSS
.feedback-body--main-content {
background-color: #003B59;
}
.feedback-sidebar--main-content {
background-color: red;
}
.global--row-no-padding [class*="col-"] {
padding-left: 0 !important;
padding-right: 0 !important;
}
.feedback-option--feedback-button {
position: absolute;
top: -10px;
right: -30px;
}
.feedback-option-content {
position: relative;
list-style-type: none;
}
Mozilla has a good write-up of the order in which things are put on top of each other. Here's a summary:
Elements that appear first in the markup go under those that appear later.
Within each context (generally just the whole page), you can specify what order things stack with a z-index. Higher numbers are on top of smaller numbers.
Usually when absolutely positioning things you'll need to give it a z-index for it to show up right, assuming you'd like to keep your code in a semantically sensible order.
Related
Kindly help and let me know where am i making the mistake as i can not make the options in the navbar go into the right side. Here i am sharing the code.
<div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" style="padding-left: 40px; padding-right: 40px;">
<div style="float: left;">
<a class="navbar-brand" href="homePage.php">Job Portal</a>
</div>
<div class="topnav-right" style="float: right;">
<a href="homePage.php">
<button class="btn btn-outline-success" type="button" >
Home
</button>
</a>
<a href="signinPageOfJobSeekers.php">
<button class="btn btn-outline-success" type="button">
Sign In or Sign up
</button>
</a>
<button class="btn btn-outline-success" type="button">
Contact Us
</button>
<?php if(!empty($_SESSION['userName'])){ ?>
<a href="logOut.php">
<button class="btn btn-outline-success" type="button">
Log Out
</button>
</a>
<?php } ?>
</div>
</nav>
</div>
Your code is not enough to give you a perfect solution. However, here is my shot:
I assume that the wrapper container <div> ... </div> you have spans 100% of the viewport width? If this is the case, you can add the following style attribute:
<div style="display: flex; justify-content: flex-end;">
<nav>
// rest of the HTML code in your example
</nav>
</div>
Of course, for a cleaner solution, instead of adding an inline style attribute, you can add a CSS class and style it in a separate stylesheet file or style tag in your document <head>:
<div class="nav-wrapper">
<nav>
// rest of the HTML code in your example
</nav>
</div>
and then in your CSS declarations
.navWrapper {
display: flex;
justify-content: flex-end;
}
Alternative solution
If you are okay with your navigation overlapping the rest of the page content, you can always position: fix it. This way it would be taken out of the document flow and overlayed on top of the other HTML elements on your page. Here is the CSS needed:
.nav-wrapper {
position: fixed;
top: 0px;
right: 0px;
z-index: 999; // <- increase this value if any elements are on top of your nav
}
Have you considered using a flex box?
https://www.youtube.com/watch?v=K74l26pE4YA
Flex box is super useful for things like positioning and layout of items in a list. Check out some of the ways you can justify content: https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
Also, each individual, item can be aligned with align-self.
It's a fairly powerful way or organizing content. We can't see all of your css at the time of answering this question, but I'd take a look at the first video if you aren't already using a flexbox or to see how it works if you have a bug with one. It might work for you in this case!
So I'm using Bootstrap 4's Jumbotron to style a landing page. Inside the jumbotron I have the standard headings and paragraphs with 2 call to action buttons. I have wrapped these elements in a div to position them correctly for a desktop screen. however when I shrink the window, the elements fall out of the jumbotron and mess up the look of the page.
Here is how it looks on desktop
And Here is how it looks on "mobile"
I hope you can see what I mean from the images. The background image of the jumbotron is perfectly responsive but the contents (text, buttons) are overflowing down the page.
Here is the relevant html
<div class="jumbotron jumbotron-fluid">
<div class="jumboContents">
<h1 class="display-3">Welcome to Other Mother!</h1>
<p class="lead">Scroll Down To See Whats On Offer</p>
<hr class="my-4">
<p>Click Below To Start Shopping or Make a Request Instantly</p>
<p class="lead">
<a class="btn btn-info btn-lg" href="#" role="button">Shop Now</a>
<a class="btn btn-info btn-lg" id="contactBtn" href="#" role="button">Contact OM</a>
</p>
</div>
</div>
And Here is the relevant CSS
.jumbotron {
position: relative;
top: -170px;
height: 100vh;
background-image: url(images/homepg.jpg);
background-size: 100% 100%;
margin: 0 auto;
color: white;
z-index: -1;
}
.jumboContents {
position: relative;
top: 30%;
left: 30%;
}
I suggest using the bootstrap grid classes on your divs to let them stack properly when shrunken screen. (ex: div class="col-md-4 col-sm-1")
I´m new here, and I have a bit of a struggle with a, most lightly, simple problem.
I want to use the glyphicon-arrow-right, as a button, with the text "to test" centered inside it, is there an easy way to do this? I have this code line atm:
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<a class="btn btn-default" style="color:green" href="textview" id="totestarrow">
<span style="font-size:10em;" class="glyphicon glyphicon-arrow-right">
</span><br>Til testene
</a>
</div>
With this I get a green arrow pointing right, with the text centered underneath it. so how do I manage to put it inside of the arrow?
Thanks!
You can set your button to use position:relative, which will cause all of the elements within it to be positioned relative to it and simply use position:absolute on your actual <span> containing your text and adjust the top and left properties to get it in the proper position :
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<a class="btn btn-default" style="color:green; position: relative;" href="textview" id="totestarrow">
<span style="font-size:10em;" class="glyphicon glyphicon-arrow-right"></span>
<span class='centered-text'>
Til testene
</span>
</a>
</div>
<style>
.centered-text {
/* This will cause your element to be positioned freely over it's container */
position: absolute;
/* This will bring the element roughly halfway down the existing element */
top: 47%;
/* Colored white to stand out */
color: white;
/* The following styles will center the element in it's container */
text-align: center;
left: 0;
width: 100%;
}
</style>
You can see an example of this here and the output demonstrated below :
I have a page that looks like this:
The Active "SORT BY..." button and the inactive button next to it, I needed to not scroll when I scrolled through the list below it. To accomplish this I have the two side by side button drops down codded like this:
<!-- Start Drop Down Menu -->
<div class="row" style="height: 300px; width: 100%; position: fixed; top: 74px; background: transparent; z-index:2; overflow: hidden;">
<div class="col s6">
<!-- Dropdown Trigger -->
<a class='dropdown-button btn' href='#' data-activates='dropdown1' style="width: 100%;">Sort By...</a>
<!-- Dropdown Structure -->
<ul id='dropdown1' class='dropdown-content'>
<li>Brewery</li>
<li>Rating</li>
<li>Style</li>
</ul>
</div>
<div class="col s6">
<!-- Dropdown Trigger -->
<a class='dropdown-button btn disabled' href='#' data-activates='dropdown2' style="width: 100%;"></a>
<!-- Dropdown Structure -->
<ul id='none' class='dropdown-content'>
<li>All</li>
<li>Brewery</li>
<li>Rating</li>
<li>Style</li>
</ul>
</div>
</div>
As you can see in the Style part of the above code:
style="height: 300px; width: 100%; position: fixed; top: 74px; background: transparent; z-index:2; overflow: hidden;"
I position it and place it fixed so it will not move when I scroll the list below. You may be looking at it and wounder why I have the height 300px when the buttons are not that big...Its because when you click the button it opens a drop down. If I have the height the same height as the button then I can see most of the drop down that open....I thought this fixed my issues but this leads to my current issue. Since the button technically drops down 300px it overlaps the first two entries in the list which makes them not clickable.... causeI am clicking on the transparent css that is covering them up.
For the list, I am adding that into this div with this style:
<div style="height: 35px; position: relative; top:60px; z-index:1;">
<div id="replace"> </div>
</div>
In short, how can I have the drop down buttons pin to their location and still be viewable when opened and at the same time still be able to click on all my entries in my list?
You should not need to set the height of your .row div to 300px. Instead, remove the overflow:hidden style, which is causing your dropdowns to get cut off.
Also, you should be breaking your CSS out into a separate file, to separate style from content.
Finally, I would add that the background should not be transparent - try it, you'll see text scrolling behind the buttons.
.row {
background: #fff;
height: 35px;
width: 100%;
position: fixed;
z-index: 10;
}
I'm tring to make a little toolbar right next to a header. So I thought list-inline ought to work pretty well. And it works, but the alignment is off and I can't seem to figure it out.
<ul class="list-inline">
<li><h3>Editor</h3> </li>
<li><div class="btn-toolbar editor toolbar" role="toolbar">
<div class="btn-group">
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">right</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">other</button>
</div>
</div>
</li>
</ul>
http://jsfiddle.net/yhaJG/1/
The following CSS might be what you're looking for. Hard to tell exactly what you want from the question though.
.list-inline { margin-top: 5px; }
.list-inline li { vertical-align: top; }
.list-inline h3 { margin-top: 6px }
Just adjust the margin-top values as needed.
JSFiddle: http://jsfiddle.net/yhaJG/7/
Also, you might want to add another class to the ul element and apply the styles to that. You can still leave list-inline on the ul element, but that way these styles won't be applied to every list-inline since there may be other uses for inline lists on your site.