Concealing figcaption for smaller screens

Currently revamping my outdated website to make it responsive. I tend to piece together code snippets without fully grasping them, so seeking straightforward guidance. The original site used subcontent divs for captions toggle. You can view it here: http://www.nancychuang.com/projects/mtc/ , where caption links are displayed below images. For the new site, I chose a budget-friendly template and have been customizing it.

I found it challenging to integrate the original captions into the new template as they were positioned using basic nested tables. It appears that displaying text underneath the images in the current template was not feasible, so I needed a less intrusive alternative. Managed to implement figcaption script by adapting code from css-tricks SlideinCaptions. So, the updated site will resemble this: .

    figure { 
display: block; 
position: relative; 
float: left; 
overflow: hidden; 
margin: 0 20px 20px 0; } 

    figcaption { 
position: absolute; 
    background: black; 
    background: rgba(0,0,0,0.75); 
    color: white; 
    padding: 10px 20px; 
    opacity: 0; 
    -webkit-transition: all 0.6s ease; 
    -moz-transition: all 0.6s ease; 
    -o-transition: all 0.6s ease; } 

    figure:hover 
    figcaption { opacity: 1; } 

figure:before { 
    content: "?"; 
    position: absolute; 
    font-weight: 800; 
    background: black; 
    background: rgba(255,255,255,0.75); 
    text-shadow: 0 0 5px white; 
    color: black; 
    width: 24px; height: 24px; 
    -webkit-border-radius: 12px; 
    -moz-border-radius: 12px; 
    border-radius: 12px; 
    text-align: center; 
    font-size: 14px; 
    line-height: 24px; 
    -moz-transition: all 0.6s ease; 
    opacity: 0.75; } 

    figure:hover:before { opacity: 0; } 
    .cap-bot:before { bottom: 10px; left: 10px; } 
    .cap-bot figcaption { left: 0; bottom: -30%;} 
    .cap-bot:hover figcaption { bottom: 0; }

The figcaption script functions on touchscreens, although the mechanism behind it eludes me! There's no mention of touch or click in the code (thus unclear how to reverse the action). On desktops, moving away from the image hides the caption, while on mobile devices, the caption remains fixed once activated. Since the text is relatively large on mobile screens, ensuring users can hide it is crucial. Either allowing users to tap anywhere to remove the caption or mimicking the original hidediv approach with a link for users to click:

<DIV id="subcontent1">
<p class="caption"><a href="http://maetaoclinic.org/" target="blank">Mae Tao Clinic</a>, founded by Dr. Cynthia Maung in 1989, serves as the primary care facility for numerous Burmese residents along the border. Offering a wide range of services, the clinic assists refugees, uninsured migrant inhabitants of Mae Sot, and Burmese individuals crossing the border due to healthcare access challenges.

<p class="caption"><a class="caption" href="javascript:dropdowncontent.hidediv('subcontent1')">HIDE</a></p></td>
</DIV>

*related: Can you specify the width of the hover block with figcaption, similar to how I did with the original subcontent divs? Unclear what 24px denotes in the code...a minimum width perhaps? but no maximum?

Your assistance is much appreciated! Thank you!

Answer №1

Allow me to provide an answer as well...

You currently have the following in your CSS:

figcaption { opacity: 0; }

This code indicates that figcaption is initially hidden.

In addition, you have:

figure:hover figcaption { opacity: 1; }

Which means that the figcaption becomes visible when hovering over the figure containing it.

These styling rules are primarily responsible for displaying the caption when hovering over the image, and on a mobile device - through tapping on the image.

You inquired about hiding the caption on a mobile device once it appears. The simple solution would be - according to the aforementioned CSS - to tap outside the picture which would remove focus from it.

However, consider whether this effect is desirable on a mobile device. It may not be very user-friendly. Another approach could involve adjusting the styling based on the device type. For instance, on a mobile device, the figcaption could always display below the image, offering a more logical layout. This can be achieved using media query CSS to target different screen sizes.

I recommend exploring online CSS tutorials to discover the various capabilities of CSS. Investing time in learning these techniques will prove beneficial, especially since you are already customizing a website.

Answer №2

To determine whether the device is touch-enabled or not, CSS can be used to apply different styles based on the result.

@media (-moz-touch-enabled: 0), (pointer: fine), (-ms-high-contrast: none) {
  figure:hover:before {
    opacity: 0;
  }
  .cap-bot:before {
    bottom: 10px;
    left: 10px;
  }
  .cap-bot figcaption {
    left: 0;
    bottom: -30%;
  }
  .cap-bot:hover figcaption {
    bottom: 0;
  }
}

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

Trigger a function in jQuery when an input field is focused

Whenever I click on a text input field, a json request is triggered which retrieves some data. $("input").one('focus', function(){ var thefield = $(this); $.getJSON("http://www.blabla.com/bla", function(data){ alert(JSON.stringify(da ...

What is the procedure for obtaining the factory of an element in situations where the element's class is not

Currently, I am facing a challenge with React where I have a single React element and I want to generate additional elements with the same class. The issue is that I am not aware of the class name, only the instance of the element. When using React.create ...

Is this JavaScript code accurately matching the height of all three elements?

What I aim to achieve https://i.sstatic.net/aNCWV.png I attempted to create a condition-like statement: [ Comparing the heights of the 3 elements ] → When all are smaller than the height of content: Stretches to the full height of content. (jus ...

Is there a way to retrieve JSON data from a child component and pass it to a parent component in Vue.js?

I have data from the results stored in a child component that needs to be passed to the main component. The Main Component is the parent, so whenever I click the button, the results should be collected in the main app <button @click="showFinalResu ...

Encountering an error where "null is not an object" while trying to access 'u.default.setString' in React-Native Clipboard

Query As I execute the code sample on snack.expo.io, an error crops up: null is not an object (evaluating 'u.default.setString') Context The following is my code snippet directly sourced from the example available on GitHub: App.js: import R ...

Issue with ESLint arises following the installation of npm create-react-app package

ESLint is showing Invalid Options: - Unknown options: env, parserOptions, rules. The 'parserOptions' has been removed and you should now use the 'overrideConfig.parserOptions' option instead. Similarly, the 'rules' have been r ...

Is there a way to display the button solely when the cursor is hovering over the color?

When I hover over a particular color, I want the button to show up. However, instead of displaying the button only for that color, it appears for all the colors of the product. Also, the placement of the button on the left side means that if I try to hover ...

The Functions of Span and Div Elements

I am facing an issue with the code below, where I am trying to align the menu bar (page-wrap) in the same line as the content. The following two lines are used for star rating and displaying the stars. <div id="content" float: left></div> ...

Unable to generate a three-dimensional plane on the XZ plane

When using the Aframe library to create a plane, I defined the following points: point_1 = [0, 0, 0]; point_2 = [1, 0, 0]; point_3 = [1, 1, 0]; point_4 = [0, 1, 0]; To generate a plane in the XY plane, everything functions as expected. Here is the workin ...

Using hooks is restricted to the confines of a function component. An error will occur if they are called outside of this scope: "

How can I integrate a shopping cart feature into my app? I've created a separate file with the necessary functions, but I keep encountering an error related to invalid hook calls. export function CartProvider(props) { const [items, setItems] = u ...

Error alert: Code syntax issue detected in Javascript </div>

Currently, I am working on a todolist project from w3schools, which can be found at: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_todo Here is the output of my work: After clicking the Add button, an error message appeared saying: "Unc ...

Exploring Vue.prototype attributes and utilizing them

I'm facing a challenge while attempting to globally set a property using Vue.prototype. This is what I currently have: microsoftTeams.initialize(); microsoftTeams.getContext((context) => { Vue.prototype.$teamsContext = true; }); new Vue({ ...

Having trouble with the AWS S3 getSignedUrl looping function?

Could you assist me in sending two S3 pre-signed URLs for every key found in the [user.idKey, user.selfieKey] array within my Express route? I have confirmed that S3 is successfully obtaining the pre-signed URLs as they are logging to the console using th ...

Variations in how words are organized within a sentence

Can you help me devise an algorithm to identify all possible combinations of word groupings in a sentence without changing the order of the words? For example, for the sentence "the test case phrase," the various combinations would include: ['the te ...

Unique Shader - Three.js

I have been attempting to implement a custom shader in Three.js, following various examples, but I am encountering issues. Below is the code snippet I have been working with: var vertex = "void main(){vec4 mvPosition = modelViewMatrix * vec4( position, 1. ...

A guide to selecting the dropdown item labeled as (Select All) using Python and Selenium

edit: Trying to submit parameters for a database-generated report on this page. Successfully modified the start date in the first field using send_keys(), but unable to click on "(Select All)" for fields 3 and onwards, except one. In order to access the h ...

Issue with Backbone: Browser button failing to activate routes

Recently, I have been working on a web application using backbone, jQuery, and the BAAS of stackmob. However, I've encountered an issue where browser buttons do not trigger the backbone routes as expected. Despite successfully navigating from one view ...

What is the best way to make a full width div within a container using bootstrap?

Imagine you have the following code snippet: <div class="container"> <div class="row"> <div class="col-md-12"> ... <div class="full-width-div"> </div> </div> & ...

What causes the generation of an outdated object when utilizing the let and new keywords to create a new object within a service function?

Hey there, looking for a basic auth authentication service in angular2? Here's the issue I'm facing: When a user logs in for the first time, everything works smoothly. However, if they try to log in with a different account for the second time, ...

Issue arising with the resizing of the image in the main section, as it is shrinking prematurely before reaching the designated width

Desired Outcome Current Situation Currently, I am in the process of creating a responsive hero section where I aim to maintain the image at full size until the window width reaches below 1300px. However, I have observed that the image starts to shrink mu ...