Transforming a diamond shape to be responsive with content aligned to the center using rotate transform

Struggling to create a responsive diamond shape in the middle of a container with a centered logo? Here's what I mean:

(images are self-drawn graphics)

I've successfully made the diamond shape responsive and centered using this code:

.cover-diamond {
    position: absolute;
    z-index: 3;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    border: solid 1px #EBC65A;
    -ms-transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}

But aligning the <img> logo in the center has been challenging, resulting in complications.

I've experimented with various methods like display:table-cell and vertical-align:middle, but no luck. Can anyone provide the correct approach?

EDIT:

The image is 80% wide with an unknown height, and the diamond shape also has an unknown height due to the 25% padding. Visit my fiddle for more details.

Answer №1

To achieve top and bottom padding on the cover-diamond element, you can use the following CSS:

padding: 12.5% 0;

If you want to add a translateY(-50%) transformation along with rotate(-45deg), you can do so like this:

transform: translateY(-50%) rotate(-45deg);

You may also consider removing the unnecessary styles for display and vertical alignment:

display: table-cell;
vertical-align: middle;

Check out the Working Fiddle for a live example.

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

Setting a global variable in the JavaScript code below

Is there a way to make the modal variable global by setting it as var modal = $("#modal"); ? The code snippet below includes the modal variable and is not functioning properly. It needs to work correctly in order to display: "Hello name, You have signed u ...

Apply the CSS style to make one element identical to another, while modifying a single property

I am currently working with the following CSS: input[type="text"] { border: 2px solid rgb(173, 204, 204); height: 31px; box-shadow: 0px 0px 27px rgb(204, 204, 204) inset; transition:500ms all ease; padding:3px 3px 3px 3px; } My goal i ...

Is there a different option than using 100vh for fixing positioned elements?

I'm working on a flex container with a nested div for top navigation. I want the top-nav to expand and occupy the full height of the viewport when it expands. Setting a height of 100vh seems like the obvious choice, but I'm looking for a more wid ...

Sprite animations function properly with a single canvas, but may encounter issues when utilizing two canvases simultaneously

Experimenting with animated sprites using the canvas element. I've successfully created a test case that works well, but it only functions properly with one canvas element. The goal is to have multiple animating sprites in the end. Any thoughts on w ...

Customize the Underline Color in MaterialUI Select Component

I'm experimenting with MaterialUI and trying to figure out how to customize the underline and text color of the Select component when an item is selected. Currently, the underline and label appear blue after selection with a gray background. Is there ...

Permanent Visibility of Bootstrap 4 Navbar Toggler Icon

I am facing an issue with my navbar-toggler as it remains visible even on a large screen where it is not needed. To view the file, click here. <div class="navbar-header"> <a href="#" class="navbar-brand">Logo</a> </di ...

Scrape all child elements within a specific div class using Selenium

I am seeking to extract the content of the span class labeled as "indigo-text descfont" from the following snippet: <div id="WineDetailContent"> event <span class="blue-text codefont">...</span> <span class=" ...

Is there a way to ensure that a child mimics the behavior of its parent when adjusting the opacity and visibility properties of both elements?

Apologies for the ambiguous title, as I am struggling to accurately convey the issue I am encountering. To clarify the problem, I have created a jsFiddle. In my current layout, all four divs have opacity: 1 and visibility: visible, while divs a and b both ...

Convert HTML tables from Yahoo Pipes into an array of JSON objects

Currently, I am experimenting with Yahoo Pipes in an attempt to convert multiple tables within a DIV into an array of JSON objects. At the moment, the HTML is being successfully parsed. Here is my current setup on Yahoo Pipes I envision each table cell ...

What are the steps for implementing this javascript code in an HTML document?

Recently, I've been seeking advice on how to address the issue of wanting a button click to automatically select the search box on my website. Suggestions have pointed towards using Javascript for this functionality, with the following code recommend ...

What are some creative ways to incorporate a variety of images into my website?

Currently working on a webpage and running into an issue. I have a div called "background" where I am loading several images using the <img>-tag. The problem is that the images are set to float:left;, causing them to wrap onto a new line as they can& ...

Transfer the text link to the following page

In the web project I'm working on, I created a tagcloud. The goal is when a user clicks on a tag, it should redirect to the page showRecipesFromTags.php. <form name="tagform" id="tagform" method="get" action="/showRecipesFromTags.php"> <?php ...

What is the best way to extract data from an XML file stored in a postgres database using jquery?

Hey there! I'm diving into the world of jQuery and XML for the first time. So far, I've managed to read an XML file using jQuery and display it on the front end. Now, my next challenge is figuring out how to store this XML data in a database. Can ...

When the screen is at mobile width, elements with the class "Responsive" are hidden using the display:none; property. These elements can be

Hey there! So, I've got this cool interactive banner on my website. It features 2 slider sections with some awesome products on the right side. The layout is responsive, meaning that when you switch to a mobile screen size (around 515px or less), the ...

Increase or decrease the quantity of items by cloning with Jquery and dynamically changing the ID

Currently, I am working on a jQuery clone project where I need to dynamically add and delete rows. Despite searching extensively on Stack Overflow and Google, I only have a basic understanding of how jQuery clone works. Any suggestions would be greatly ap ...

Issues with CSS positioning

I'm facing an issue with the jQuery drop-down bar slipping behind images on a specific page that uses jQuery innerfade. You can see the problem here: <?php include('perch/runtime.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

Enumerating multiple div elements in Selenium using Python

I am attempting to create a web scraper in Python, but the classes of the tiles are updated dynamically. This means my only option is to use xpaths. The issue I'm facing is that within the divs, they change between different cards. For example, Card ...

Tips for preventing line breaks in CSS while adjusting zoom levels on a webpage

While adjusting the zoom level on the page, I noticed that the text breaks and separates onto another line. The first quick link appears fine, however there seems to be an issue with the second and third quick links as well as the lorem text. Apologies f ...

Create an HTML button with dual functionality

I currently have a button in my HTML that triggers the opening of the sidebar on mobile devices. <a href="#header" class="button scrolly">Contact Me</a> There is also a label element that, when clicked, selects the name field in the contact f ...

CSS3 consumes a high amount of resources

Currently, I am in the process of developing a hybrid app using Ionic. My main focus is on customizing the Ionic main CSS via SCSS and adding my own custom CSS as well. The layout of the app has been achieved without extensive use of JavaScript logic and i ...