Make icon appear on top right of the box - html

I would like to make the question mark on hover appear on the top right part of the white box. Currently, it is appearing on the bottom left part of the white box.
<div class="panel panel-default">
<div class="panel-heading">
Test
</div>
<div class="panel-body">
<div id="rptTitle">
<br />
<br />
Text here....... text here......
<br />
<br />
</div>
<div class="questionBox" data-original-title="More Information" data-toggle="tooltip" data-placement="top">
<i class="fa fa-question-circle grayColor"></i>
</div>
</div>
</div>
CSS:
.grayColor {
color: #A6A6A6;
}
.panel {
cursor: pointer;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #fff;
opacity: 0.8;
}
.panel:hover {
cursor: pointer;
border: 1px solid #eee;
background: #fff none repeat scroll 0 0;
opacity: 1;
}
.panel:hover .panel-heading {
background-color: #f6f6f6;
}
.panel .questionBox i {
font-size: 15px;
display: none;
}
.panel:hover .questionBox i {
font-size: 15px;
display: block;
}
JSFiddle
I tried using position:absolute; and using right, top but that wouldn't help me if I have multiple divs
UPDATE:

You should relatively position your outer panel and then you can absolutely position your icon.
Try the following solution:
.panel {
position:relative;
}
.fa.fa-question-circle {
position: absolute;
top: 0;
right: 0;
}
Fiddle
The reasoning for this is because absolutely positioning something positions an item relative to it's first ancestor element that is positioned non-statically. This is the reason for the relative positioning to the panel.
Picture a box. The box has a relative positioning. Anything inside of that box that is positioned absolutely has a maximum height/width of that box. So when you position the icon absolutely and use top: 0; right: 0, you get it to the top right of that box. In this case, the box is the panel.
UPDATE
Given your new criteria, you can try something like this:
#rptTitle {
display:inline-block;
width: 90%;
}
.questionBox {
display: inline-block;
float: right;
}
It's a quick and dirty solution, but fits your needs. Use the concepts to build it better :)
New Fiddle

You had the right idea with position:absolute; but you also need to set the parent element to position:relative;. Lastly add top:0px and right:0px to the question mark element.
With the updated post you will need to also move the div inside the div with the class panel-body and make sure panel-body is position:relative;.
JSFiddle

Try this:
.questionBox > * {
position: absolute;
top:65px;
right: 25px;
}
Live example:
(updated) https://jsfiddle.net/kow5np4q/7/
Another approach (without position: absolute)
https://jsfiddle.net/kow5np4q/8/
The 3rd approach:
https://jsfiddle.net/kow5np4q/10/
And with the 3rd approach, you don't need to use <br>s. Use padding instead.

Related

CSS: Set Inline element inside padding

I am looking at the Instagram website. I notice that they put a zoom icon inside the padding of adjacent input. I wonder how this is done, can somebody show me an example
Thanks.
Here is the example for jQuery search box on focus show hide icon as per your reference. I hope this answer will be helpful.
$('.btn-close').hide();
$('.fa-search').show();
$('.input-text').on('focus', function() {
$(this).siblings('.btn-close').show();
$(this).siblings('.fa-search').hide();
});
$('.btn-close').click(function(e) {
$('.fa-search').show();
$('.btn-close').hide();
e.stopPropagation();
});
$('.input-text').on('focusout', function() {
$(this).siblings('.btn-close').hide();
$(this).siblings('.fa-search').show();
});
.input-text {
border: 1px solid #888;
min-height: 40px;
font-size: 16px;
padding: 0 25px 0 5px;
}
.input-box {
position: relative;
display: inline-block;
}
.input-box .fas,
.btn-close {
position: absolute;
right: 0;
padding: 11px 4px;
top: 0;
color: #888;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="input-box">
<input type="text" class="input-text" placeholder="text">
<i class="fas fa-search"></i>
<a class="btn-close" href="#"><i class="fas fa-times-circle"></i></a>
</div>
The answer is that they don't actually put the icon inside the input box. The just draw a rectangle around both the icon and the <input>. The icon itself is added to the <span> on the line right after the highlighted <input> in the image in the question. Look for the class coreSpriteSearchIcon.
When I inspected that <span>, I saw these styles applied:
background-image:
url(/static/bundles/metro/sprite_core_2x_6ba81dcece9b.png/6ba81dcece9b.png);
}
background-size: 410px 396px;
background-position: -240px -366px;
height: 10px;
width: 10px;
The background-image is the sprite file (an image containing multiple smaller images). background-size ensure that the image isn't stretched. background-position tells you where to find the search icon within the larger sprite image. And, width and height tell you how much of the image to display.
They were able to place it where it is by using absolute positioning:
left: 11px;
position: absolute;
top: 9px;
z-index: 2;
One of the way to achieve this is to use position: absolute and put input into a wrapper. Let me show you:
.input-wrapper {
position: relative;
}
.input-wrapper img {
position: absolute;
top: 5px;
left: 5px;
}
input {
height: 40px;
width: 200px;
padding-left: 35px;
font-size: 20px;
box-sizing: border-box;
}
<div class="input-wrapper">
<img src="https://picsum.photos/30"/>
<input type="text" />
</div>
So basically we use position: relative to move img relatively to it. Also note, that you have to add extra padding(left one in this case) so text won't overlap with icon.
There are a lot of ways to do the same: position: relative, negative margin, background-image, utilising of pseudo-elements, but absolute positioning is the most semantically correct in my opinion.

Push ribbon div to right edge of screen

I am designing a site that has a specific requirement to display a ribbon to the far right of the screen, I am using Bootstrap and the ribbon is in a bootstrap container, with a row and columns divided equally between the two elements, I want the Designer Text to stay exactly where it is because I am trying to keep it responsive and contained when going to mobile. How can I push the image div (Ribbon) all the way to the far right extending outside of the container.
I have include an image below of what I am working with. I may be doing this completely wrong, as my design skills are minimal.
I would like it to look like this
Here is the code:
.bookmarkRibbon {
/*width:100%;*/
height: 0;
width: 100%;
border-bottom: 22px solid #ff5750;
border-top: 22px solid #ff5750;
border-left: 20px solid transparent;
position: absolute;
margin-right: -3000px;
}
.bookmarkRibbon a {
display: block;
padding: 0;
position: relative;
/* allows us to position our pseudo-elements properly */
background: #ff5750;
overflow: visible;
/*height: -18px;*/
margin-left: 29px;
margin-top: -18px;
color: #fff;
text-decoration: none;
font-weight: bold;
font-size: x-large;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-7">
<h1 ID="lblCategoryName" runat="server"></h1>
</div>
<div class="col-xs-5">
<div class="bookmarkRibbon" id="discountBannerContainer" runat="server" style="margin-top: 15px">
20% OFF ADDRESS STAMPS<p class="mine">CODE: STAMP 20</p>
</div>
</div>
</div>
</div>
You have to move the ribbon outside the container to be child of body.
Than you can position it absolute.
<body>
<div class="ribbon"></div>
</body
.ribbon {
position: absolute;
top: 300px;
right: 0;
}
If you can not move the ribbon outside the container you have to use position fixed.
Unfortunately the ribbon will scroll with your page.
.ribbon {
position: fixed;
top: 300px;
right: 0;
}
Last option would be to use negative values and use the calc function.
This is not quite ease but doable.
Do you have a link to your site? I could take a looke at it if you like to.

VanillaModal How to keep close jpeg always on the upper right of modal box?

I'm using vanillamodal (http://cocopon.me/app/vanillabox/demo.html) and want to position the close button always on the upper right of any modal box.
My code: http://jsfiddle.net/bcj5S/
.vnbx-content > iframe {
border-width: 0;
vertical-align: middle;
margin: 0 auto;
}
.vnbx-close {
background-image: url("img/close.jpg");
background-position: center center;
background-repeat: no-repeat;
background-size: 12px;
width:670px; height:29px; display:block; z-index:3200; position:absolute; top:7px;
right:75px; cursor:pointer; outline: 0;}
}
Basically, the close button has to be positioned using the coordinate system of the modal dialog box that you are displaying. If dialog is positioned relatively, absolutely, or "fixedly," then, within that block, using absolute positioning, you place a close button in the upper right corner or anywhere you want.
Here's a quick fiddle to illustrate CSS-only dialog modal: CSS-only Modal.
Notice that the modal itself is positioned absolutely and the x-element is placed absolutely also using the coordinate system of the modal:
<input type = "checkbox" id = "closeToggle" />
<label for = "closeToggle">Open</label>
<div id = "modal">
<label for = "closeToggle"></label>
Content goes here...
</div>
And here's CSS:
input[type = "checkbox"] {
display: none;
}
label {
cursor: pointer;
}
#modal {
width: 200px;
height: 200px;
border: 1px solid blue;
position: absolute;
display: none;
}
#modal > label {
position: absolute;
top: -20px;
left: -10px;
}
#modal > label:before {
content: "x";
}
input:checked ~ #modal {
display: block;
top: 50%;
left: 50%;
margin: -100px 0 0 -100px;
}
Hope that helps.
It all seems to be dependent on what you're setting the box relative to. It should be set relative to the top left corner when it's set to the top right.
Without a good code sample (which by looking around seems to be hard to get) I couldn't give you any specifics.
EDIT: If you already have scripts in place, you could set the margin-right of the box to the width of the pop-up using a script of some sort.

z-index not working with position absolute

I opened the console (chrome\firefox) and ran the following lines:
$("body").append("<div id=\"popupFrame\" style=\"width:100%;height:100%;background-color:black;opacity:0.5;position:absolute;top:0;left:0;z-index:1;\" />");
$("body").append("<div id=\"popupContent\" style=\"width:200px;height:200px;z-index:1000;background-color:white;\" >dasdasdsadasdasdasdasdasd</div>");
The #popupContent should be above all but it's affected by the #popupFrame opacity.
The content is not contained in #popupFrame which makes this very weird.
The goal is to create a firefox-like alert box.
The second div is position: static (the default) so the z-index does not apply to it.
You need to position (set the position property to anything other than static, you probably want relative in this case) anything you want to give a z-index to.
Old question but this answer might help someone.
If you are trying to display the contents of the container outside of the boundaries of the container, make sure that it doesn't have overflow:hidden, otherwise anything outside of it will be cut off.
Opacity changes the context of your z-index, as does the static positioning. Either add opacity to the element that doesn't have it or remove it from the element that does. You'll also have to either make both elements static positioned or specify relative or absolute position. Here's some background on contexts: http://philipwalton.com/articles/what-no-one-told-you-about-z-index/
z-index only applies to elements that have been given an explicit position. Add position:relative to #popupContent and you should be good to go.
I faced this issue a lot when using position: absolute;, I faced this issue by using position: relative in the child element. don't need to change position: absolute to relative, just need to add in the child element look into the beneath two examples:
let toggle = document.getElementById('toggle')
toggle.addEventListener("click", () => {
toggle.classList.toggle('change');
})
.container {
width: 60px;
height: 22px;
background: #333;
border-radius: 20px;
position: relative;
cursor: pointer;
}
.change .slide {
transform: translateX(33px);
}
.slide {
transition: 0.5s;
width: 20px;
height: 20px;
background: #fff;
border-radius: 20px;
margin: 2px 2px;
z-index: 100;
}
.dot {
width: 10px;
height: 16px;
background: red;
position: absolute;
top: 4px;
right: 5px;
z-index: 1;
}
<div class="container" id="toggle">
<div class="slide"></div>
<div class="dot"></div>
</div>
This's how it can be fixed using position relative:
let toggle = document.getElementById('toggle')
toggle.addEventListener("click", () => {
toggle.classList.toggle('change');
})
.container {
width: 60px;
height: 22px;
background: #333;
border-radius: 20px;
position: relative;
cursor: pointer;
}
.change .slide {
transform: translateX(33px);
}
.slide {
transition: 0.5s;
width: 20px;
height: 20px;
background: #fff;
border-radius: 20px;
margin: 2px 2px;
z-index: 100;
// Just add position relative;
position: relative;
}
.dot {
width: 10px;
height: 16px;
background: red;
position: absolute;
top: 4px;
right: 5px;
z-index: 1;
}
<div class="container" id="toggle">
<div class="slide"></div>
<div class="dot"></div>
</div>
Sandbox here
If you're a big 'ol dumdum like me (but know your positioning rules are 100% correct) trying to get something like this:
to look like this:
Your solution may be as simple as ensuring your background is not transparent for the element you want in front of/behind the other element.
I had the the same problem, and i tried to solve it by appending the element with absolute position in a div with a sticky position, my problem was with speeddial (reactjs + material), so i dont know if it will work with all cases.
It may be too late, but it can be preferred as an alternative method. The order of layering for displaying elements in the absolute position depends on the order in which the elements are inserted into the parent element. In other words, instead of using z-index, it is possible to send it to the back by adding it with $(parent).prepend(me), and to bring it to the front by adding it with $(parent).append(me).
function BringToFront(){
$("#parent").append($("#me"));
}
function SendToBack(){
$("#parent").prepend($("#me"));
}
#mySister{
position:absolute;
left:25px;
top:25px;
width:100px;
height:100px;
background-color: red;
}
#me{
position:absolute;
left:50px;
top:50px;
width:100px;
height:100px;
background-color: yellow;
}
#myBrother{
position:absolute;
left:75px;
top:75px;
width:100px;
height:100px;
background-color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="parent">
<div id="mySister"> </div>
<div id="me">Hello! this is me!</div>
<div id="myBrother"> </div>
</div>
<button type="button" onclick="BringToFront()">Bring to front</button>
<button type="button" onclick="SendToBack()">Send to back</button>

Why img without position is like "absolute"?

Check this code :
HTML :
<div style="position: absolute; visibility: visible; width: 172px;">
<img class="inf-image" align="right" src="http://www.ilritaglio.it/wp-content/uploads/2012/02/wee.jpg">
<div class="inf-content">
Hello
</div>
</div>
CSS :
.inf-image
{
position: relative;
cursor: pointer;
margin: 3px 8px 0px 0px;
width:20px;
}
.inf-content {
background-color: #FF0000;
padding: 10px;
width: 150px;
height:50px;
}
looks like the div (which is relative) is under the image (which look absolute). Why? It should push the div over its height.
Floating elements (like an <img align="right">) offset only the content of block elements, but not their backgrounds, so the red background of the div is seen under the image.
Its all about the CSS stacking context. If you give an element another position than static it will be moved to its own stacking context. From a logical point of view the .inf-image { position: relative; } is no longer a child of the parent DIV or a sibling to .inf-content. What you have now is a DIV with another DIV (the red one) inside. The image itself "hovers" in its own context right below the document root (HTML) and is just positioned relative to that element, which preceded it in the source.
Which is shown above which element can be determined by a combination of position and z-index.
https://developer.mozilla.org/en/Understanding_CSS_z-index
http://reference.sitepoint.com/css/stacking
According to your css and html your div is positioned absolute while your image is positioned relative. This is your problem.
<div style="position: relative; visibility: visible; width: 172px;">
<img class="inf-image"src="http://www.ilritaglio.it/wp-content/uploads/2012/02/wee.jpg">
<div class="inf-content">
Hello
</div>
</div>
.inf-image
{
position: absolute;
cursor: pointer;
margin: 3px 8px 0px 0px;
width:20px;
right:0;
}
.inf-content {
background-color: #FF0000;
padding: 10px;
width: 150px;
height:50px;
}