What could be causing the text alignment issue in the flexbox next to this image?

I am having trouble centering a logo and the words 'style guide' next to each other in the header. I am using flexbox for this layout, but the text positioning seems off. I suspect it may be due to scaling the logo to half size, but I can't figure out how to correct it. Any insights on why this is happening?

Here is the HTML:

<div class="header">
    <div class="container">
        <img src="http://i1077.photobucket.com/albums/w474/skottunder/example-logo_zpsso7yyy5k.jpg"></img>
        <span id="header-text">Style Guide</span>
    </div>
</div>

And the CSS:

.header {
    background: #317cde;
    width: 100%;    
}

.container {
    margin: 0 auto;
    padding: 10px 0;

    width: 320px;
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;

    -webkit-flex-flow: row wrap;
    justify-content: space-around;
}

.header .container img {
    transform: scale(0.5);
    float: left;
}

#header-text {
    color: #fff;
    font-size: 28px;
    float: left;
}

Explore the CodePen example.

Answer №1

To center your items, make sure to include align-items:center.

.header {
  background: #317cde;
  width: 100%;
}
.container {
  margin: 0 auto;
  padding: 10px 0;
  width: 320px;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  align-items: center; /* add this */
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
}
.header .container img {
  transform: scale(0.5);
  float: left; /* can be removed */
}
#header-text {
  color: #fff;
  font-size: 28px;
  float: left; /* can be removed */
}
<div class="header">
  <div class="container">
    <img src="http://i1077.photobucket.com/albums/w474/skottunder/example-logo_zpsso7yyy5k.jpg" />
    <span id="header-text">Style Guide</span>
  </div>
</div>

Note: The float styles will not take effect due to the presence of the flex statement.

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 reason behind Object.hasOwn(x,y) being different from Reflect.ownKeys(x).includes(y) when x represents a CSSStyleDeclaration object and y is a hyphenated property such as 'z-index'?

Both of these conditions are true: 'z-index' in getComputedStyle(document.body) // true Reflect.has(getComputedStyle(document.body), 'z-index') // true Additionally, the following statements also evaluate to true, indicating that &apo ...

adverse offset and backdrop

To achieve the desired layout, I am trying to adjust the negative margin for the .text div so that it aligns on top of the .image div. <div class="wrap"> <div class="image"><img src="imgage.jpg" /></div> <div class="text ...

Is there any practical reason to choose tables over CSS for controlling layouts?

As I dive into updating a large amount of code for a web application, I've noticed that tables are heavily used throughout to manage layout. Being relatively new to HTML programming, I find myself questioning the necessity of using tables when CSS co ...

Obtain the value of a range using JQuery

I made an attempt to retrieve the value of JQuery's range slider when it changes. Here is how I tried: On the HTML/PHP page: <div class="total"> <label for="">Total</label> <p><span class="monthrc"></span ...

Is it possible to combine margin auto with a transform on the left simultaneously?

While examining a webpage, I noticed a positioning issue and decided to remove some CSS code to determine the root of the problem. It appears that the navbar has a 1px gap on the left side from the edge of the screen. After removing the last two lines of c ...

Exploring the characteristics of images in Javascript

I've gone through my code multiple times but I just can't figure out why it's not functioning correctly... Could someone shed some light on this? What am I missing here? The purpose of the code is to allow users to input different values i ...

The props are not receiving the margin property

I am working on a styled component that needs to receive a prop to determine if it should have a margin on the left or right. It seems that there is a syntax issue that I am struggling with. Here is the code snippet: const FormDiv = styled.div` displa ...

Ways to conceal #div element from displaying in the href attribute within the anchor tag

My anchor tag has an href attribute that looks like this: <a onclick='loadReview(\"" + strexternalURL + "\");' href='#productName1'. When clicking on it, the URL appears as http://localhost:54986/Dealerlist.aspx#productName ...

What is the best method for overriding the CSS rule for input[type=checkbox]?

My checkmark follows this rule: input[type=checkbox] { display: none; } I tried to change it like this: <input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" style="display:block;& ...

What is the reason behind the additional height created by line-height?

<div><iframe style="height: 100px"></iframe></div> <div style="line-height: 0"><iframe style="height: 100px"></iframe></div> Click here to view the code snippet on jsFiddle. Upon inspecting the DOM, it is e ...

Is there a way to trigger a link to open in Safari when I tap on it within a UIWebView

When I click on the UIWebview, I am trying to open a link in Safari (like an ad display). The following code is what I am currently using, but I have noticed that for some links, it opens within the UIWebview instead of opening in Safari. - (BOOL)webView: ...

Tips for adjusting the color of the sidebar in an HTML email template

My attempt at modifying the background color of my HTML email template has been focused on changing the sidebar's white color, rather than altering the background of the email body itself. This is the CSS code I have: @import url('https://fonts. ...

PHP overall outcome

I have created a form that includes checkboxes, but I am facing difficulty in calculating the total result based on the selections. Ideally, if a user selects three checkboxes, the total should be $3, and if only one checkbox is selected, the total should ...

Tips for increasing the number of inputs within a form using <script> elements

I am currently working on a form within the script tags and I would like to include additional input fields before submitting. However, the submit button seems to be malfunctioning and I suspect that there may be an issue with how I am accessing it in my c ...

Container with adjacent gradient CSS shape

I am currently working on a unique design concept for a website we are developing. The header requires a parallelogram shape above it and a trapezium shape to the right of the container, as illustrated below. Successfully implementing the parallelogram ab ...

Is it possible to dynamically utilize document.getElementById()?

I am attempting to print an HTML page using window.print after each REST API call updates the content. Is it possible to print continuously for each REST API call? var myPrintContent = document.getElementById("data-box"); var myPrintWindow = wind ...

Align an element to the right outside of its parent

I am facing an issue with my parent div and three children. I want one child to float left of the parent, one to be in the exact center of the parent, and one to float right of the parent. However, the floated right element is going outside of the parent d ...

Containing more than a full page of information, the footer stays fixed at the bottom of the screen, even as the user scrolls to

As I work on developing my artist website to showcase my music, I have encountered an issue with the footer placement. My goal is seemingly simple - I want a footer that always sits at the bottom of the site, just under the content/body section. There shou ...

Retrieve static dropdown options from a service rather than directly populating them in the HTML code

Recently, I have been working on this HTML code. <select ng-model="Type"> <option value=""></option> <option value="10D">10 Days</option> <option value="20D">20 Days</option> <option value="30D">30 Days ...

Alignment of elements in a list at the bottom

I am looking to create multi-level tabs using <li> that grow from bottom to top. Here is the current code I have: div{ width: 200px; border: 1px solid black; } ul{ margin: 0px; padding: 0px; } li{ margin: 2px; width: 20px; display: ...