Tips for adjusting the header background to ensure it fits perfectly

Seeking assistance in adjusting the header size to accommodate both the image and text content.

Attempts to modify the background size using the "background-size" property have been unsuccessful.

header {
  background-color: red;
  background-size: 200px 100px;
}

header h1 {
  font-size: 50px;
  text-align: center;
  text-decoration-line: underline overline;
  text-decoration-style: double;
  position: relative;
  margin-top: -100px;
  margin-bottom: 100px;
}

header .pic {
  border: 5px #000 outset;
  border-radius: 50px;
}
<header>
  <img class="pic" src="" alt="" width="200px">
  <h1>Placeholder Text</h1>
</header>

The issue lies in the positioning of the header background, which currently stops at the midpoint of the text and image. The desired outcome is for the background to extend to the bottom of whichever element—text or image—is positioned lower.

Answer №1

Here is a suggestion to try out:

header {
    background: url("img/index.jpg") ;
    background-color: red;
    background-size: 200px 100px;
}

header h1 {
    font-size: 50px;
    text-align: center;
    text-decoration-line: underline overline;
    text-decoration-style: double;
    position: relative;
    margin-top: -100px;
    margin-bottom: 100px;
}

header .pic {
    border: 5px #000000 outset;
    border-radius: 50px;
}
<header>
<h1>Placeholder Text</h1>
</header>

Answer №2

Creating a background image within a container can be achieved with the following CSS code:

.banner {
 background-image: url('https://picsum.photos/800/400');
 background-size: cover;
 background-repeat: no-repeat;
 height:100vh;
 width: 100vw;
}

h1 {
 color: black;
 font-size: 50px;
 text-align: center;
}

Rather than using a standard image tag, you specify the background image through CSS properties.

To view a live demonstration, visit: https://codepen.io/SaraSmith/pen/ejOJLW

Answer №3

Perhaps you are searching for the CSS property display: flex

Give this a try

/* Reset 
*******************/  
* { margin: 0; padding: 0; box-sizing: border-box; }
img { max-width: 100%; }

/* Styles 
*******************/  
header { background-color: red; display: flex; align-items: center; justify-content: space-between; padding: 1rem; }  
header .pic { width: 200px; }  
header h1 {
    font-size: 50px;
    text-align: center;
    text-decoration-line: underline overline;
    text-decoration-style: double;
    position: relative;
}
<header>   
    <img class="pic" src="https://sg.fiverrcdn.com/photos/105746482/original/3e2a4ad867ed23117cfda223391c35ab42bb99fc.png">    
    <h1>Placeholder Text</h1>
</header>

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

Struggling to retrieve a class within an <a> element in jsTree when hovering?

I'm currently utilizing jsTree and below is how I'm initializing it... function setupJSTree(data){ $("#treeSelector").jstree({ "plugins" : ["themes","json_data","UI","types"], "themes" : { "theme":"def ...

Dynamically switch between showing more and showing less content on each div

Whenever the specific show more button is clicked, the content should be displayed without causing the entire component to re-render. I have tried using a useState, but each time the button is clicked, the whole component re-renders, resulting in long load ...

What is the best way to download a modified canvas with filters using the solutions from stackoverflow?

There have been numerous inquiries regarding how to apply CSS filters to an image, with some solutions that don't utilize CSS filters but still achieve the desired outcome. However, for someone new to JavaScript like myself, these answers can be confu ...

Discover the process of retrieving HTML elements from a different webpage and incorporating them into your own site

As a newcomer, I'm in search of a code that can help me fetch an HTML string from one webpage and use it in another webpage. To illustrate my point, consider the following mock examples. Example 1: Mysite.com/A.html <body> <!---My Script Goe ...

I'm not entirely sure why I keep getting the error message stating "Cannot read property 'innerHTML' of null"

Having an issue with my JavaScript code where I am trying to insert a new table row into the HTML but keep getting an error message that says "Uncaught TypeError: Cannot read property 'innerHTML' of null" <!DOCTYPE html> <html lang=" ...

When working with ReactJs, you may encounter a delay in adding a class to the li element upon click event

I am facing an issue where the first li element works perfectly when clicked, but for the rest of the elements, I have to click twice to apply the desired styling. Can anyone explain why this behavior is occurring? App.js import React, { Component } from ...

Is resizing images using HTML/CSS more effective than tools like Fireworks?

Usually, I start by creating an image in Fireworks, adjusting it to fit the right dimensions for the website, and then exporting it as either a JPG or PNG file. This process has always worked well for me. Lately, I've observed that when I insert a la ...

tips for deleting spacing in the <pre> element

I need help with formatting my text within <pre></pre> tags. The issue I'm facing is that there is an indent on the first line and I want to remove it. Can someone assist me in modifying this code to achieve that? @foreach (v ...

Updating the checklist status using an ajax request: A step-by-step guide

Is it better to update the checklist status by making individual ajax calls for each checklist item or by making one call and updating it once completed? I have included a template showing how it currently looks and what I am aiming for. Unfortunately, I ...

jCarouselLite problem: Images refusing to display in jQuery

My website currently has jCarouselLite integrated, but I'm facing an issue where the PREV and NEXT buttons are visible, yet no IMAGES are showing up. The image links seem to be correct. Do you have any suggestions? jQUERY: <script type="text/jav ...

Unable to back out of side navigation

My side navigation menu is giving me some trouble. It opens up just fine when I click the button, but it won't close back up when I click it again. The button is supposed to toggle between opening and closing the side navigation. I've looked at ...

Deleting a button from a list item or array in Angular 12

Having some trouble removing a list item with the click button, I've tried a few options but nothing seems to be working. Can anyone offer assistance? I need to remove a list item from my users array when clicked. Below is the Typescript code and cor ...

Is it possible to use a hashtag and exclamation mark in URLs as a folder designation?

Can anyone guide me on how to make my pages look similar to the ones on Grooveshark, like this example: ? I'm looking for a tutorial or resources on implementing this layout using jQuery or JavaScript. ...

Troubleshooting: Ruby on Rails and Bootstrap dropdown issue

Having some issues with implementing the bootstrap dropdown functionality in my Ruby on Rails application's navigation bar. I have made sure to include all necessary JavaScript files. Below is the code snippet: <div class="dropdown-toggle" d ...

Why is it important to incorporate the CSS property background-repeat: repeat; into our code?

It is believed that if you don't expressly mention the background-repeat in CSS styling, browsers will automatically set it as background-repeat: repeat. With this default behavior in place, one might wonder why there is even a need for a separate ba ...

CSS Troubleshooting: Image failing to load

Having an issue with bootstrap/css. I'm trying to load an image from the source folder using this CSS code: background: url('../img/home.jpg') no-repeat; Unfortunately, the image is not showing up in my home section on the page. https://c ...

The functionality of jQuery date picker and time picker is compromised when the fields are generated dynamically

I am currently utilizing the jQuery code below to dynamically create multiple input fields, which include time pickers and date pickers. However, I am encountering an issue where they are not functioning as expected. $('#add_another_event').clic ...

SVG utilizes a distinct color for every individual path

I have an SVG file containing two different paths. <path d="M 84.4 53.2 C 75.3 50.1 67.1 48.5 59.6 48.3 C 51.2 48 45.2 47.5 41.5 46.5 C 35.7 45.1 29.9 42.4 23.9 38.4 C 21.6 36.9 19.4 35.2 17.3 33.2 C 19.4 34.2 21.6 35 23.9 35.6 C 27.3 36.5 34.1 37 44 ...

Issue with displaying Bootstrap modal on top of another modal

Upon clicking the "Click me here" button, a modal pops up and displays a toast message expressing gratitude. The thank you modal should remain open on top of the save modal even after clicking save. However, upon saving, an error message appears: Cannot r ...

Troubleshooting webpack issue: CSS background image fails to load

After reading numerous posts regarding CSS background images not loading, I believe my situation is unique. Here is how I've configured my webpack setup (relevant parts only): { test: /\.(png|svg|jpg|gif)$/, use: [ { ...