The text is placed below the image, rather than appearing alongside it

My website bby is supposed to be displayed right next to the image logo, but it's showing up under the logo for some reason. Can someone help me with this issue? You can view the current layout here

This is the html code I have:

body {
    font-size:20px;
    font-family: Optima, sans-serif;
    line-height:1.5;
    padding: 0;
    margin:0;
}

.container {
    width:80%;
    overflow:hidden;
}


header {
    font-family: Monaco, sans-serif;
    color:white;
    padding-top:100px;
    min-width: 90%;
    min-height: 200px;
    margin: 0;
    padding: 10px;
    background:#6BD326;
}

#logo {
    float:left;
    display:inline-block;
}

.branding {
    float: left;
}

nav li {
    float:left;
    padding: 0px 20px;
    list-style-type: none;
}

nav {
    float:right;
}

#logo {
    margin-top:5px; 
    width:40%;
}
<header>
        <div class="branding">
            <div id="logo">
                <img src="https://picsum.photos/200/300" style="width:100px;" />
            </div>
                <span><h1><u>My</u>&nbsp;Website&nbsp;bby</h1></span>
        </div>
        <nav>
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="">Photogallery</a></li>
                <li><a href="">Contact me</a></li>
            </ul>
        </nav>
</header> 

If you want to see the issue visually, refer to the image linked above. I'm new to coding and really need help figuring out what's wrong.

Answer №1

You can also achieve the desired layout by using a combination of display: inline-block and vertical-align: middle.

For instance:

body {
  font-size: 20px;
  font-family: Optima, sans-serif;
  line-height: 1.5;
  padding: 0;
  margin: 0;
}

.container {
  width: 80%;
  overflow: hidden;
}


header {
  font-family: Monaco, sans-serif;
  color: white;
  padding-top: 100px;
  min-width: 90%;
  min-height: 200px;
  margin: 0;
  padding: 10px;
  background: #6BD326;
}

#logo {
  float: left;
    display: inline-block;
    vertical-align: top;
}

.i-b {
  display: inline-block;
    vertical-align: top;
    width: calc(100% - 40%);
}

.branding {
  float: left;
}

nav li {
  float: left;
  padding: 0px 20px;
  list-style-type: none;
}

nav {
  float: right;
}

#logo {
  margin-top: 5px;
  width: 40%;
}
<div class="branding">
            <div id="logo">
                <img src="https://i.picsum.photos/id/237/536/354.jpg?hmac=i0yVXW1ORpyCZpQ-CknuyV-jbtU7_x9EBQVhvT5aRr0" style="width:100px;" />
            </div>
                <span class="i-b"><h1><u>My</u>&nbsp;Website&nbsp;bby</h1></span>
        </div>
        <nav>
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="">Photogallery</a></li>
                <li><a href="">Contact me</a></li>
            </ul>
        </nav>
    </div>

Check out the code in Jsfiddle

Answer №2

Here is the code that is functioning properly:

Body code:

 <body>
<div class="branding">

    <div id="logo">
        <img src="./img/logo.png" style="width:100px;" />
    </div>
    <nav>
        <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="">Photogallery</a></li>
            <li><a href="">Contact me</a></li>
        </ul>
    </nav>
        <span><h1 style="padding: 30px; margin-left:130px;"><u>My</u>&nbsp;Website&nbsp;bby</h1></span>
</div>

</div>
</body>

Your CSS should look like this:

body {
    font-size:20px;
    font-family: Optima, sans-serif;
    line-height:1.5;
    padding: 0;
    margin:0;
}
.body img{
    display: inline;
}

.container {
    width:80%;
    overflow:hidden;
}

header {
    font-family: Monaco, sans-serif;
    color:white;
    padding-top:100px;
    min-width: 90%;
    min-height: 200px;
    margin: 0;
    padding: 10px;
    background:#6BD326;
}

#logo {
    float:left;
    display:inline-block;
}

nav li {
    float:left;
    padding: 0px 20px;
    list-style-type: none;
}

The mistake was in this section:

.branding {
    float: left;
}

Answer №3

Within the

<div class="logo-box">
, you have the option to include an additional div with the following style:

align-items: center; justify-content: flex-end;

Answer №4

It is recommended to validate your code using the W3C Validator.

If you encounter any errors in the HTML, such as the one mentioned below:

Error: Element h1 not allowed as child of element span in this context. (Suppressing further errors from this subtree.)

To learn more about the difference between block and inline elements, you can visit Can <span> tags have any type of tags inside them? and refer to the formal spec at https://www.w3.org/TR/html401/struct/global.html#h-7.5.3

If you need an immediate solution, consider changing the span to a div (which allows h1 elements as children) and set both as inline-block elements.

Answer №5

Experiment with flexbox and remove float:left

.logo {
    display:flex;
    align-items:center;
}

Answer №6

Take a look at this - I eliminated all the floats and utilized flex properties instead.

body {
    font-size:20px;
    font-family: Optima, sans-serif;
    line-height:1.5;
    padding: 0;
    margin:0;
}

.container {
    width:80%;
    overflow:hidden;
}


header {
    font-family: Monaco, sans-serif;
    color:white;
    padding-top:100px;
    min-width: 90%;
    margin: 0;
    padding: 10px;
    background:#6BD326;
  display: flex;
  justify-content:space-between;
  flex-wrap: wrap;
}

#logo {    
    margin-top: 5px;
    display: flex;
    align-items: center;
}
#logo span{
  margin-left: 10px;
}

nav ul {
  display: flex;
  flex-wrap: wrap;
  
}
nav li {
    padding: 0px 20px;
    list-style-type: none;
}
<header>        
<div class="branding">
            <div id="logo">
                <img src="https://cdn.mos.cms.futurecdn.net/BVb3Wzn9orDR8mwVnhrSyd-1200-80.jpg" style="width:100px;" />
                <span><u>My</u>&nbsp;Website&nbsp;bby</span>
            </div>
        <nav>
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="">Photogallery</a></li>
                <li><a href="">Contact me</a></li>
            </ul>
        </nav>
    </div>
</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

How to target specifically images contained within anchor elements using jQuery?

I am looking for a way to select only images that are inside links, so I can add the rel="lightbox" attribute to those links. I have attempted to achieve this using 2 loops but it is not working as expected because it also adds the rel attribute to normal ...

Generating an .html document from a log file

Looking for a way to transform log files into easily accessible .html files that can be viewed by anyone? Check out the script I've been working on: #!/bin/bash ## This handy script converts log files into HTML format, allowing optional GREP search ...

Having trouble getting Google to show breadcrumbs in search results

I've been trying to implement schema.org's breadcrumb microdata in order to have Google display my breadcrumbs in search results. However, when I check with Google's structured data testing tool, the breadcrumb is not showing in the search r ...

Internet Explorer 9 does not display content until the ajax/json function has finished executing

I have encountered an issue with my code regarding updating a div element. The first innerHTML call seems to be ineffective and does not render in the browser. However, the second innerHTML call works as expected by appending "Complete" once the ajax call ...

Adjusting the color of a value in justGage requires a few simple steps to

Is it possible to modify the color and design of the text in the Value parameter of justGage after creating the gauge? My goal is to change the text color to blue with an underline to give it a link-like appearance. Appreciate your assistance. ...

When the button is clicked, populate a new form with information from the model

As a newcomer to stackoverflow and django, please excuse me if my description is lacking in detail. This is the models.py file: from django.db import models # Create your models here. SPORTS_CHOICES = ( ('nfl', 'NFL'), (&apos ...

"Patience is a virtue: Tips for waiting until a webpage is completely loaded using

I attempted to use a special class name that only shows up after the page has completely loaded, but for some reason it appears before the content is visible on screen. try: WebDriverWait(self.browser, 20).until(EC.element_to_be_clickable((By.CLASS_NA ...

Creating a mockup for a website design project in my class, utilizing HTML and CSS. Encountering issues with the CSS not displaying correctly, unsure of the root cause of the problem

Check out this wireframe design I created: https://i.stack.imgur.com/Ro3dl.png I'm working on translating this into HTML and CSS so that I can further develop it. The HTML Code: <!doctype html> <html> <head> <title> Trinit ...

Troubles with showcasing icons on a website

I need some help with a minor issue that I'm stuck on. I'm trying to display an information icon that, when clicked, opens a pdf. The strange thing is that the icon doesn't show up on the page even though it exists on the server. However, wh ...

Examine the spans and delete the first-child node

Basically, this functionality allows the user to cycle through hidden information by clicking on it. Here is how you can structure your HTML: <div id="facts"> <span>click to cycle</span> <span>fact 1</span> <s ...

Can you provide me with a comprehensive list of all the colors available in Twitter Bootstrap 3?

I've integrated the twitter bootstrap sass 3.0.3.0 gem, which is supposed to be the latest version of twitter bootstrap 3.0.3. I'm trying to customize the colors using the 'customize' section of the LESS variables, but I can't seem ...

What are the available choices for constructing HTML based on an ajax response?

Are there any alternatives or libraries available for constructing html from an ajax response? Currently, I am taking the json data received, creating the html as a string, and using a jQuery function to insert it into the DOM. However, I believe there mu ...

Border extends across two separate rows

Let me illustrate my issue with a specific example where I am utilizing a single column with a rowspan: <table border="1" style="width:300px"> <tr> <td rowspan="2">Family</td> <td id="jill">Jill</td> <td>Smi ...

Bootstrap 5 - Achieve automatic column width within a row

In my Bootstrap 5 setup, I have a variety of pages that have different column layouts - sometimes 2 columns, sometimes 3. The template system I'm using dynamically adjusts the layout to accommodate the need for a third column when necessary. <div ...

Deleting an element from an HTML page with jQuery

Hi there, I'm just starting to learn about jQuery. Below is an example of a list element I have: <ul> <li> <a href="abc">ABC</a> </li> <li> <!-- This is the element I want to get rid of --&g ...

Enhancing elements with fade-in effects upon hovering

Is there a way to incorporate a subtle fade in/fade out effect when hovering over items on this webpage: http://jsfiddle.net/7vKFN/ I'm curious about the best approach to achieve this using jQuery. var $container = $("#color-container"), ...

Having trouble understanding the odd behavior in IE7. Suddenly seeing a scrollbar appear when hovering

The webpage layout I am currently experiencing issues with can be found at the following link: When viewing this page in ie7 or ie8 Compatibility View mode, a strange horizontal scrollbar appears whenever I hover over one of the menu items. It seems that ...

How can I use AngularJS to save selected assets?

<div style="z-index: 1; position: absolute"ng-show="ctrl.company.selected"> <div style="" ng-repeat="Asset in ctrl.company.selected.Assets"> <div class="pd-5"style="width: 300px; background-color: white; border-bottom: gray solid ...

The CSS variable for the Bootstrap Modal header padding, var(--bs-modal-header-padding), is missing or not defined

Is there a way to use the modal-header CSS property inside a normal div instead of inside a modal? When I try to do so, I am getting an error saying that the variable is not defined. Can someone please help me understand what I am missing? <html lang= ...

How can I display a nested div when the parent div's v-if condition is not met?

In my project, I am utilizing Laravel 6 in combination with Vue.js 2. To iterate through users and showcase their information within div elements, I am using a for loop outlined below. The Category names are stored in user.pivot.demo2, and the users are ...