Tips for adding a hidden element along with an inline-block display styling

I am faced with a dilemma in my coding project. I want a div to have both inline-block and display none properties simultaneously, but it seems like I can only choose one option.

This is a snippet of my HTML code:

.like_user_wrapper{
    margin-top:20px;
    padding:5px; 
    height:55px;
    box-shadow:1px 1px 10px #f0f0f0;
    background:white;
    display:inline-block;
    display:none;
}

As much as I would like to achieve this effect without resorting to JavaScript for hiding the div, it presents a challenge.

Answer №1

Simply utilize visibility: hidden;

#like_user_wrapper{
    margin-top:20px;
    padding:5px; 
    height:55px;
    box-shadow:1px 1px 10px #f0f0f0;
    background:white;
    display:inline-block;
    visibility: hidden;
}

Take note that a custom ID is being used (#...) instead of a class (....)

To make it visible later on, you can apply this JavaScript property to that specific ID:

document.getElementById('like_user_wrapper').style.visibility='visible'; 

This can be incorporated in an onmouseover="", or a javascript function etc, so it becomes visible when desired. To see how this works in html, check out this example:

<!DOCTYPE HTML>
<html>
<head>
<style>
#like_user_wrapper {
    margin-top:20px;
    padding:5px; 
    height:55px;
    box-shadow:1px 1px 10px #f0f0f0;
    background:white;
    display:inline-block;
    visibility: hidden;
}
#hover {
    width: 80px;
    height: 50px;
    background-color: red;
}
</style>
</head>
<body style="background-color:blue;">
<div id="like_user_wrapper">Like User Wrapper</div>
<br><br>
<div id="hover" onmouseover="document.getElementById('like_user_wrapper').style.visibility='visible';" onmouseout="document.getElementById('like_user_wrapper').style.visibility='hidden';">Hover over me</div>
</body>
</html>

Learn more about the visibility CSS property from this help page

Note: In most browsers, by default a DIV has the display property block, so using inline-block may not be necessary - you could wrap it in a <div> with that property regardless.

Answer №2

If you want to toggle the visibility of an element with jQuery, it's best to avoid using jQuery.show().

Instead, use

$('.like_user_wrapper').css({'display': 'inline-block'});
to show the element.

Alternatively, simply use $('.like_user_wrapper').hide(); to hide the element.

Don't forget to remove any display: inline-block from your CSS.

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

jQuery has been utilized to clone a form, resulting in the fields becoming inactive

I have a basic form with some fields that are affected by the click event. In addition to this, I am duplicating the form and appending it (with the intention of renaming the fields, but I have not succeeded yet). The problem I am facing is that after cl ...

Auto-filling a form with the selected 'id' in Django using JavaScript or AJAX

I am a novice and I want the form to be autofilled when I select a vehicle ID from the template. Here are my models. class Fuel(models.Model): vehicle = models.ForeignKey(Vehicle, on_delete=models.CASCADE) previous_km = models.IntegerField(blank=False, nul ...

Tips on adding style to your jQuery autocomplete dropdown

I am currently utilizing jQuery autocomplete functionality. I have configured it to communicate with a service and retrieve records: <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1 ...

Setting up routes in Vue 2.0 - Avoid using 'new' for any side effects caused

Currently, I am setting up a vue project using the webpack template (npm install init webpack). However, I am encountering an error in the terminal: ERROR in ./src/main.js ✘ http://eslint.org/docs/rules/no-new Do not use 'new' for side effe ...

Issue with deploying Azure node.js application due to libxmljs error

My goal is to launch my website using libsmljs built on node.js on Windows Azure. However, during the deployment process on Azure, I encounter a failure with the following error message: Command: C:\DWASFiles\Sites\CircuitsExpress\Virt ...

Using CSS in Android WebView

I am currently working on creating a book reader for EPUB files, and I would like to display the book pages in a 2-page layout (horizontally) similar to a physical book. To achieve this, I have set up two webviews at runtime and attempted to manage the con ...

How can I incorporate raw HTML into a Django template using HTML-formatted strings?

I'm looking to convert a string that contains HTML tags converted from a Markdown file into actual HTML. Afterward, I want to insert the HTML into a template using Django (this is my first time working with Django). This is what my current output loo ...

Displaying all checkboxes within an array of forms

Hello, I have created a form with the following structure: <div class="row calc"> <div class="large 12 columns"> <div class="large-1 columns"> <label>Quantity</label> <input name="units[]" type="tex ...

Refresh the AJAX content at regular intervals using JavaScript library jQuery

I created a content management system that keeps a record of recent user logins. Currently, this data is displayed in a jQuery UI tab using Ajax. I would like to display this information in a sidebar on the main page and update it via AJAX every 30 seconds ...

Using AngularJS and JavaScript, set the Submit button to be enabled only when the email input is valid and a value is selected in

I'm trying to create a form that includes an email input field and a drop-down list sourced from a database array. Initially, the submit button is disabled when the form loads. My goal is to figure out how to activate the submit button only when the ...

Tips for preserving data in a Spring form utilizing jquery ajax while avoiding the need to reload the page

I experimented with this example, where the student class object is received at the controller side and can be used directly. However, I want to call the post method using jQuery ajax and send the data as a class object instead of individual input field va ...

What could be causing the unexpected behavior of TypeScript in Visual Studio Code?

VSCode is showing errors, but everything is functioning properly. Here are some of the errors: Type expected. [ { "resource": "/C:/Users/Dell/Desktop/vite-project/src/App.tsx", "owner": "typescript", "code": "1110", "se ...

Utilizing jQuery to dynamically display and conceal a dropdown menu based on user interaction

I have been working on a code that allows the user to make a new selection when clicking on a word. The code is almost perfect and here it is: http://jsfiddle.net/24rjN/ HTML: <p>Your current town of stay:</p> <p id="profile_town_selecte ...

Designing a logo atop a Jquery tab

In the layout I have designed, there is a header followed by a jQuery Tab navigator. The tabs have padding on the left side, and I want the header image to overlap this area. Currently, the image is hidden behind the tab panel. Which CSS property can be us ...

Differences Between JavaScript KeyCode and CharCodeIn the world

Issue at Hand: The challenge is to restrict allowed characters in an HTML input field to only a-z and A-Z. It is essential for business requirements that this restriction happens on KeyPress, preventing disallowed characters from even appearing in the in ...

Tips for anchoring an element when scrolling reaches its highest point

Is there a way to keep a div element fixed in its original place when scrolling through it, so that it locks into position once we reach a certain point? I've tried using CSS position:fixed; without success. I have noticed this technique on many webs ...

Is there a way to determine the number of clicks on something?

I'm attempting to track the number of times a click event occurs. What is the best method to achieve this? There are two elements present on the page and I need to monitor clicks on both of them. The pseudo-code I have in mind looks something like ...

Ensuring the accuracy of forms using third-party verification services

While working on an Angular form validation using an external service, I encountered a cannot read property of undefined error. The component contains a simple form setup: this.myForm = this.fb.group({ username: ['', [this.validator.username] ...

What is the simplest method to remove numbered images after they have been clicked on?

I am working with a simple code that displays images of numbers 1-10 on the screen (named 1.jpg, 2.jpg, etc.). A random number is generated and when the correct image is clicked, a prompt appears. However, I want the incorrect image to disappear when cli ...

Include previous input as a "phantom" thumbnail to the slider element of type "range"

https://i.stack.imgur.com/JnuCN.png Using a tutorial from w3schools, I have customized a regular range slider. The objective is to send a new value command to an external MQTT-based home automation system and display the previous value as a ghost-thumb in ...