Having trouble with images not showing up properly when applying rounded CSS borders and opacity effects

Trying to solve a unique problem, I am seeking advice:

On my website, I have included a 300 x 300 Pixel square png-image of a circle. Utilizing Zurb's Foundation 5.0.2 as a CSS Grid basis.

My objective is to create a CSS-border around the circle and incorporate an opacity-effect that only reveals the image fully upon hovering with the mouse. Importantly, the surrounding CSS-border and background should remain unaffected by this hover effect. Refer to the links for visual examples.

This is what I have so far in terms of code:

HTML:

<div class="large-4 columns" id="border">

            <div id="foto"><img src="/img/test.png" alt="Portrait" width="300" height="300"></div>

 </div>

CSS:

    #border #foto {
        border-radius: 50%;
        width: 300px;
        height:300px;
        background: #1ABC9C;
        border: 15px solid #34495E; 

}  

#foto:hover {
        opacity: 1.0;        
}



#foto {
        opacity:0.5;        
}  

The current code successfully displays the border around the circle, but applies the hover effect to both the border and the image:

If I adjust the CSS in a certain way, it does apply the hover effect solely to the picture, however, it decreases the size of the image and loses its centered display:

#border {
    border-radius: 50%;
    width: 300px;
    height:300px;
    background: #1ABC9C;
    border: 15px solid #34495E; 

}

I would greatly appreciate any guidance on how to properly display the image and implement the intended hover effect.

Thank you sincerely.

Answer №1

Make sure to include the overflow:hidden property in both your border and foto div elements.

#border #foto {
    border-radius: 50%;
    width: 300px;
    height:300px;
    background: #1ABC9C;
    border: 15px solid #34495E; 
    overflow: hidden;
} 

http://jsfiddle.net/ufdM7/

Answer №2

Eliminate the border attribute from #border #foto and incorporate overflow:hidden.

Your code should look like this:

#foto:hover {
    opacity: 1.0;
}
#foto {
    opacity:0.5;
}
#border {
    border-radius: 50%;
    width: 300px;
    height:300px;
    background: #1ABC9C;
    border: 15px solid #34495E;
    overflow:hidden;
}

View Fiddle here.

Answer №3

Here is my solution:

http://jsfiddle.net/u9LrK/1/

#image, #image picture {
    background: #1ABC9C;
    border-radius:50%;
}
#image {
    border-radius: 50%;
    border: 15px solid #34495E; 
    height: 300px;
    width: 300px;
}
#image:hover picture {
    cursor: pointer;
    opacity: 0.5;
}

Is this the solution you were looking for?

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

Add the onmouseover attribute to dynamically alter the text

I'm trying to add the onmouseover function to the image of Angelina Jolie in order to change the text above, which currently says "Your Daily Dose of Contrabang". What is the best way to achieve this? Thank you for your assistance. You can check out t ...

`JQuery fadeOut seems to have a limitation where it only applies to the

I have a group of divs, each containing an anchor tag that triggers a JavaScript function (which uses AJAX to delete a row from a table). Here's an example setup: <div id="container"> <div><a id="btn" onclick="deleteRow()">Delet ...

How can I divide a div by utilizing word wrap?

My CSS-styled div is pretty straightforward .text { text-transform: capitalize; color: #FFFFFF; background: #918a8a; opacity: 0.6; font-size: 2em; height: 80px; width: 200px; } It creates a grey box w ...

To enhance the appearance of an input field, implement the Bootstrap check feature

Using bootstrap in my app, I am dealing with a readonly input where I would like to add a checkmark inside of it. My attempt to simply add <input readonly type="text" id="kyc_status" class="form-control" value="Success ...

I encountered a problem in my Angular form where the keycode event for F2 is not functioning properly in certain scenarios. Can anyone help me diagnose the issue

During my Angular project, I created an HTML page with a form that includes input data with autofocus. To enhance user experience, I added an event listener for the "F2" key that triggers a console message. My objective is to ensure this functionality wor ...

Is there a way to work around the CORS policy in order to fetch data from URLs?

I have been developing a tool that can analyze URLs from an uploaded CSV file, search the text content of each URL, and calculate the total word count as well as the occurrences of "saas" or "software". The goal is to generate a new CSV file with the origi ...

Can CKEditor be integrated with Mutation Observer? If so, how can this be achieved?

Trying to detect changes in the current CKEditor content. The goal is to identify which element's content has been modified when a user writes multiple paragraphs. Not well-versed in JavaScript or jQuery, but managed to come up with this code after s ...

Information displayed when Tab is inactive - Material Ui and React

Just diving into the world of React and UI design, seeking some guidance on an issue I'm facing. I'm working on implementing Material Ui Tabs in my Component, but struggling to get a tooltip to show on a disabled Tab. Here's a snippet of my ...

PHP code for retrieving all combobox values from a form during submission

When I submit the form, I am only able to retrieve the value of the last combo box. Is there a way to capture all the combo boxes' values? Also, I need to know how to access the value of a label. Below is the code snippet used to generate the list of ...

Apply a border to the div that has been selected

I have a tool for storing information and I am using *ngFor to display each instance in a line. Is there a way to add a border when clicking on a line? The border should only appear on the clicked line, disappearing from the previous one if another line i ...

What is the method for adding a CSS class to the textContent in a HTML element?

Hi there, I'm currently trying to make some changes to the textContent of the HTML code below. However, it contains an <i> tag, so I'm wondering how I can change the textContent without affecting the <i> tag itself. Is there a way to ...

Aligning the title vertically in Ionic on Android device

Currently, I am in the process of developing an application using the Ionic framework and cordova. After uploading my app for testing purposes, I encountered a small issue. The title in the top bar on Android appears to be misaligned vertically. Is there a ...

Retrieve a distinct HTML onclick event using VBA

I need some assistance because I have a major issue that I can’t solve or find help for online. Here is the code I am dealing with: <span class="test taLnk hvrIE6" onclick="ta.trackEventOnPage('Hotel_Review' ,'URL_HOTEL|text|2| ...

How can I transfer a particular data value from a div to JavaScript within Laravel 5.0?

Displaying separate square divs based on integers retrieved from the database. This is the front-end view. I want to pass the room ID (code) to a JavaScript function when clicking on these div elements. https://i.stack.imgur.com/aIYTr.png Below is my cur ...

Tips for converting an entire column along the vertical axis to a different language

Looking for a solution with my grid view where I want to translate the items of the second column on the y axis, as shown in the image. I attempted to use the translateY() function, but it resulted in the need to scroll in order to see the translated items ...

Finding the midpoint of SVG paths and VML shapes

I'm currently experimenting with: My main focus is on obtaining the center points of different countries (to accurately place markers on each country). I've encountered some challenges in achieving this and have attempted various methods, such ...

Aligning a child div within a parent div using HTML/CSS where the child div takes up 30% of the parent div and

Can anyone help me figure out why these two INPUT elements aren't aligning next to each other? I appreciate any assistance you can offer! <STYLE> html, body { width: 100%; height: 100%; margin: 0px; padding: 0px; } </STYLE& ...

How can I remove specific items from a session array when they are selected?

I am seeking a solution that will allow me to remove a specific item from an array when that item is clicked. For example, if I click on "Two", it should disappear. See a demonstration here: CODE: <form method="post"> <input type="text" i ...

Is there a way to divide this constantly changing list into 3 separate columns?

I'm currently tackling updates on an older web application, and instead of completely rewriting everything to conform to modern standards, I am endeavoring to keep the changes as straightforward as possible. Displayed below is a dynamically generated ...

Accessing new information seamlessly without the need for page refresh

For optimal mobile viewing of my website, I am considering implementing a select element. Here are the available options: HTML: <select name="select-choice-8" id="select-choice-nc"> <optgroup label="News"> & ...