What are the best methods for creating a responsive webpage with images and text in the header?

My webpage features a razor page with a header component called PageHeader.razor. I have been attempting to make it responsive, but I am facing an issue where the text and image overlap when viewed in responsive mode.

What could be causing this problem?

Here is the code for the page with the header:

<div class="row myheader">
    @{
        string title = "This is a title";
        string subtitle = "This is a subtitle";
        <PageHeader Title=@title Subtitle=@subtitle />
    }
</div>

... and the header component:

    <div class="d-flex align-items-center">
        <div class="col-2 me-0">
            @{
                string url = $"/images/trofee.png";
                <img src=@url class="rounded float-start image-responsive" height="256" width="256" />
            }
        </div>
        <div class="col-10 ms-0 rounded mb-3 align-self-end text-start">
            <div class="row mytitleheader">
                <h2><span>@Title</span></h2>
            </div>
            <div class="row mysubtitleheader">
                <span>@Subtitle</span>
            </div>
        </div>
    </div>

@code {
    [Parameter] public string Title { get; set; } = string.Empty;
    [Parameter] public string Subtitle { get; set; } = string.Empty;
    [Parameter] public string ImageType { get; set; } = string.Empty;
}

... along with the CSS styles applied:

.myheader {
    background: -webkit-linear-gradient(left, yellow, orange); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(right, yellow, orange); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(right, yellow, orange); /* For Firefox 3.6 to 15 */
    background: linear-gradient(to right, yellow, orange); /* Standard syntax (must be last) */
    box-shadow: 10px 10px 5px black;
    margin: 4px 7px 25px 4px;
}

.mytitleheader {
    color: red;
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    font-weight: bolder;
    font-style: italic;
}

.mysubtitleheader {
    font-style: italic;
    color: blue;
    font-size: 1.5rem;
}

Check out examples of the page in small and large views:

https://i.sstatic.net/73Zpc.png and: https://i.sstatic.net/esUFI.png

Answer №1

The reason is that you have specified col-2 for the parent of the img element, which results in a width of 16.666%. To make the parent of the img element 256x256, simply remove this specification.

<div class="me-0">
         @{
              string url = $"/images/trofee.png";
              <img src=@url class="rounded float-start image-responsive" height="256" width="256" />
          }
</div>

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

A fading transparency box on the border

Looking for a box with varying opacity from left to right (See image for reference - the red marked box has decreasing opacity from right to left). Here is my attempt: .waterMark { background-color: #FFFFFF; float: right; opacity: 0.6; position: ...

What is the best way to synchronize the scale of images with the tempo of a song?

I just started learning CSS, JS, and HTML and I have a question about scaling an image based on a song. Despite searching through YouTube and various forums, I still haven't found a solution. Any help would be greatly appreciated :) Here is the HTML ...

Can you tell me why the jquery datepicker control is only loading a portion of the CSS?

Working on a new C#/ASP.Net application and I decided to incorporate the datepicker control that I've used before. I transferred all the necessary components from my previous app to this one. The appearance of the datepicker in the old app was like th ...

Is the textarea's shape out of the ordinary?

Most textareas are typically rectangular or square in shape, similar to this: However, I am interested in having a custom-shaped textarea, like the example below: Is it feasible to achieve? ...

Instructions on adding a solid border color to a circular div using CSS

Hey there! I'm curious, is it possible to style a straight border color on a rounded div using CSS? Here I have some basic Tailwind CSS code. <div class="rounded-2xl w-72 h-20 border-l-4 border-l-yellow-500"> ... </div> In the ...

Retrieving all buttons from a webpage and removing those with a specific background-image using JavaScript

Hey everyone, I'm still learning about javascript and other web development languages. My current task is to locate all the buttons on a webpage and remove the ones that have a specific background image. I know about using getElementsByTagName but n ...

When it comes to adjusting the height of an element, there are two ways to go about it: using $(element).height

function adjustHeight(){ var headerHeight=$(element).find('.header').outerHeight(); console.log(headerHeight); var temp=$(window).height()-headerHeight; console.log(temp); $('.users ...

Why won't divs align vertically in the center?

I'm struggling to create a navigation bar layout where the icons are centered both horizontally and vertically within their cells. http://jsfiddle.net/digorydoo/j2v5m7gr/ I can't seem to pinpoint what's causing the issue with my current la ...

What is the best way to position an image in the bottom right corner of a fluid div container?

I am struggling to position this icon image at the bottom right hand corner of this div, so that it appears as if the message is originating from the icon's head. Despite my efforts, I have yet to find a definitive solution. https://i.stack.imgur.com ...

What is the best way to adjust the margins of my div based on the width of the webpage?

I have a website where I use two columns with modules to display information like this: https://i.sstatic.net/Jp97V.png However, I work on vertical monitors and when I switch to a more landscape format, the layout looks like this: https://i.sstatic.net/D ...

What is the best way to showcase a container within a two-column layout?

Looking to showcase the content of two columns exclusively within a container, with each column spaning the full width of the page, just like the image below. Can this be achieved using css grid? Your assistance and support is greatly appreciated. < ...

What is the best way to create a personalized image as the background in WordPress using CSS for a client?

I have this in my style.css .showcase{ background: url("x.jpg") no-repeat 0; } My website is built on WordPress and I have implemented advanced custom fields for the client to edit text. However, I am struggling to find a way for them to change the ...

Changing background color during drag and drop in Angular 2: A step-by-step guide

A drag and drop container has been created using Angular 2 typescript. The goal is to alter the background color of the drag & drop container while dragging a file into it. Typescript: @HostListener('dragover', ['$event']) public onDr ...

What are some ways I can customize the appearance of a Bootstrap 5 Navbar specifically when it is in the collapsed

Currently utilizing Bootstrap 5, my goal is to align the Navbar social icons to the left when the navbar is collapsed for small/mobile devices, and to the right when viewed on a larger screen. Can you assist in identifying which selectors need styling for ...

Modify the :after property of an element using jQuery

Is there a different approach I can take to achieve this desired outcome? Currently, the code snippet below is not yielding the expected results. $('.child_flyout:after').css({'top':'20px'}); Are there any alternative method ...

Navbar collapse not functioning properly on HTML, CSS, and JavaScript

I have developed a CSS code snippet: .nav{ right: 0px; left: 0px; margin-top: 0px; margin-bottom:20px; height: 35px; text-align: center; background-color: red; z-index: 1; } .sticky { background: #000; text-align: center; ...

Adjusting background-position-x while scrolling

I came across Ian Lunn's Parallax tutorial and found it really interesting. The tutorial can be accessed at . My goal is to enhance the effect by not only changing the y-position of the background but also adding horizontal movement based on scroll in ...

Choosing each item from a lineup, one by one

Currently, I am in the process of developing a small website with multiple pages. The main requirement for this project is to have a vertical menu on the home page. Implementing the menu was relatively easy. I successfully added a hover effect to the vert ...

Two resizable divs positioned next to each other - first div adapts to the size of the second div

I have a unique challenge with two divs positioned side by side. The first div contains random text of varying lengths, while the second div holds a random number of inner divs. My goal is to have these two divs completely fill the space within their wrap ...

The scrollbar track has a habit of popping up unexpectedly

Is there a way to prevent the white area from showing up in my divs where the scroll bar thumb appears? The issue seems to occur randomly on Chrome and Safari. https://i.sstatic.net/jFzTf.png This is the div in question .column-content{ height:60vh; ...