Is there a way to display a position:fixed image on a separate line or as a block element?

I am struggling with the positioning of a menu button image below a logo div on the right side of the viewport. The issue arises when my body text starts directly below the logo div, causing it to run behind the fixed position image if it's a large paragraph.

Does anyone know how I can make the fixed-position image act as its own line, force a line break, or work with display: block to push the text down so it starts below the image?

I have attempted using display: block with the image and image div, but it seems like I might be styling it incorrectly. Clearly, I am a bit lost here, so apologies for any confusion!

<head><style>
    img.logo {
    height: 3em;
    max-width: 80%;
    width: auto;
    padding: .5em;
    display: block;
    margin-left: auto;
    margin-right: auto;}

div.menu {
    width: 100%;
    display: block;}

.menu img {
    position: fixed;
    right: .5em;
    padding: .5em;}
</style></head>

<html>
    <img class="logo" src="http://doc.jsfiddle.net/_downloads/jsfiddle-logo-white.svg">
    <div class="menu">
        <img src="https://dl.dropboxusercontent.com/u/95732802/menu.svg">
    </div>

    Here is where some text should go!
</html>

You can check out the fiddle for this issue here.

Answer №1

An element with the CSS properties position: fixed; or position: absolute; is removed from the normal document flow, meaning changing its display property to block will have no effect.

If you are aware of the height of the image, you can simply add a margin or padding, like this:

header {
    padding-bottom: 2em;
}

Alternatively:

header {
    margin-bottom: 2em;
}

Or, if you only have a series of <p> elements following the <header>:

header + p { /* for a p after it */
    margin-top: 2em;
}

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

Troubleshooting: Why Printing a List in JSP Might Not Be Working

Update: All systems are functioning perfectly - it turns out the issue was just a simple mistake made by the original poster. Thanks to all the kind individuals who diligently searched for a flaw that didn't actually exist. Also, appreciate the helpfu ...

Ways to prevent individuals from inserting code into my form?

Currently, I have a form that feeds data into a database, and then these values are displayed on the page. My struggle lies in finding a way to prevent all inserted code from being executed when submitted through the form. This represents the structure of ...

mobile-responsive vertical alignment using Bootstrap

Here is a jsbin that demonstrates the issue and here is the markup: <div class="row"> <div class="col-sm-4 xs-12"> <strong>UK Postcode</strong> </div> <div class="col-sm-4 xs-12"> <strong>Other Fie ...

Enclose an image with a <div> element while maintaining the <div> height at

Encountering a challenge where positioning an element on top of an image at specific coordinates (20% from the top and 30% from the left) is required. Initially, the solution involved wrapping the image in a div with a relative position and using absolute ...

Having trouble retrieving data from a contact form with php, js, and ajax?

I am facing an issue with my contact form on a website. I am unable to receive the filled fields from the contact form via email. Can someone please help me figure out what is wrong with the code or suggest an alternative solution? Any assistance in fixing ...

Switching the file format from HTML to .ASP resulted in the loss of the website's design elements and images

After initially creating an HTML file, I decided to rename it with a .asp extension for uploading online. To do this, I copied the original HTML file and moved it into a folder containing .asp files. However, after replacing the existing file, my website l ...

Retrieving CSS content and resolving image references from external CSS files for the Link Validator

Currently, I am developing a Link Validator tool designed to analyze and validate all links within a specific domain based on a given seed page. For instance, when analyzing http://www.example.com/, the tool should assess all links associated with example. ...

Visual Studio has issues with div elements nested within dl elements

There appears to be an issue with Visual Studio 2019 (not tested previous versions) not supporting div tags within dl. When copying and pasting code from the source (3rd example) into an HTML page in Visual Studio, warnings are generated. In the followin ...

My PHP form is not functioning properly, despite having completed all the steps correctly

I am having trouble with my PHP form. It shows a success message, but I never receive any email notifications. I have tried everything to fix this issue, but nothing seems to work. Below is the main PHP code I am using: <?php error_reporting(E_ALL ^ E ...

AJAX fails to retrieve a result

I've been attempting to grasp the concept of using ajax, but unfortunately I have not been able to receive any response. Here is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta ...

What is the best way to identify the complete template of an Angular component's CSS without mentioning any specific tags?

Typically, I structure each view with an outer DIV that serves as the foundational background. <div class="outer"> <!-- Content goes in here --> </div> Then, within my SASS file, I apply styles to it like this. div.outer { ... } Thi ...

The Best Way to Calculate a Total Sum with Comma-Separated Values in AngularJS

In my application, I am utilizing the MEAN stack with AngularJS as the front-end. I am trying to figure out how to calculate the total sum and include comma values. I have managed to get the total sum value, but the comma value is not being calculated prop ...

What is the best way to update the text within a Span element as the user moves through the Jquery slider?

Can I utilize jQquery to dynamically alter the text content of my "video_box_label" span element based on the active slide in my "flexslider" slideshow? For instance, when the slideshow transitions to the second slide, I want the text to change from "Mee ...

Encountering a 404 Not Found issue while trying to add scripts with Node.js

I am currently working with a node server and an HTML file, where the default route is being directed. server.js /** * Created by Creative Coder on 10/26/2015. */ var express = require('express'); var mysql = require('mysql'); var a ...

Unable to achieve proper centering and bottom vertical alignment for div element using CSS and HTML codes

I am facing an issue with centering and vertically aligning a div inside another div. Despite setting the CSS properties, it doesn't seem to work properly. Can you please review my code below: #outer { border: 1px solid black; height: 500px; } #in ...

jquery select2 not functioning properly following ajax call

I am having an issue with my select2 control on the website. Initially, everything works perfectly fine when the site loads. However, if the content of the div named "simpleDiv" where the Select2 is located, is loaded via Ajax, the Select2 fails to display ...

Looking to spice up your static HTML site? Dive into the world of Ruby on

I recently developed an app that features a static HTML webpage containing text and images, and now I'm interested in incorporating Ruby on Rails to explore its capabilities further. After creating a basic RoR application, I copied the HTML content f ...

Verify whether the div contains a height style. If it does, refrain from altering the height

In my design, I have a main container div with a set height (which may change depending on css media query). There is also a parent div where the user can input a height value (usually in percentage, occasionally in pixels). The child divs allow the user t ...

What is the best way to incorporate background colors into the sidebar menus of grandchildren?

I am currently utilizing the advanced sidebar menus page which can be accessed through this link: https://wordpress.org/plugins/advanced-sidebar-menu/ Within the plugin, there are widgets that allow users to add background colors and text colors to child ...

Ways to retrieve element values in JavaScript without relying on IDs

Imagine for a moment that I had the subsequent code: <div class="post"> <h2 itemprop="name"> <a href="http://www.example.com">The Post Title</a> </h2> <div class="details"> <span> <em class="date" ...