How to Position Elements using Bootstrap and CSS

I am facing a simple issue with my webpage: I am unable to center the div-image in the header and align the content vertically. This is the current setup:

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

The desired position for the image is POS. I have tried methods like margin:auto, using flexbox, and even attempted to use bootstrap, but none of them seem to work! Here is the code snippet:

<body>
    <header>
        <div class="logo-holder"></div>
    </header>
    <div class="container align-middle">
        <div class="row">
            <div class="col">
                <img src="{{ object.image.url }}">
            </div>
            <div class="col">
                <div class="container">
                    <h1>{{ object.title }}</h1>
                </div>     
            </div>
        </div>
    </div>   
</body>

CSS:

body{
    font-family: 'Lato', sans-serif;
}
.container img{
    border: 1.5px solid rgb(138, 137, 137);
    width: 400px;
}
header{
    height: 10em;
    display: flex;
    align-items: center;
    justify-content: center;
}
header .logo-holder{
    margin:auto;
    position: absolute;
    background: url(../img/main-logo.png) no-repeat center center;
    width: 104px; height: 85px;
    position: absolute;
    top: 30px;
    left: 10%;
    }

.container h1{
    text-align: center;
    text-transform: uppercase;
    color: #353738; 
    letter-spacing: 3px;
    font-size: 30px; 
    font-weight: 600;
}

This should be an easy fix for someone experienced in frontend development. I have researched extensively, but what works in online code snippets does not translate properly into my own code. Any suggestions on how to properly center the logo and vertically align the product div (the div containing the image and title)?

Answer №1

After making some adjustments to your CSS, I was able to get it working smoothly.

I decided to take out the Flex properties from the header, and instead set the logo-header to display:block; with margin:auto auto;. Additionally, I removed the absolute positioning of the logo-header.

body{
    font-family: 'Lato', sans-serif;
}
.container img{
    border: 1.5px solid rgb(138, 137, 137);
    width: 400px;
}
header{
  position:relative;
  display:block;
  width:100%;
  height: 10em;
}
header .logo-holder{
    display:block;
    margin:auto auto;
    background: url('../img/main-logo.png') no-repeat center center;
    width: 104px; height: 85px;
}

.container h1{
    text-align: center;
    text-transform: uppercase;
    color: #353738; 
    letter-spacing: 3px;
    font-size: 30px; 
    font-weight: 600;
}

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

Adjust the CSS to give <a> elements the appearance of plain text

Is it possible to style an anchor tag to appear identical to plain text? Consider the following scenario: <p> Here is some text and here is a <a class='no-link' href="http://www.example.com" >link</a></p> I have atte ...

Animating several elements by toggling their classes

I'm struggling to implement smooth animations on this box. I've tried using 'switchClass' but can't seem to keep everything together. Any help would be greatly appreciated. Here is the code snippet for reference: <script src=" ...

Exploring the differences between React state and CSS :hover in the context of a dropdown menu that is accessible to both desktop users (via mouse) and

I have come across a dilemma regarding a dropdown menu that needs to cater to both Desktop/PC users (with mouse) and Mobile devices (with touch). After considering my options, here are the proposed solutions: OPTION 1 One approach is to implement it usi ...

Prevent the resizing of my website on iOS devices using HTML and CSS

I'm encountering an issue with a website I developed that seems to be resizable on certain iOS devices, including the new iPhone X. I haven't been able to replicate this behavior on other standard websites. Perhaps there's a simple CSS solut ...

Moving a DOM element within AngularJS to a new location

I have created an angular directive that functions like a carousel. To keep the dom element count low, I delete elements from the dom and then re-insert them using angular.element to select, remove, and insert items as shown below: app.directive('myD ...

Is it common for functions to be outlined in standard CSS practices?

I am curious if the CSS standard includes definitions for "functions"; I have not come across any information about them on w3schools or other sources. When I refer to "functions," I am talking about calls such as rgb(int, int, int) or url(string) that ar ...

Begin counting starting from 1 all the way up to 24, then feel free

I've developed a counter that increments from 0 to 24, and once it reaches 24: setInterval(function(){DayAndNight()}, 1000); var iState = 12; function DayAndNight() { //console.log('test'); switch(iState) ...

How to embed HTML code within PHP using a conditional variable

I've encountered an issue with a PHP code that sends emails containing HTML templates. The HTML template includes PHP variables such as Name and Email. <strong>Name: {name} </strong> As the email template is lengthy, I have included ...

Tips for enhancing the appearance of the dropdown scrollbar in PrimeNG

Just started exploring Angular and I've been struggling to customize the scrollbar on a PrimeNG dropdown. Does anyone have any tips or tricks to achieve this? Here is the HTML code: <p-autoComplete placeholder="- Select -" (onSelect)="onSelect(dh ...

Is it possible to rotate an image with a random angle when hovering in Angular?

I'm currently working on a photo gallery project and my goal is to have the images rotate when hovered over. However, I am experiencing difficulties in passing values from TypeScript into the CSS. HTML <div class="back"> <div cl ...

Discovering the font-weight attribute in Selenium IDE

Currently, I am working with Selenium IDE and aim to detect when a text element has the 'font-weight:bold' CSS property applied to it using 'verifyAttribute'. The specific CSS locator being used is: css=body.home.es ul#languages li:nt ...

Like the Word outline view, the list view can be easily collapsed and expanded with a simple click

I've seen a few examples, but I haven't been able to achieve what I'm looking for. I need to extract text from a field and convert it into an outline view similar to the one in Word. Is this possible? Any help would be greatly appreciated. I ...

I keep receiving unexpected security alerts in Firefox without any specific cause

After making some updates to my page, I started receiving a security warning. The data you've entered may be at risk as it is being sent over an insecure connection that could potentially be intercepted by a third party. I'm puzzled because m ...

Unable to authenticate an HTML form using PHP and Apache 2

In my website's footer, there is a form that I am trying to run using a PHP file located at 127.0.0.1/form.php on localhost. I learned that PHP code inside HTML is commented out, and according to the PHP Documentation, the PHP file needs to be run dir ...

Using Styled Components to Implement Background Images in a React Application

I'm currently attempting to pass a background image using a prop, but I'm encountering an issue where it's indicating that url is undefined. const CardImage = styled.div` height: auto; width: 100%; background-size: c ...

Inject an html <img> tag using an AJAX PHP call

Greetings everyone, I am currently in the process of developing a captcha maker using PHP with an Object-Oriented Programming (OOP) approach. The implementation involves a Captcha class responsible for generating the captcha image. You can find the complet ...

Modifying SVG gradients with JavaScript

My goal is to modify the stop color of a gradient displayed in an SVG element. I've been trying to adjust the stop-color attribute, but so far, my attempts have not been successful: <svg><defs> <linearGradient gradientTransform="rotat ...

"Enhance your website with Ajax code that enables automatic refreshing of a PHP file, keeping its values up-to-date

Before diving in, I want to make it clear that my understanding of ajax is limited. I'm currently working on a small application where I have a load.php file that echoes 3 variables: $loadout[0]; $loadout[1]; $loadout[2]; The PHP file is functioning p ...

How to style tags between select options in HTML using React JS?

Is there a way to customize the appearance of a span element that is nested within an option tag? <select> <option value="option1">Active Wallet <span style={{fontWeight:'bold!important'}}>mBTC</span></o ...

Dividing the webpage background into separate sections to showcase a variety of colors, patterns, and more

I'm in the process of dividing the background on my website into distinct areas. My goal is to have the patterned area extend both horizontally and vertically on either side until it reaches the edge of the visible webpage. Figuring out how to achiev ...