Why use display: block in a media query to override display: flex? - html

I am looking at some HTML code, which looks like this (summarised):
html,
body {
height: 100%;
background: #1c1c1c;
}
header {
background: #1c1c1c;
display: flex;
}
.child {
flex-grow: 1;
}
ul {
display: flex;
}
li {
flex-grow: 1;
}
#media only screen and (max-width:542px) {
header div:nth-child(1) {
display: block;
}
}
<header>
<div class="child">
<img src="logo.png" />
</div>
<ul class="child">
<li>About</li>
<li>Services</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</header>
The display:block on the third line from bottom of the css has no effect and I find myself wondering what it is there for?

It's not apparent in the code because there seem to be parts missing.
But here's the underlying logic:
display: flex lines up child elements in a row
display: block restores vertical stacking
So the override takes you out of flex layout and back to standard block layout (where flex properties have no effect).
This set-up can be handy for switching from a desktop to a mobile layout, among other use-case scenarios.
Here's a simplified version of the code for illustration purposes:
.child {
display: flex;
justify-content: space-around;
}
#media (max-width:542px) {
.child {
display: block;
}
}
<ul class="child">
<li>About</li>
<li>Services</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
jsFiddle demo

Related

I want my nav bar to appear on the opposite side of my logo

I want my header to appear as such, with the logo on one side and the nav bar on the other side:
Image
It currently appears with the logo and nav bar stacked on top of each other, on the left side: Image
I tried using a flex display, and justifying the content but that didn't work. Any ideas? Here's the code pen: Why do I need to have code to link a codepen lol https://codepen.io/jalal_b/pen/ZEpmzzX
This is what you need to add to your styles:
#header { display: flex; }
#nav-bar { flex: 1; }
#nav-bar ul { display: block }
#nav-bar ul li {
display: inline-block;
margin: 0 2em;
}
You might need to fit into your design.
Here is an article about flex-box in CSS if you want to learn more: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Good luck! ✌️
I copied your code to a snippet below.
I simply added this code to your CSS:
#header {
display: flex;
flex-direction: row;
}
Then set display: inline on your list items:
li {
list-style-type: none;
display: inline;
}
You will probably need to adjust your layout a bit to space out the list items a bit more.
#import url('https://fonts.googleapis.com/css2?family=Staatliches&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#700&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Raleway&display=swap');
#header {
display: flex;
flex-direction: row;
}
#header-img {
margin-left: 40px;
margin-right: auto;
display: block;
height: 45px;
width: auto;
}
.nav-link {
color: #BEB7A4;
text-decoration: none;
font-family: "Montserrat";
}
li {
list-style-type: none;
display: inline;
}
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<div id="page-wrapper">
<header id="header">
<div class="logo">
<img
id="header-img"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeYAAABoCAMAAAATgKPhAAAAflBMVEX///8AAACnp6f29vadnZ1xcXH5+fmZmZlKSkrq6urc3Nzz8/Pm5uYsLCy4uLgxMTHNzc3U1NTg4OBSUlKCgoJLS0vMzMzo6OgfHx9gYGAkJCQNDQ04ODiOjo4oKChmZmaurq4/Pz/CwsJ2dnaHh4cVFRU2NjZiYmJ0dHRra2tiAXGQAAAQH0lEQVR4nO1da3ejPK/NraSEXAq5NPcAaTpP//8fPAkhKcZbRhIk885Z2R9mrUzB2GxblmRJtFovvPDCCy+88MILL7zwwgsKBMPIK/4eRv7f6so/AM8LojCMAu+Mv90XCcbv+/U0vf8cHEb7ZPZPjeBJ6KbxbjVqF/C+i9N/ZEmk1x4Pbr+vP49/s0v/i4jG03UbYTk5LobsZrwOE/F4EQ4iv7Hl9nPt7S7/GV5/fmsmacodw20o6Xkkn9zWP+0GetV3jYlnD6pv/YUXrzaQ4xzrY1rdSIauqxkLm+1qNm5GXKyuLc7yn/H154k/QX/xIxpDPpLJz473yhfg7srJHhOPnQb8YUUzzkB6LDpkNF8x6YT8zlLIaV7lP2/vJVI09aYYQ4bvDuNxGprHxAN/+IPyZyfeIEZ9xtTR0HxeC6tFl9/jArz7bTnN7/lPi2aBzFDTfJYeb5VLWkEzxfLKfZvRxJ4/iKRadOtoPmOuWNHd/mp6e63zazMUzbPJT8xttgbN7V/tgIKc5g/iSVO2YuPPZWM4VC06Nc3t9pt0k+5d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MH8vN+z6G5Bs+M6EgdzXYBLrx9ymnGNdGY361IFXm2N+zJifQkmqnajlXABetL0NFsfz8KP0xBM1XCjRW4La8Ldgd9tP0smnWfHsOJVmXoaB7a/hgoOT7BuVNV1QlKbLNCDIjvl1W/LMdJ79NobkWyvPsL3ngHWjqaQY3ZGF2moRnWr21TOWBlhIn4TV2G7FoSz6O5FUg3aG4YlZJme9pBPVVFMyW2KU3YRKDI8fxxbvxPpFm4QW/Z5UqUNAMbFV3m80tvF0CJ7Zg3pDSRvKqzil3R7lNpbvnsBb0UFF1S0gy8c2h309FMZEmyI9aDnqQu2LEqi+e5NJ+lGW+HPkoCx5Q0AxMV0aejmXSSsENcgw5XFZtVmyPPpvlMdPVnyGayqG4lzeCr2N9A51PSTIptQWYCowRFe7rj5OM9n+bzi8MBIrd+96Tp32CTJZLqTIAdBEQWgNnAooo6khSlww467w53yea9N+DFRXs9C/2mi+DY8MMZzjna9qpjxSykfWsMMee+0L4PBJ92O/YbYmmHA7v57GbhKvIWnRnY6bbHTtrIV0IfDH/cmxUqIK2nX530kWUc/mV43SBMO/2v2fGCWS+NpNnmfxXn7gfBIPXP/3b/pX6/8MILL7zwwgv/T/F/8/jqGMewQ5wAAAAASUVORK5CYII="
alt="sporks logo"/>
</div>
<nav id="nav-bar">
<ul>
<li><a class="nav-link" href="#about">About</a></li>
<li><a class="nav-link" href="#how-to-use">How To Use</a></li>
<li><a class="nav-link" href="#where-to-buy">Where To Buy</a></li>
</ul>
</nav>
</header>

Justify inner Flexbox items across full width of flex container

I have a Flexbox in use for header navigation, the logo is aligned to the left and the ul items are aligned to the right as in a traditional style. Both the logo and the navigation links are flex items within a full width Flexbox, and I have given them both flex: 50%. The navigation links section is also a Flexbox (an inner Flexbox) to prevent the menu from stacking and instead behaving in a better responsive manner.
When I apply justify-content to that inner Flexbox, there is no change to the links, as if there is an overriding style or the property does not work on an inner text box. I should like the navigation links to equally divide themselves among the 50% of the screen width.
I've toyed with placing flex: auto on the items but can't keep it within the current layout by doing that, and I've tried fiddling with inline elements to see if I can remove any overriding property, but no cigar.
#nav {
display: flex;
flex: 50%;
align-items: center;
}
#logo {
margin-right: auto;
width: 50px;
height: auto;
}
#links {
margin-left: auto;
display: flex;
justify-content: space-between;
}
#links a {
text-decoration: none;
}
<nav id="nav">
<img id="logo" src="https://pngimage.net/wp-content/uploads/2018/06/logo-placeholder-png.png"/>
<ul id="links">
<li><a href="#">Link1<a></li>
<li><a href="#">Link2<a></li>
<li><a href="#">Link3<a></li>
<li><a href="#">Link4<a></li>
</ul>
</nav>
You were pretty close. Important changes I made were to set the width of the #links <ul> to 50% and add justify-content: space-between to the container #nav wrapper. A few other style changes to the ul so it doesnt have default margin and padding and I think it is behaving as you are expecting now..
#nav {
display: flex;
align-items: center;
justify-content: space-between;
}
#logo {
width: 50px;
flex: 0 0 50px;
}
#links {
width: 50%;
display: flex;
justify-content: space-between;
margin: 0;
padding: 0;
list-style: none;
}
#links a {
text-decoration: none;
}
<nav id="nav">
<img id="logo" src="https://pngimage.net/wp-content/uploads/2018/06/logo-placeholder-png.png"/>
<ul id="links">
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
</ul>
</nav>
I think you have problem with flex: 50%; CSS deceleration. It's not at proper place. I have re-write the html to use it properly and fixed the CSS according.
Here is the Modified CSS
#nav {
display: flex;
background: #eee;
}
#nav>#logo,
#nav>#links {
flex: 50%;
}
#logo img {
width: 50px;
height: auto;
}
#links {
display: flex;
justify-content: space-around;
list-style-type: none;
}
#links a {
text-decoration: none;
}
<nav id="nav">
<div id="logo"><img src="https://pngimage.net/wp-content/uploads/2018/06/logo-placeholder-png.png" /> </div>
<ul id="links">
<li><a href="#">Link1<a></li>
<li><a href="#">Link2<a></li>
<li><a href="#">Link3<a></li>
<li><a href="#">Link4<a></li>
</ul>
</nav>
Also the code available at codepen https://codepen.io/mobarak/pen/jRjZxB/

Flexbox not appearing in mobile view

I am trying to use flex box for mobile view but it does not seem to work for a specific box(the title flexbox works fine but the labels flex doesnt show). Also, I have divs inside the labels flexbox as child elements
#media screen and (max-width:450px) {
.title {
display: flex;
}
.click {
display: none;
}
.name {
display: flex;
font-size: 50px;
}
.labels {
display: flex;
width: 100%;
background-color: aliceblue;
}
}
<div class="labels">
<div class="port social">Social</div>
<div class="port bio">Bio</div>
<div class="port web">Website</div>
<div class="fancybox fancyboxy-iframe port resume" href="image/Weldons%20resume%20final.pdf" data-fancybox="gallery">Resume</div>
</div>
https://codepen.io/ew39020/pen/MmEmyZ
I found two problems:
In Codepen CSS, row 19: you have diplay instead of display
In your snippet here: Media queries seem not to work here, because result is too wide.
And if you want elements to have equal width, just add flex: 1 to them.
.title {
display: flex;
}
.click {
display: none;
}
.name {
display: flex;
font-size: 50px;
}
.labels {
display: flex;
width: 100%;
background-color: aliceblue;
}
.labels > * {
flex: 1;
}
<div class="labels">
<div class="port social">Social</div>
<div class="port bio">Bio</div>
<div class="port web">Website</div>
<div class="fancybox fancyboxy-iframe port resume" href="image/Weldons%20resume%20final.pdf" data-fancybox="gallery">Resume</div>
</div>
In your CodePen code, you misspelled the display property under labels:
.labels{
diplay:flex; /* missing the `s` */
width:100%;
background:blue;
}
When I corrected this, the flexbox works. I also added a media query condition to test this under a smaller screen, and it worked.

how to properly align list items vertically?

I wanted to create a list of items by displaying a name, a list of properties and an image. Although this seems like quite a common and easy problem, I am struggling to get it right.
After having changed the markup a dozen of times, I chose to represent the list by a ul in which each li consists of a h3(name), a ul(properties) and a img(image).
In order to make it fill the page a bit more, I used CSS's flexbox in order to put the image and the properties next to each other in a responsive way.
img {
max-width: 100px;
}
#example > ul > li {
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-around;
justify-content: space-around;
-webkit-align-items: center;
align-items: center;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
h3 {
width: 100%;
text-align: center;
}
div > ul {
border-left: 2px solid red;
}
<section id="example">
<ul>
<li>
<h3>Bulbasaur</h3>
<div>
<span>Properties</span>
<ul>
<li>green</li>
<li>seed</li>
<li>grass</li>
<li>poison</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/2/21/001Bulbasaur.png" />
</li>
<li>
<h3>Charmander</h3>
<div>
<span>Properties</span>
<ul>
<li>orange or some kind of red, I am not completely sure</li>
<li>lizard</li>
<li>fire</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/7/73/004Charmander.png" />
</li>
<li>
<h3>Squirtle</h3>
<div>
<span>Properties</span>
<ul>
<li>blue</li>
<li>tiny turtle</li>
<li>water</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/3/39/007Squirtle.png" />
</li>
</ul>
</section>
This looks pretty nice when the properties for all elements are equally long, but it kind of looks messy when this is not the case (the property-lists are not properly aligned as indicated by the red lines in the above snippet). I know I could get all the content in a table, causing every table element to be aligned nicely under each other, but then I don't know how I can have my names in a different line than the properties and the image...
My question could thus be formulated as:
How can I align the properties nicely under each other in such a way that they are displayed next to the image (to fill the space on the screen)? Additionally I would like that the image is displayed under the properties when the screen becomes too small (i.e. responsive design) and a separate line for the name.
Any help will be greatly appreciated
Update:
As it turned out that my question is not that clear, I tried to make it more clear by adding the vertical red lines in the snippet. I manage to get the desired result when using a table, but then I have to omit the names (as shown in the attached image) and the responsiveness...
You can just create a simple item element, something like this:
HTML
<li class="item">
<h2>Charmander</h2>
<div class="content">
<h3>Properties</h3>
<ul>
<li>orange or some kind of red, I am not completely sure</li>
<li>lizard</li>
<li>fire</li>
</ul>
</div>
<div class="image">
<img src="http://cdn.bulbagarden.net/upload/7/73/004Charmander.png" />
</div>
</li>
I simply divided the element in three main sections: title, properties and the image.
As you can see the properties are still inside a <ul> because they are used like a enumeration.
CSS
#example > ul {
padding: 0;
}
.item {
width: 100%;
background: #CCC;
padding: 20px;
box-sizing: border-box;
/* Padding will be inside the element (will not affect the width/height) */
margin: 20px 0;
overflow: hidden;
/* Used to keep the floated element inside the flow */
}
.item h2 {
text-align: center;
}
.item .content {
width: 60%;
float: left;
padding-left: 20px;
box-sizing: border-box;
}
.item .image {
width: 200px;
float: left;
}
.item img {
width: 100%;
}
.item .content ul {
border-left: 2px solid red;
margin-bottom: 20px;
}
With the first selector (#example > ul) I reset the default padding it has.
The text of the properties will just start on a new-line if it is too long (you can test this by resizing the window).
You can just edit the padding-left of the .content element, to move the properties a little bit more to the right or to the left.
Example JsFiddle
This is just to give you an example of how you want to approach this.
Hope it was helpful!
I have just been so stupid. As an alternative to the helpful answer of nkmol, it could also be as simple as changing the justify-content property to space-between and correct it by setting width and auto-margins.
img {
max-width: 100px;
}
#example > ul > li {
width: 80%;
margin: auto;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
-webkit-align-items: center;
align-items: center;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
h3 {
width: 100%;
text-align: center;
}
li > div > ul {
border-left: 2px solid red;
}
<section id="example">
<ul>
<li>
<h3>Bulbasaur</h3>
<div>
<span>Properties</span>
<ul>
<li>green</li>
<li>seed</li>
<li>grass</li>
<li>poison</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/2/21/001Bulbasaur.png" />
</li>
<li>
<h3>Charmander</h3>
<div>
<span>Properties</span>
<ul>
<li>orange or some kind of red, I am not completely sure</li>
<li>lizard</li>
<li>fire</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/7/73/004Charmander.png" />
</li>
<li>
<h3>Squirtle</h3>
<div>
<span>Properties</span>
<ul>
<li>blue</li>
<li>tiny turtle</li>
<li>water</li>
</ul>
</div>
<img src="http://cdn.bulbagarden.net/upload/3/39/007Squirtle.png" />
</li>
</ul>
</section>
PS: I'm sorry for my awful question...
You need to break out your items from the primary UL
You can think of it as though you were building a table, but instead, use divs and then use a UL just to list the properties. This way, you can style each of the individual elements as needed.
look here: https://jsfiddle.net/oq04f6pm/2/
<section id="example">
<div class="section-title">Bulbasaur</div>
<div class="section-list">
<span>Properties</span>
<ul>
<li>green</li>
<li>seed</li>
<li>grass</li>
<li>poison</li>
</ul>
</div>
<div class="section-image">
<img src="http://cdn.bulbagarden.net/upload/2/21/001Bulbasaur.png" />
</div>
</section>
img {
max-width: 100px;
}
.section-title {
width: 100%;
text-align: center;
font-weight: bold;
}
.section-list, .section-image {
width: 50%;
float: left;
}
.section-image {
text-align: center;
}
#media screen and (max-width: 400px) {
.section-list, .section-image {
width: 100%;
}
.section-image {
text-align: left;
}
}

Why is justify-content space-between not doing anything?

I'm trying to get the top-nav and bot-nav divisions to separate vertically by using justify-content: space-between. However, it isn't doing anything. Can someone point out what I'm doing wrong please?
#import url(https://fonts.googleapis.com/css?family=Rock+Salt);
html {
font-family: 'Rock Salt', cursive;
}
.flex-container {
display: flex;
}
header {
width: 300px;
height: 100vh;
position: fixed;
background-color: blue;
}
nav.flex-container {
align-items: center;
flex-direction: column;
justify-content: space-between;
}
ul {
padding: 0;
margin: 0;
list-style-type: none;
}
#logo-container {
background-color: red;
width: 100%;
}
#logo {
margin: auto;
padding: 10px 0;
}
<body>
<div id="root-container">
<header>
<div id="logo-container" class="flex-container">
<h2 id="logo">Name Goes Here</h2>
</div>
<nav class="flex-container">
<div class="top-nav">
<ul>
<li>This is a list item</li>
<li>This is a list item</li>
</ul>
</div>
<div class="bot-nav">
<ul>
<li>This is a list item</li>
<li>This is a list item</li>
</ul>
</div>
</nav>
</header>
</div>
</body>
https://codepen.io/anon/pen/rxMPMN
The height of a block element defaults to the height of the block's content, unless you define a specific height. And flexbox justify-content defines how the browser distributes space between and around flex items. So it won't have any effects with flex-direction:column by default.
In your example nav.flex-container doesn't have any height defined, you can set either a percentage n% (as you already set 100vh on header, the parent element) or vh value to it.
nav.flex-container {
height: 80%; /*your value*/
}
Updated pen - https://codepen.io/anon/pen/LGRqzy
Or, set header to display:flex as well, and add flex:1 (grow) on nav.flex-container.
header {
display: flex;
flex-direction: column;
}
nav.flex-container {
flex: 1;
}
Updated pen - https://codepen.io/anon/pen/WrGPMW
You should add a height for .flex-container and then add overflow-y: scroll to the header to make the nav scrollable.
nav.flex-container
{
height: 100%;
align-items: center;
flex-direction: column;
justify-content: space-between;
}
header
{
width: $header-width;
height: 100vh;
position: fixed;
background-color: blue;
overflow-y: scroll;
}
justify-content only work in the flex-box main-axis direction, meaning flex-direction: row
You need to use align-content which is supposed to work for the cross-axis, flex-direction: column.
Reference Flexbox|Codrops Reference > align-content