Struggling to Make Hover Effect Work on a Wrapper Div

I could really use some assistance.

Struggling to figure out how to make the hover effect work correctly on a wrapper/container DIV.

CSS:

#myhover:hover {
    border: 1px solid red;
}

HTML:

<div id="myhover" style="background: #ffffff; 
      width: 177px; height: 20px; border: 1px solid #808080;">
    <div style="float: left;">
        <input id="refdocs" style="padding-left: 4px; padding-right: 3px; 
                  height: 15px; width: 158px; border: none;" type="text">
    </div>
    <div style="line-height:18px; font-size: 11pt;  color: #779297;">+</div>
</div>

Answer №1

Inline styles can cause unintended overrides because they are the most specific in the cascade. To avoid this issue, move your styling for #myhover into a separate style sheet.

For example:

#myhover {
    background: #ffffff; 
    width: 177px; 
    height: 20px; 
    border: 1px solid #808080;
}

Example on jsfiddle: http://jsfiddle.net/va8Bz/

Answer №2

The CSS styles in your style attribute are taking precedence over the stylesheet selectors, as they are more specific.

You have a few options to address this issue:

  1. Transfer your styles from the style attribute to the external stylesheet.
  2. Transfer your styles from the style attribute to the external stylesheet.
  3. Use !important with the style declarations that need to override those in the style attribute.

I recommend moving your styles from the style attribute to a separate stylesheet for better organization and management.

For example: http://jsfiddle.net/Y7NW9/

Answer №3

To achieve your desired styling, it is recommended to move all of your CSS rules into a separate stylesheet rather than using inline styles.


You can also simplify your HTML markup as follows:

<div class="container">
    <input class="refdocs" type="text">
    <div class="icon">+</div>
</div>


Next, in your external CSS file:

.container {
    display: inline-block;
    position: relative;
}

.input-wrapper {
    float: left;
}

.refdocs {
    border: 1px solid #808080;
    padding: 2px;
    padding-right: 14px;
    margin: 0;
}

.refdocs:hover {
    border: 1px solid red;
}

.icon {
    font-size: 11pt;
    position: absolute;
    top: 3px;
    right: 5px;
}

Check out this demo for a live example

Answer №4

Here is the solution to your query that was addressed in a previous post:

#add {
    float: right;
    width: 20px;
    height: 20px;
    cursor: pointer;
    text-align: center;
}
#add:hover {
    color: #f00;   
}

http://jsfiddle.net/kUSBM/

Your feedback on the provided solutions is highly appreciated.

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

Error: jQuery Datatables Library encounters an issue with undefined variable "oColumn"

I'm encountering an issue with implementing the jQuery Datatables library on my Joomla website's table. The script partially styles the table, but then stops (changing header and text colors, but missing datatables controls). http://datatables.ne ...

Tips for removing two specific "th" elements from a table that is generated dynamically

I have a challenge where I need to remove 2 specific elements from a table depending on which delete button is clicked Check out the code snippet below : <!--HTML--> <button type="button" class="collapsible">Manage Formulas</button> < ...

What is the best way to choose a random image in a Django template?

I am currently facing an issue with selecting a random image in my Django template each time the page loads: <!--<img src="{% static 'images/640px-Waaah.jpg' %}"/>--> <img src="{% static 'images/Crying_Baby.jp ...

Embed a FLV video within a jQuery tooltip

My current setup includes a line of code like this: <img title="FLV Video goes here" class="tooltip" src="/images/icon-question.png" alt="questions" width="12" height="12" border="0" /> When hovering over the image, the text in the title attribute ...

Oops! Smarty encountered a fatal error that wasn't caught

An error occurred while processing the template file "C:\xampp\htdocs\eventos\libs\templates\teste.tpl" on line 9. The error message states: Fatal error: Uncaught exception 'SmartyCompilerException' with message &apo ...

What could be causing the html.fromstring function to malfunction in my code?

In my current code, I am utilizing html.fromstring: import html import sys url = "https://tokcount.com/?user=totallynotbenandoliver" response = requests.get(url) try: response = requests.get(url) except: print ('Sorry bad url') s ...

Customize Swiper js: How to adjust the Gap Size Between Slides using rem, em, or %?

Is there a way to adjust the spacing between slides in Swiper js using relative units such as 2rem? The entire page is designed with relative units. All measurements are set in rem, which adjusts based on the viewport size for optimal adaptability. For i ...

The presentation of the Google graph with dynamically changing data appears to be displaying inaccurately

I am looking to incorporate a graph displaying sales and purchase data on my webpage. Users should be able to select from categories like Purchase, Sales, or Production. I have separate tables for Purchase (AccPurchase) and Sales (AccSales), with productio ...

Changing the color of a div's text based on its content with CSS

I am facing a challenge in styling the text inside a “div” element using a Javascript function. Initially, when the page loads, these “divs” contain no value. The values of the "divs" will change between "Open" and "Closed" twice a day when the Jav ...

CSS animations for loading page content

Currently, I am incorporating animations into my project using HTML5 and CSS3, and the progress has been smooth. I have been able to achieve effects such as: #someDivId { position: absolute; background:rgba(255,0,0,0.75); transition: all 0.7s ...

Challenges with the dropdown menu navigation bar

I am struggling with my dropdown menu and sign up/sign in buttons as they are not aligning properly. I have tried various coding methods but haven't been able to fix the issue. Can someone provide me with suggestions on how to rectify this problem? c ...

How can I fix the position of the close button when using the paper component of a modal in material ui to ensure responsiveness on the screen

I recently created a cards page where multiple cards are displayed. Each card opens a modal component when clicked, but unfortunately, the close button is not functioning properly. Here's an image showing the issue with the button's position whe ...

What could be the reason for the failure of background: url(local.png)?

I am facing an issue where the background url() property only seems to work with online stored images. Local stored images do not display when I try to use them. This is my folder structure: index.html src css style.css images background.png profile ...

Make a hyperlink in Internet Explorer redirect to open in Mozilla Firefox

I am struggling with linking two URLs from a corporate intranet site built on Sharepoint to Firefox. The issue is that the links lead to an external site that doesn't function properly in Internet Explorer, which is the default browser for most users. ...

The page background appears to be incomplete in its coloring

As I work on creating a web application for personal use, my goal is to ensure it is mobile-friendly. However, I've encountered an issue where the background of my language page isn't displaying in full blue color as intended. Despite trying diff ...

Adjust the size of the canvas object/figure

Currently, I am developing a small script that allows users to upload an image, mark a spot on the image with a yellow box, and then save the modified image. I am utilizing HTML5 canvas for this project. While I have successfully implemented image uploadin ...

BASH-SHELL SCRIPT: Display a specific portion of content from a file

Recently, I stumbled upon a text file containing a snippet of HTML code: >>nano wynik.txt which includes the following text: 1743: < a href="/currencies/lisk/#markets" class="price" data-usd="24.6933" data-btc= "0.00146882" My goal is to extr ...

How to store a collection of web elements into an array using Python

I am facing a challenge trying to extract all the stock tickers (security symbols) and store them in a single array from the following website: There are two main issues that I have encountered: Each page switch prevents me from importing all values in ...

"Escape the confines of traditional div sections with the dynamic features of

In the beginning, I have arranged two rows of three divs on my webpage, which is how I intend to use them later. However, when testing the 'mobile view', the divs in the section overflow and move into the next part below the section. This causes ...

Leveraging ng-repeat in Angular

Recently, I came across a json information on a specific part model and got an idea to showcase it in a long scrolling list of item thumbnails. You can check out an example here: http://ionicframework.com/docs/components/#item-thumbnails However, when I a ...