Place a central div above and nestled between two other divs using Foundation Zurb

Recently, I've started using Foundation and I must say, I'm quite impressed with it. However, I have a query regarding centering the logo in between two full divs horizontally. The current code I have works well but doesn't adapt to screen changes. Is there a more efficient way of achieving this within Foundation?

Is there a better method to integrate the logo into Foundation so that it automatically resizes when the screen size changes? Or is manually resizing for different screens the only option?

HTML

<div class="row fullWidth"> 
    <div class="large-12 columns box">
        <img src="logo.png" class="logo">
     </div> 
</div>

<div class="row fullWidth"> 
    <div class="large-12 columns box">
    </div> 
</div>
 

CSS

.fullWidth { 
  width: 100%; margin-left: auto; 
  margin-right: auto; max-width: initial; position: relative; 
}

.logo{ 
  position:absolute; left: 50%; 
  top: 20px; margin-left: -100px;// half-width of logo z-index: 20; 
}

.box{ 
  background-color: #333; 
  height: 120px; 
  margin-bottom: 10px; 
} 

Answer №1

If you have the logo's height information, using a negative margin-top can also work, but you might need to enclose the two outer divs within a new div.

Your HTML structure could look like this:

<div class="outer">
    <div class="row fullWidth">
        <div class="large-12 columns box"> 
            <img src="logo.png" class="logo">
        </div>
    </div>
    <div class="row fullWidth">
        <div class="large-12 columns box"> </div>
    </div>
</div>

And here is how your CSS styling may be set up:

.outer {
    width: 100%;
    position:relative;
}

.fullWidth {
   width: 100%;
   margin-left: auto;
   margin-right: auto;
   max-width: initial;
   // position: relative; // OMITTED
}

.logo{
    position:absolute;
    left: 50%;
    top: 50%;
    margin-left: -100px;// half-width of logo
    margin-top: -100px;// half-height of logo
    z-index: 20;
}

Answer №2

Here are the steps to center it:

<div class="row centerContent">
     <div class="large-12 columns box">
         <img src="logo.png" class="logo">
      </div>
      <div class="row centerContent">
         <div class="large-12 columns box"> </div>
    </div>
</div>

View Demo

Answer №3

Are you having trouble resizing the logo? If that's the case, you can attempt the following code:

.logo{
    position:absolute;
    left: 50%;
    top: 20%;
    margin-left: -100px;//half-width of logo
    z-index: 20;
}

After applying this code, your logo should now be resizable.

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

What could be causing the Bootstrap collapse feature to malfunction?

<nav id="na-vrh" class="navbar navbar-expand-lg navbar navbar-dark bg-dark"> <div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> < ...

Is there a way to display a secondary header once the page is scrolled down 60 pixels?

.nav-header2{ background: purple; display: flex; justify-content: center; align-items: center; } .header2-container{ width: 68vw; height: 60px; padding: 0 2vh; border: 1px solid red; ...

Guide on incorporating HTML data into an existing webpage

Requesting assistance in creating an HTML page that features a dynamic drop-down menu. The drop-down should trigger a list to appear upon selection, which can be sourced from either a text file or plain HTML document. The envisioned functionality involves ...

If a span element does not exist, a bullet can be added within it

Is there a way to add and remove a bullet from an li element with the selected class, only if there is no span already present? Currently, every time the link is clicked, a bullet gets added. What would be the best approach to avoid adding multiple bullets ...

Having issues with your PHP dropdown database code?

I am having trouble with the code below. It seems to display the HTML portion correctly, but it is not fetching the data from my database. My goal is to populate a drop-down list with data from the database and then display it in a table below when the u ...

Inscribe latitude from marker onto input field

Currently, I am working on a feature where markers are added to Google Maps API v3 by clicking on the map. Each marker then displays its coordinates in an info window. However, I am facing an issue with picking up the latitude and longitude values and inse ...

How can I search for a particular string in JavaScript?

I have a unique custom div that has been modified to function as an input element. Inside this custom div input element, there is a <p> tag with a default placeholder text. My goal is to verify whether the content of this div is empty or contains new ...

Seeking a material design template for mandatory form patterns

I'm struggling with getting my required field patterns to work using regular expressions. Additionally, I'd like to center my 'onboard' button on the page. You can find my code at this StackBlitz link: https://stackblitz.com/edit/angula ...

Are you seeing empty squares in place of Font Awesome icons?

If the Font Awesome icons are displaying as blank squares in all browsers despite correctly linking the stylesheet and attempting to install the package through npm which results in a npm ERR! code E401, it can be frustrating. Even after checking the brows ...

What are some ways to display alternative content when JavaScript is not enabled?

When JavaScript is disabled, I want to display an entirely different set of content. While I am aware that the <noscript> tag can be used for this purpose, how can I ensure that the remaining page elements are hidden as well? Any suggestions would b ...

Whenever I try to include something within the `componentWillUnmount` function,

I'm currently learning React on my own. I've been trying to save session data in my componentWillUnmount method. However, when I add code inside componentWillUnmount, nothing seems to happen. I tried debugging by adding console logs and debugger ...

Use jQuery to parse the JSON below and then showcase the information in an HTML table

Can anyone assist me with parsing the following JSON using jQuery and presenting it in an HTML table? I want to showcase the values of "key" and "doc_count" in an HTML table. Your help would be greatly appreciated. Please find the JSON data below: { ...

Revitalize Your RAILS Application with Automatic Partial Refresh

Using a controller events with action show : def show @event = Event.get(params[:id]) if !connected? || !@event return redirect_to request.referrer || root_path end @requests = @event.get_requests Inside the view show.html.erb: ...

When utilizing a JQuery .animate function to transition a div from 0px to 450px in height, an unintended margin is produced during the process

I have been attempting to implement a collapsible footer using JQuery. While I have successfully integrated all the animation functions, there seems to be an issue with the animate function affecting the div (id=draw) by creating an unseen margin beneath i ...

CSS - owl carousel automatically stretches images to full width

Here is the code snippet that I am working with: $(document).ready(function() { $('.owl-carousel').owlCarousel({ loop:true, items:4, autoplay:true, autoplayTimeout:2000, autoplayHoverPause:true }); }); #owl-demo ...

Preventing the negative consequences of being colorblind through programming techniques

My experience as a web developer has taught me that poor color contrast on a website can severely impact revenue. I am determined to change this, but have encountered an issue. On my site, there is a section where users can select a color and see it displa ...

"Troubleshooting IE-specific problem: Loading dropdown options dynamically with AJAX on change

Struggling with a particular issue lately. I'm attempting to populate a second dropdown menu based on the selection made in the first one using jquery ajax. Surprisingly, it works flawlessly on all browsers except for IE 11. Below is the ajax functio ...

Is it possible to alter the background color once the content of an input field has been modified?

I am working with an angular reactive form and I want to dynamically change the background color of all input fields when their value is changed. Some of these input fields are pre-populated and not required. I came across a potential solution on Stack Ove ...

Having trouble with media queries on my iPad

I currently have a media query set up as follows: @media only screen and (max-width: 959px) It works when I resize my browser, however, it does not seem to be functioning correctly when my iPad is in portrait mode. When I include and (max-device-width: 9 ...

Explaining the Usage of Nav-pills in Bootstrap v4

I am looking to align my navigation bar across the width of the div. However, I am currently using Bootstrap v4 and the nav-justify class is not available yet. Below is the code snippet: <ul class="nav nav-pills"> <li class="nav-item"> ...