Quantcast
Channel: Active questions tagged flexbox - Stack Overflow
Viewing all articles
Browse latest Browse all 1323

How can I make a and content within the of my HTML split into left and right within the same parent box with CSS?

$
0
0

So I just began my programing journey, and in the course that I'm in, I just got tasked with fixing a broken website by myself without the course guidance. I was excited to test myself with what I had already learned... until I came across a brick wall.

So within my HTML file what I'm trying to manipulate is written as follows:

<header><div class="content"><a href="index.html" class="desktop logo">Fotomatic</a><nav class="desktop"><ul><li><a href="#">Product detail</a></li><li><a href="#">About us</a></li><li><a href="https://www.instagram.com/">Follow us<img class="icon" src="./resources/images/instagram.png"                  /></a></li></ul></nav>

On the website the idea is that the "Fotomatic" should stay on the left of the nav and the <ul> elements should go to the right of the nav. Here is a mockup of how it should look like:

Mockup

My CSS for my current build are as follows:

header {  position: fixed;  width: 100%;  border-bottom: solid 1px #c6c1c1;  background-color: white;  z-index: 1;}header .content {  display: flex;  align-items: center;  padding: 1.875rem;}header .desktop {  font-family: Roboto-Mono-Regular;  font-size: 2rem;  color: #4a4a4a;}header nav ul {  display: flex;  font-size: 1rem;  font-family: Roboto-Regular;  line-height: 1.6;}nav li {  padding-left: 3.5rem;}nav a {  vertical-align: bottom;  line-height: 1.6;  font-size: 1rem;  color: #4a4a4a;}header .icon {  width: 1rem;  padding-left: .75rem;}

The CSS rules above provide this result:

Result of original code

Now, given that it is my first encounter with flexboxes I did some research of my own.

I tried many things, from simple ideas like just floating the <ul> element right, text-align, all the way to trying to manipulate flexboxes.

The closes that I got to what I wanted was with the margin CSS rule line like so:

header .desktop {  font-family: Roboto-Mono-Regular;  font-size: 2rem;  color: #4a4a4a;  margin-left: auto;}

The CSS rules above provided this result:

Result of margin-left: auto; rule on the parent .desktop

The result I got with that is that the entire box get's pulled, not only the <ul> elements, but the “Fotomatic" <a> as well.

Now, even though this is not the result I expected, as far as I understand it behaved that way because the <a> element is a child to .desktop as well.

So I tried the same margin-left:auto; only in the <ul> elements but nothing happens:

header nav ul {  display: flex;  font-size: 1rem;  font-family: Roboto-Regular;  line-height: 1.6;  margin-left: auto;}

Result of margin-left: auto; rule on <ul>, child to .desktop

My assumption is that either I'm not correctly understanding how flexboxes work yet, or there is another CSS rule that is not letting me manipulate the header nav <ul> like I would expect.

Any other instances where the header has CSS rules are within a @media rule where the screen-size is smaller, so I don't believe those are a problem at all so I did not include them to keep this question as "short" as possible.

I know the answer is probably staring me in the face, but I cannot seem to find it.

Thank you all in advance!


Viewing all articles
Browse latest Browse all 1323

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>