DEV Community

lolleri200
lolleri200

Posted on

Need help with CSS

How can I move the logo, center, right elements inside the header element?

Top comments (10)

Collapse
 
s_aitchison profile image
Suzanne Aitchison

Can you share what your html looks like? Something like a codepen would help us help you 😊

Collapse
 
lolleri200 profile image
lolleri200
Collapse
 
s_aitchison profile image
Suzanne Aitchison

OK great!

So if I understand your question correctly you want to achieve this:

Screenshot of the three divs side by side in the header

In which case, take your three divs: header_logo, header_center, header_right and move them inside the header div. So you now have:

<div id="header">
  <div id="header_logo">
      <h2>This is a logo in a div element</h2>
  </div>
    <div id="header_center">
      <h2>This is the center in a div element</h2>
  </div>
  <div id="header_right">
    <h2>This is the right border in a div element</h2>
  </div>
</div>

That puts your elements inside the header. However, they will naturally appear one below each other. To change that so they flow left to right across the page, you can change your CSS and make use of flexbox.

Add this extra line to your header div CSS:

#header {
    width: 960px;
    height: 80px;
    background-color: powderblue;
    display: flex;
}

This will achieve the screenshot I posted. Hopefully I didn't misunderstand and this is of some help - but let me know if not!

Thread Thread
 
lolleri200 profile image
lolleri200

Yes! Thank you, I couldn't find any good guides online..

Thread Thread
 
s_aitchison profile image
Suzanne Aitchison

No problem! Glad I could help 😁

Thread Thread
 
lolleri200 profile image
lolleri200

I noticed that the page is displayed correctly, but for some reason is not scaling if I look at it with a smaller display.

Thread Thread
 
s_aitchison profile image
Suzanne Aitchison

So all of your items have a fixed with (e.g. the header is 960px wide). This means regardless of the size of screen, it will occupy 960px. If you want it to be response, try using a percentage, e.g. make the header 100% and the items inside 33%

You can also look up 'CSS media queries' which will find you further resources about making a responsive design

Collapse
 
corentinbettiol profile image
Corentin Bettiol

Woaw, please provide some code or context, I don't really known what you are trying to do right now :)

Collapse
 
lolleri200 profile image
lolleri200 • Edited

Ohh I thought I attached the picture. There :)

dev-to-uploads.s3.amazonaws.com/i/...

Collapse
 
corentinbettiol profile image
Corentin Bettiol

Thanks, someone have already answered your question :)