Display an icon at the upper right corner of the container

Is there a way to shift the question mark on hover to the top right corner of the white box instead of the bottom left corner?

<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 attempted using position:absolute; and adjusting with right, top but it did not work well with multiple divs.

UPDATE:

https://i.sstatic.net/5OCj4.png

Answer №1

For optimal results, consider positioning your outer window with relative positioning before absolutely positioning your icon.

Here is a suggested solution:

.window {
  position: relative;
}

.fa.fa-star {
  position: absolute;
  top: 0;
  right: 0;
}

Try This Solution on Fiddle

The rationale behind this approach is that when you use absolute positioning, the item is positioned based on its nearest ancestor element that has non-static positioning. Hence, the need for relative positioning of the window.

Imagine a container. The container has relative positioning. Any element inside that container positioned absolutely will be limited to the height and width of the container. By setting the icon's position as top: 0; right: 0, it will appear at the top right corner of the container, in this case, the window.

UPDATE

Based on your updated requirements, you might want to experiment with this code snippet:

#rptTitle {
  display: inline-block;
  width: 90%;
}

.questionBox {
  display: inline-block;
  float: right;
}

While not perfect, this quick solution should meet your current needs. Feel free to enhance it further using these principles :)

Check Out the New Fiddle

Answer №2

Utilizing the position:absolute; property was a good start, but don't forget to also assign position:relative; to the parent element. Additionally, include top:0px and right:0px for the question mark element.

After updating the post, remember to nest the div within the panel-body class div and ensure that panel-body has position:relative; set.

Check out the updated code on JSFiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking for a jQuery fix: How can I deactivate specific items once an item is selected?

I'm currently working on a form where I need certain options to be disabled when a specific option is selected. I'm new to jQuery and could use some assistance, thank you. Check out the link here: My goal is to disable some options in the secon ...

Incorporating an Aspx Page into a Static Website

We currently have a static website consisting of all html files. In addition, we have a dynamic ASPX website with a specific page (RegisterAndBuy.aspx) that displays data based on user selections and collects personal information to send to the Admin via ...

Tables that respond to changes in screen size, allowing nested table cells to inherit widths

I am currently working on a responsive table with unique content in each row and a concertina feature for expanding rows. When the concertina is activated, it adds another row to the table below the current row, using a td element with a colspan attribute ...

`Can you teach me how to dynamically load HTML elements using input JSON data?`

What is the best way to iterate through an input array of objects? I currently have data for only 2 people included. However, there are more than 50 people's information in the input and I need to loop through all of them. Here is a sample code snip ...

Scrollable container with jQuery draggable functionality

I am currently working on implementing a draggable list that I want to contain within a scrollable div. $( ".draggable" ).draggable(); Here is the fiddle I have created for this: http://jsfiddle.net/YvJhE/660/ However, the issue I am facing is that the ...

The 'css' property cannot be set on something that is undefined

I'm attempting to dynamically change the size and color of a circle based on user input in the form fields. However, I've encountered the following error: Cannot set properties of undefined (setting 'css') Could anyone provide guidan ...

Leveraging HTML tables for input purposes

Just starting out with php, HTML, and mysql. Using HTML tables for the first time here. Created an HTML table filled with data from a MySQL table. Planning to use this table as a menu where users can click on a cell with a specific date. The clicked date ...

Replicate the cursor to make it show up twice

Is there a way to create a duplicate cursor effect on my website, making it appear twice and perhaps look like it's drunk? I want the cursor to still interact with images and change accordingly, but always have two visible. Can this be achieved easily ...

Align and resize image using CSS styling

Seeking assistance on centering and cropping images using CSS. Tried implementing the technique from this specific article. However, experiencing inconsistencies in device UI output. Can someone shed light on this behavior? Scenario: The objective is t ...

Encoding and Displaying Characters in HTML with UTF-8

I am experiencing an issue with UTF-8 characters in the page title. I would like to include the music symbol ♫ on the page title. The strange thing is that sometimes it displays correctly (in Google Chrome) and other times it shows a square symbol indic ...

Leverage JSON as the primary data source for Assemble.io

Can Assemble.io be used to compile json files into HTML using templates? If so, how can I configure my gruntfile to accomplish this? Overview of My Folder Structure: Data productlist1.json productlist2.json productlist3.json productdetail1.json product ...

What is the process for adjusting the border color of my button?

Is there a way to change the blue outline color to #D5A021 instead of blue when the button is clicked by the user? I believe it might be related to the btn-primary class HTML <a class="btn btn-primary btn-xl js-scroll-trigger" href="#services">Fin ...

AngularJS 1: Dynamically updating input values in real-time

Hey everyone, I'm experimenting with Angular and have encountered a roadblock. I am trying to assign values to an input element using ng-repeat for a list of parameters. <input type="text" ng-model="parameters.inParameterName" class="form-control ...

Guide to transforming plain text into HTML format using Angular 4

In my Angular application, I am facing the task of adding a value to an array where the value itself needs to be in HTML format. This means that when the value is displayed, it should render as HTML text. For instance, if someone hovers over the text, I ...

Encountering Issues with Formatting InnerHtml Text using RegEx

Technology: React.js I have been working on a custom function in JavaScript to highlight specific words within a code block. The function seems to be functioning correctly, but the highlighting isn't staying after the function is completed. Any ideas ...

Having issues with the CSS block in my Jekyll dropdown navbar

I have been exploring resources from both w3schools and another website to create a navigation bar in Jekyll using frontmatter. However, I am running into issues with the block property in CSS. Most of the navbar is functioning properly, except for the dro ...

Adjust the color of text using the <text-shadow> technique

The default 'text-shadow' for white text in a <div> is defined as follows: When the text color is changed to #627CA9 by clicking on it, I want the 'text-shadow' to be updated to match the new color. text-shadow: 0 0 1px #FFFFFF, ...

Unable to utilize static files in node.js and express

Attempting to utilize node.js and express for crafting a chat client has proven to be a bit challenging. Whenever I attempt to incorporate external CSS or JS files, I encounter GET errors. My current configuration in index.js is as follows: var express = ...

The quantity addition and subtraction function is malfunctioning

I have implemented a quantity plus/minus feature in HTML which is embedded from a jQuery script provided below. jQuery.ajax({ type: "POST", url: "http://ayambrand-com-my-v1.cloudaccess.host/index.php?option=com_echa ...

Unexpected behavior in Internet Explorer with ChartJS version 2.6.0

When using ChartJS v2.6 to create a pieChart within a Bootstrap Grid, everything appears correctly in Chrome and Firefox, but not in Internet Explorer. In IE, the chart is unintentionally stretched on larger screens. Bootstrap should handle the sizing, but ...