Aligning images both horizontally and vertically inside a div with changing dimensions

Looking for advice on centering forward and back arrows on either side of an image within a resizable div. The dimensions of the div change based on the image size.

Check out my progress here:

Play around with the layout on this jsfiddle: http://jsfiddle.net/thwackukulele/4zHyd/. Just keep in mind that it may not work without the linked images.

The forward and backward arrows are currently positioned at the top of the blue area next to the image. I'm striving to have them centered both horizontally and vertically within this blue section.

I understand that I've used a lot of positioning, so if there's a better approach to tackle this layout, I'm open to suggestions. My main goal is to convey my intentions clearly to the developer who will be implementing the database CMS functionality. The code doesn't have to be flawless, just needs to showcase my vision effectively.

Appreciate any assistance in advance!

Answer №1

.fb-frame-wrap{ position:relative; }
.r-arrow, .l-arrow{ position:absolute; top:50%; margin-top:-32px; width:64px; height:64px}
.l-arrow{left:0}
.r-arrow{right:0}

Answer №2

I'm a bit confused by the question, as there seems to be a lot of code to go through. It might be helpful to only include the relevant code snippet for the specific issue you're facing.

Consider using the following CSS:

.container {
    position: relative;
}
.left {
    position: absolute;
    left: 0;
    top: 50%;
}
.right {
    position: absolute;
    right: 0;
    top: 50%;
}

Answer №3

If you want to perfectly position the links within a div, try this method: absolute positioning the links to the div with a top of 50% and a negative margin-top equal to half of the link's height. Here's an example showcasing this technique:

http://example.com/code-sample

HTML:

<div>
    <img />
    <a id="next"></a>
    <a id="prev"></a>
</div>

CSS:

div {
    position: relative;
    height: 300px; /* Set size */
    width: 500px;
    background: blue;
}
#prev, #next {
    position: absolute;
    width: 24px;
    height: 24px;
    top: 50%;
    margin-top: -12px;
    background: red;
}
#prev {
    left: -48px;
}
#next {
    right: -48px;
}

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

Keeping your Contact Form 7 perfectly centered on your WordPress website

Currently, I am utilizing the contact form 7 plugin on my Wordpress website. While I have two forms set up, I only want to center align one of them. To achieve this, I initially added the following CSS code in my additional CSS: div.wpcf7 { text-align: c ...

Looking for a different method to remove a list item within an unordered list using CSS instead of HTML

I am currently working on designing a mock-up website using CSS codes. If you want to see the mock-up website, you can visit: Here is the specific list I am referring to: https://i.sstatic.net/HA3fC.jpg This is the expected outcome: https://i.sstatic.ne ...

Tips for Including a Parallax Image Within a Parallax Section

Currently, I am working on implementing a parallax effect that involves having one image nested inside another, both of which will move at different speeds. My progress has been somewhat successful, however, the effect seems to only work on screens narrowe ...

Choosing a specific category to display in a list format with a load more button for easier navigation

Things were supposed to be straightforward, but unexpected behaviors are popping up all over the place! I have a structured list like this XHTML <ul class = "query-list"> <li class="query"> something </li> <li class="query" ...

Icons from Material Design Lite are not appearing as expected when integrated into an Angular project

Recently, I integrated MDL into my Angular project. While most of it is functioning properly, the MDL icons seem to be giving me trouble... I've implemented them using <i class="material-icons">share</i>, but instead of displaying as an i ...

Can you explain the function of the "Normalize CSS" feature in Fiddle?

I recently came across this interesting fiddle: Demonstration of rounded corners It achieves the desired outcome, however, I noticed that it only works properly when the "Normalised CSS" checkbox is selected. When it's not checked (like in my code), ...

Loading images in advance using JavaScript

I have been searching through multiple forums and cannot seem to figure out the issue. The problem I am encountering is related to a website where there are three images with a hover effect. When the page first loads, there is a delay in loading the backgr ...

Enhance your website with a dynamic navigation menu created with the power of html5

Currently in the process of designing a mobile website, I am facing a specific challenge. The homepage features menu items labeled 'a', 'b', 'c', ..., 'h'. My goal is to initially display only the first three menu it ...

What is the method for obtaining a unique id that changes dynamically?

Having trouble accessing the dynamically generated ID in jQuery? It seems to work fine in JavaScript but not in jQuery. Here's an example of the issue: My jQuery code: var img = $("#MAP"+current_img_height); $("#map").css({'height': img.h ...

Incorporating SCSS into HTML files when they are situated at the same hierarchy

I have <h1 class='title home'> My Title </h1>, and to apply styles I can use the following CSS: .title { font-size: 1.95em; } .title .home { color: black; } While this method works, I a ...

There are two images within a container - one as the background and the other as the foreground. What measures can I take to

I am experiencing an issue with two images on my website. One is set as the background and the other is displayed above it, appearing properly when viewed on larger screens but distorting when the browser window is minimized. You can view the site at the f ...

Utilize grids to ensure consistency in the width of every <li> element across the browser

Is there a way to make the ul element span the entire width of the webpage regardless of window size? http://jsfiddle.net/32hp1w5p/ ul { grid-column: 1/13; list-style-type: none; display: table; margin: 0 auto; } li { float: left; border: ...

Sophisticated filter - Conceal Ancestry

Check out this snippet of my HTML: <td> <a class="button" href="#"> <input id="download">...</input> </a> <a class="button" href="#"> <input id="downloadcsv">...</input> </a> </td> I am ...

What could be causing appendChild to malfunction?

I'm having an issue trying to create three elements (parent and one child) where the third element, an <a> tag, is not appending to modalChild even though it's being created correctly. modal = document.createElem ...

Is there a way to activate a click event when I click on a button that is located outside of the dialog element?

In my Vue 3 app, I am using the native HTML dialog element as a modal. I have managed to position a button outside of the modal with absolute positioning. However, I am facing an issue where I cannot trigger a click event (displayNextModal) when clicking ...

The input box refuses to accept any typed characters

I encountered a strange issue where the input box in the HTML was not allowing me to type anything. const para = document.createElement('p') const innerCard = document.getElementsByClassName('attach') for(let i = 0; i < innerCard.l ...

Modify the background color of an R chunk in a bookdown gitbook

Is there a method to eliminate the grey background color in order to display the colorful class? https://i.sstatic.net/l1Hhi.png https://i.sstatic.net/4aHMF.png ...

Is there a way for my box to avoid reaching the bottom of the page?

Is there a way to prevent my box from reaching the bottom of the page? I am currently using Bootstrap 4 and have tried the spacing utilities, but they don't seem to be effective. https://i.sstatic.net/YRqb4.png Attached is a picture showing that the ...

Stop the "float:right" div from taking up all available space

I encountered an issue while developing a reddit clone. Just to clarify, I'm using bootstrap v5.0 The problem arises when trying to position the sidebar on the right and the content on the left. The layout seems fine at first, but the content sectio ...

Displaying PHP error location

Here is the PHP code snippet I am using: if($_SESSION['msg']['login-err']) { echo '<p class="error">'.$_SESSION['msg']['login-err'].'</p>'; ...