Tips for adjusting the size of an image to fit within the page layout alongside navigation bars

I am currently working on adjusting the size of my image to fit on the page without requiring a scroll. It appears that the jumbotron and navigation elements are causing the image to be pushed down. To address this issue, I thought about placing the image behind the jumbotron and nav components. I attempted using overflow: hidden, but that did not produce the desired results. Another approach involved enclosing everything within my wrapper, which did work, but it caused issues with the responsive design. The image I intend to use as a background can be viewed here: .

Below is the code snippet:

html, body {
margin: 0;
padding: 0;
display: table;
width: 100%;
height: 100%;
}
.jumbotron {
background-color: rgba(51, 51, 51, 1);
padding-bottom: 0;
margin-top: -20px;
margin-bottom: 0;
padding-top: 20px;
h1 {
font-size: 5em;
text-transform: uppercase;
font-weight: 100;
color: #fff;
margin: .2em 0 0 .2em;
letter-spacing: .2em;
span {
font-weight: normal;
}
}
p {
color: #fff;
margin-right: .5em;
margin-bottom: 0;
}
#slogan {
font-size: 1.2em;
margin: 0;
margin-right: 20px;
}
}
.navbar {
background-color: rgba(51, 51, 51, 1);
border-radius: 0;
margin-top: 0;
margin-bottom: 0;
min-height: 0;
border: none;
li a {
outline: none;
text-transform: uppercase;
padding: 5px 15px 10px 15px;
font-size: .9em;
}
}
.wrapper{ // The wrapper is ONLY on the index.html page.
// position: relative;
display: table;
width: 100%;
height: 100%;
text-align: center;
color: #FFF;
background-image: url("https://static.pexels.com/photos/7106/macbook-computer-clean-hero.jpg");
background-position: center center;
background-size: cover;
}
.h2_slogan {
font-weight: 100;
font-size: 3em;
text-transform: uppercase;
margin-top: 1em;
}
<header class="jumbotron">
   <h1>John <span>Smith</span></h1>
   <p class="text-right" id="slogan">Accessible. Affordable. Dependable.</p>
</header>
<nav class="navbar navbar-inverse">
   <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
         <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
         <span class="sr-only">Toggle navigation</span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         </button>
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
         <ul class="nav navbar-nav text-center">
            <li><a href="index.html">Home</a></li>
            <li><a href="about.html">About</a></li>
            <li><a href="#">Skills</a></li>
            <li><a href="#">Portfolio</a></li>
            <li><a href="contact.html">Contact</a></li>
         </ul>
      </div>
   </div>
</nav>
<div class="wrapper">
   <h2 class="text-center h2_slogan">Web Developer & Designer</h2>
</div>

Answer №1

If you want to add a background image behind both the jumbotron and navbar, you can simply insert it into your body tag.

Here's what you need to do:

Update your HTML code like this:

<body id="homepage">


Next, include this in your CSS file:

body {
    background-image: url("../img/header.jpg");
    background-position: center center;
    background-size: cover;
    background-repeat: no-repeat;
}


And that’s all there is to it.

Check out JsFiddle for an example.

We hope this explanation is helpful!

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 is the best method to deallocate and remove the background-color property of CSS once it has been defined?

There is a perplexing issue that I am unable to resolve. The "Shop" section on this page has an intriguing translucent blue-green background: This background is set using the ID "#left-area". Interestingly, on another page, which can be found at , the sam ...

Steps to activate a faded background following a form submission triggered by an On change event

My goal is to implement a greyed-out background upon form submission without a traditional submit button. Instead, I want the form to be submitted when the user selects an option from one of three drop-down lists. Here is a snippet of the form: <form ...

Issue with SVG compatibility in Mozilla Firefox

Just starting out with SVG and here is my code: <div style="width:650px;"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect width="640" height="200" style="fill:#ddd;"></rect> <polyline points="0 200,20 200, 40 200, ...

Implementing a Link Button in Yii2 FullCalendar

I have been successfully using FullCalendar, however I am now in need of adding a link to the button with className='btn' so that when clicked, it redirects to the view page. Code snippet from my controller: public function actionIndex() { $ ...

The website is not optimized for mobile viewing

I have recently made an existing website responsive using Twitter Bootstrap. Everything seemed to work fine when I tested it by resizing the browser window, as it perfectly fit in the viewport. However, upon checking the site on mobile and tablet devices, ...

Move your cursor over a div element while utilizing NgClass

I'm currently working on implementing a hover effect on a div using an Angular ngClass directive. Within the template file, I have a div element with the class "list-item-container" that includes another div with the class "list-item." This "list-item ...

What is a way to increase the boldness of an HTML anchor tag when hovering without using CSS, but by modifying the inline style?

Is it possible to make the following anchor tags appear bolder on hover using inline styles, without utilizing any external or embedded CSS file? <a href="https://en.wikipedia.org/wiki/Internet_of_Things" target="_blank">Internet of things<br& ...

A guide on aligning a CSS item perfectly in the center using absolute positioning

I have been searching for a solution to my problem, but all I found were answers that addressed similar issues in a slightly different way. My challenge involves placing multiple smaller images on top of a larger background image. To achieve this, I utili ...

Is it possible to establish a connection between Firebase Storage and HTML using TypeScript without Angular or React in IntelliJ?

My project goal is to create a functional login and register page using TypeScript. Currently, my code operates without a database, but I aim to implement Firebase for registering user credentials for easy login. I have only come across tutorials using F ...

How to enhance the animation of the Material-UI right side persistent drawer

I am currently working on a sophisticated application that includes several drawers. Specifically, I am encountering an issue with the animations of the right side drawer. While the drawers animate correctly, the parent divs do not seem to follow suit. Eve ...

Struggling with a filtering and sorting problem in my code, looking for some assistance

I'm encountering an issue with an isotope filter menu. The goal is for it to load data based on a timestamp and allow filtering. However, there seems to be a conflict between my sortBy script and the filter script. Below is the code in question: Sor ...

Utilizing CSS3 Patterns: A Guide

Is there a way to utilize these patterns effectively? I attempted to implement them, but it was not successful. http://jsfiddle.net/ujmWH/ I also tried on tinkerbin with the same outcome. Appreciate any advice or guidance. ...

To close the sidenav, simply click anywhere outside of it

Is there a way to close the sidenav by clicking anywhere outside it in my HTML code? <body> <!-- show image while loading --> <div class="se-pre-con"></div> <!-- Header starts here --> <div class = "header"> <!-- ...

Having difficulty populating a form with multiple array values using a loop

I could use some assistance with this issue. I am attempting to populate a form using values from an array, but it's causing problems with the form. My goal is to show the af_rating in the input fields <?php $af_skill = array(12, 9, 6, 3, 4, ...

Purchase Masonry Supplies for Optimal Arrangement

I've been using a neat little tool called jquery-isotope to create a masonry style layout for the blog posts on my website. It's set up with two columns, showcasing two different post types - long form articles and image-only posts. The masonry ...

Dynamic styling updates on page refresh in Next.js

There is a strange issue with my styling that I can't seem to figure out. I have a NavBar set to be 20vh in height and an image set to be 100% in width. However, whenever I refresh the page, the NavBar height decreases and the image width increases si ...

Change the order of columns using CSS in a mobile-first approach

Is there a way to achieve the layout shown in the image using only HTML and CSS? I attempted rearranging the stacked elements for larger screens by: #2: float: left #1: display: inline-block #3: float: right However, this approach did not yield the desi ...

Nextjs Version 13: Implementing a Loading UI for Search Parameter Changes

I am working on a component that handles user input and updates search parameters accordingly. This results in a page refresh to display updated data on the UI. However, despite these actions, the loading.tsx file for this route is not being triggered. Af ...

Switch the background image of a div when hovering over a different div that is not its parent or sibling

I am in the process of building a dynamic portfolio on WordPress and I need some help with a specific functionality. At the top of my page, I have a large banner image, followed by individual thumbnails of my work below. What I want to achieve is the abili ...

Place the text within the contenteditable body of a frame at the specific caret position

Within my iframe object, there is a contenteditable body. I am trying to paste text or HTML elements at the caret position. However, when I attempted this code snippet, I encountered an error message saying Cannot read property 'createRange' of u ...