A web page with a full-width header, content constrained to a set width, logo elements displayed with flexbox, and a footer that

I've been facing challenges in making this website responsive on both desktop and mobile devices. Initially, the header background image wasn't displaying as intended, followed by issues with the flexbox logo elements in the header and the sticky footer. Unfortunately, these components have not functioned properly together. I decided to remove the complicated code for the sticky footer. Describing the problem has proven to be quite difficult, so I have created mockups for both desktop and mobile views. Notably, the second flexbox div ("Register today") should move out of the header, stretch to fit the content width, and attach to the bottom on mobile.

Key concerns at the moment:

  1. Moving Div #2 ("Register today") outside the header in the flexbox layout on mobile and expanding it to match the content width seems challenging. As a flexbox inherently contains all its divs, hiding Div #2 on mobile and showing an alternative element for "Register today" might be necessary

  2. Developing code for a sticky footer that is compatible with the existing setup

If there are any queries or uncertainties, please feel free to ask in the comments, and I will update the question accordingly.

Desktop Design

https://i.sstatic.net/tLdG6.png

Mobile Design

https://i.sstatic.net/vy0RX.png

html {
max-width: 800px;
margin: 0 auto;
}

body {
background-image:url('/img/bg.png');
background-repeat:repeat-x;
}

header {
display:flex;
flex-wrap: wrap;
height:116px;
background-color:grey;
justify-content:space-between;
align-items:center;
}

#logo {
margin-left:15px;
}

#register {
margin-right:35px;
}

#register a{
color:white;
text-decoration:none;
font-weight:bold;
font-size:x-large;
}


/*#content 
{
margin: 0px 15px 0px 15px;
}
*/

footer
{
text-align:center;
font-size:small;
}

#copyright{
}


@media only screen and (orientation: portrait) {
html{
padding-right:15px;
padding-left:15px;
}

#logo {
margin:0;
}

#register {
background:blue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8> 
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css.css">
</head>

<body>
<header>
<div id="logo"><a href="/" title="Home"><img src="/img/logo.png" srcset="/img/logo.png 1x, /img/logo2x.png 2x" width="354" height="85"></a></div>
<div id="register"><a href="/register">Register today!</a></div>
</header>

<div id="content>
<h1>Text content</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>


<footer>
<div id="copyright¬">&copy; Copyright 2019 Copyright footer. Privacy policy</div>
</footer>
</body>
</html>

Answer №1

Are you looking for a specific layout? Check out this example: (If your browser doesn't shrink below 600px width, adjust the devTools to the right or left and expand it to make the View Port smaller; less than 600px for this scenario).

To see the responsive (mobile) layout, resize the window to under 600px width. The Stack Overflow editor may not display it accurately, but the code is correct. Alternatively, view it here on codesandbox (resizing the window may be challenging, hence the first link).

The 600px viewport width can be adjusted as needed. All styling code outside the media query pertains to responsiveness/mobile - for View Port (VP) width under 600px (or portrait media query); while everything inside is for VP width above 600px (min-width: 600px applies the styling).

I noticed you wanted to vertically center your content. This can be achieved using JS with simplicity or some CSS magic. If you're eager to do so, feel free!

As for the transition between mobile and desktop layouts, I set the desktop code to apply at 600px, ensuring certain elements stretch to 100% width before maxing out at the specified 800px.

Hope you find this helpful.

Answer №2

For the purpose of this demonstration, I have made a change to your media query from orientation: portrait to orientation: landscape. The effectiveness of this change on your actual site may vary, but I wanted to provide my solution. Please note that these are just two possible strategies among many for achieving this outcome:

1) Shifting Div #2 ("Register today") outside the header within the flexbox layout in mobile view and extending it to match the content width

To achieve this, give the header a position: relative along with a margin-bottom: 30px, while styling div#register with height: 30px, position: absolute, and bottom: -30px.

2) Crafting code for a sticky footer that remains compatible with the above changes

Set html and body with height: 100%, apply a display: flex along with flex-flow: column to the body element, and assign flex: 1 property to div#content.

  html {
  max-width: 800px;
  margin: 0 auto;
}

body {
  background-image: url('/img/bg.png');
  background-repeat: repeat-x;
}

header {
  display: flex;
  flex-wrap: wrap;
  height: 116px;
  background-color: grey justify-content:space-between;
  align-items: center;
}

#logo {
  margin-left: 15px;
}

#register {
  margin-right: 35px;
}

#register a {
  color: white;
  text-decoration: none;
  font-weight: bold;
  font-size: x-large;
}


/*#content 
{
margin: 0px 15px 0px 15px;
}
*/

footer {
  text-align: center;
  font-size: small;
}

#copyright {}

/*@media only screen and (orientation: portrait) {*/
@media only screen and (orientation: landscape) {
   html, body{
      margin: 0;
      height: 100%;
   }
  html {
    padding-right: 15px;
    padding-left: 15px;
  }
  header{
     background: gray;
     display: block;
     width: 100%;
     position: relative;
         height: auto;
    margin-bottom: 30px;
  }
  footer{
     background: lightblue;
  }
  #logo {
    margin: 0 auto;
    max-width: 356px;
  }
  #register {
    background: blue;
    margin: 0;
        height: 30px;
    position: absolute;
    bottom: -30px;
    width: 100%;
  }
  
  body{
     display: flex;
     flex-flow: column;
  }
  
  #content{
     flex: 1;
  }
  <header>
    <div id="logo">
      <a href="/" title="Home">
        <img src="http://placekitten.com/354/85" />
       </a>
    </div>
    <div id="register"><a href="/register">Register today!</a></div>
  </header>

  <div id="content">
    <h1>Text content</h1>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>


  <footer>
    <div id="copyright">&copy; Copyright 2019 Copyright footer. Privacy policy</div>
  </footer>

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

Experience a dynamic sliding effect when hiding elements with AngularJS using the ng-hide directive and ng

If you take a look at my jsfiddle http://jsfiddle.net/99vtukjk/, you'll see that currently, when clicking on the left or right text, the hide animation moves upwards. Is there a way to change this animation to slide and fade to the left menubar instea ...

When incorporating `Ionic/core` into my project, it unexpectedly alters my scss styling

Exploring StencilJs: In my project using StencilJs, I aim to create a wheel time picker with 3 columns for hours in 12-hour format and minutes which can vary based on the provided array such as [0,15,30,45] or [00,30]. Additionally, there will be options ...

What is the best way to generate an accordion populated with data from a MySQL query?

Everything is in order, I've got all the chapters and video series extracted without any issues: $id_course = 1; $stmt = $con->prepare("SELECT c.chapter, v.preview, v.title_video, ...

Is there a way to upload an image without utilizing or concealing the `<input type='file' />` element?

Currently, I am developing a PHP script that retrieves the directories and files from specified local computer drives. The goal I am striving for is to enable users to upload an image to my server by clicking on its name from the listing, without using th ...

AngularJS (ui-mask) provides a valid input mask feature

i encountered an issue while trying to create an input mask using ui-mask in AngularJs. I want the textarea to turn green when the entered string is correct. However, in my case, the textarea starts off green and then turns red when a word is typed until t ...

Anchor link leading to an incorrect location

Sorry for the potentially silly question, but I'm struggling to figure out what's happening here. I'm currently working on a website and trying to create an anchor link at . I've placed the anchor just before in this code: <a name ...

Expanding Vue Tabs with Bootstrap: Manipulating tab-content to perfectly fill parent height

On my webpage, I have implemented a tabs component called b-tabs. This component is enclosed within a parent div with a specific height. I am trying to make the content of the tabs take up the full remaining height of the parent component. https://i.ssta ...

Activate the parent navigation link when on sub-pages

I want to ensure that the parent navigation item is highlighted when a user is on a child page based on the URL. For example, if the user is currently viewing foo1-child and the parent is foo1, I need to apply the active class to Foo 1: http://foo.com/foo ...

Modifying the color of the accordion icon in Bootstrap 5.3 by utilizing a root variable

Is it possible to change the icon color of Bootstrap 5.3's accordion component to match the color of the heading text? I have successfully set the heading text color using a CSS root variable var(--body-text). However, when trying to override the SVG ...

jQuery for Dynamic CSS Class

Is there a way to apply a different style to a link upon page load with jQuery? I would like the link to appear highlighted when the user navigates to a specific page, such as clicking on the About Us menu item. I want to use jQuery to achieve this effect. ...

jQuery text alignment breaking bug

I am attempting to create an overlay for a couple of my divs to prevent users from progressing without completing previous tasks. The overlay is functioning correctly and the message is displaying, but I encounter issues when trying to center the message. ...

Incorporating PHP script within a stylesheet

Is it possible to include php code within a css file for adding conditions to css properties? styles.css <?php if($suserid == 2) { ?> .proverb { border:0px solid blue; margin-left:34px; width:250px !important; margin-top:6px; } <?php } e ...

Troubleshooting head.js and jQuery problems in Chrome/Firefox 5

After rendering the page, it looks something like this: <!DOCTYPE html> <html> <head> <script> head.js("js/jquery.js", "js/jquery.autocomplete.js"); </script> </head> <body> ... content ...

Move a 'square' to a different page and display it in a grid format after clicking a button

I am currently developing a project that allows students or schools to add projects and search for collaborators. On a specific page, users can input project details with a preview square next to the fields for visualization. Once the user uploads the ...

Extracting information from HTML and transferring it to Javascript using jQuery

My goal is to utilize jsGrid for showcasing database data without repeating code extensively. I aim to generate separate grids for each <div> with a specific id while passing on relevant values accordingly. To clarify my objective, here's a sni ...

I'm looking to add a price ticker to my html webpage. Does anyone know how to do this?

PHP Code <?php $url = "https://www.bitstamp.net/api/ticker/"; $fgc = file_get_contents($url); $json = json_decode($fgc, true); $price = $json["last"]; $high = $json["high"]; $low = $json["low"]; $date = date("m-d-Y - h:i:sa"); $open = $json["open"]; ...

What is the best way to activate a JQ function with my submit button?

Is there a way to trigger a JQ function when clicking the submit button in a form? I managed to make Dreamweaver initiate an entire JS file, but not a particular function. ...

Discover the size of an image using JavaScript by accessing innerHTML

I'm currently working on a unique AJAX function that retrieves image URLs without using node append for insertion. Instead, I opted to utilize innerHTML, but this has posed challenges in accurately obtaining the file dimensions. My current approach i ...

What steps can I take to troubleshoot a non-functional button in a Bootstrap 5 Modal?

I have a Django based web site that utilizes Bootstrap 5 for styling. Among the data presented on the site is a table with a notes column containing lengthy text. To enhance readability and keep the table compact, I attempted to integrate the Bootstrap Mod ...

Is there a way to eliminate the horizontal line in my Table design?

Is there a way to eliminate the horizontal line from the table? css, html <table border="1" style="width:100%; border-collapse: collapse"> <tr> <th>Prepared By:</th> <th>Released ...