Flexbox behaviour disappears on adding a piece of code in style ...please help to resolve this

The html code I tried is given below:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Load an icon library to show a hamburger menu (bars) on small screens -->

<style>

* {
  box-sizing: border-box;
}

.header {
  padding: 30px;
  text-align: center;
  background: white;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

/* Add a black background color to the top navigation */
.topnav {
  overflow: hidden;
  background-color: #333;
}

/* Style the links inside the navigation bar */
.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

/* Change the color of links on hover */
.topnav a:hover {
  background-color: #ddd;
  color: black;
}

/* Add an active class to highlight the current page */
.topnav a.active {
  background-color: #4CAF50;
  color: white;
}

/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
  display: none;
}

/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
@media screen and (max-width: 600px) {
  .topnav a:not(:first-child) {display: none;}
  .topnav a.icon {
    float: right;
    display: block;
  }
}

/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. 
This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }

/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. 
This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  
.topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
  
.flex-container {
  display: flex;
  flex-wrap: wrap;
  }
  
.flex-item-left {
  background-color: #f1f1f1;
  padding: 20px;
  flex: 50%;
}

.flex-item-right {
  background-color: dodgerblue;
  padding: 20px;
  flex: 50%;
}

/* Responsive layout - makes a one column-layout instead of a two-column layout */
@media (max-width: 600px) {
  .flex-item-right, .flex-item-left {
    flex: 100%;
  }
}


</style>
</head>
<body>

 <div class="flex-container">
  <div class="flex-item-left">
  <h2>Our Vision</h2>
  <h3>True to its name Karunya which means 'Compassion' shall be an institution with social concern to address the problems of humanity through technical education, research and development, products, patents and extension.
  The faculty and students of Karunya will be nurtured in character, ethics and spiritual discernment to serve the society with fervor.</h3>
  </div>

 <div class="flex-item-right">
  <h2>Our Mission</h2>
  <h3>True to its name Karunya which means 'Compassion' shall be an institution with social concern to address the problems of humanity through technical education, research and development, products, patents and extension.
 The faculty and students of Karunya will be nurtured in character, ethics and spiritual discernment to serve the society with fervor.</h3>
 </div>
</div>
</body>
</html>

if I remove the code -

/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. 
This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }

I get output as sexpected with flexbox. I dont understand why this piece of code affects flexbox behaviour.Please help to solve.

expected

Thanks…

* { box-sizing: border-box; } 
.header { padding: 30px; text-align: center; background: white; } 
body { margin: 0; font-family: Arial, Helvetica, sans-serif; } /* Add a black background color to the top navigation */
 .topnav { overflow: hidden; background-color: #333; } /* Style the links inside the navigation bar */ 
.topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } /* Change the color of links on hover */
 .topnav a:hover { background-color: #ddd; color: black; } /* Add an active class to highlight the current page */
 .topnav a.active { background-color: #4CAF50; color: white; } /* Hide the link that should open and close the topnav on small screens */
 .topnav .icon { display: none; } /* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
 @media screen and (max-width: 600px)
 { .topnav a:not(:first-child) {display: none;}
 .topnav a.icon { float: right; display: block; } } /* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
 @media screen and (max-width: 600px)
 { .topnav.responsive {position: relative;}
 .topnav.responsive .icon { position: absolute; right: 0; top: 0; } /* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
 @media screen and (max-width: 600px)
 { .topnav.responsive {position: relative;}
 .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } 
.flex-container { display: flex; flex-wrap: wrap; } 
.flex-item-left { background-color: #f1f1f1; padding: 20px; flex: 50%; } 
.flex-item-right { background-color: dodgerblue; padding: 20px; flex: 50%; } /* Responsive layout - makes a one column-layout instead of a two-column layout */ @media (max-width: 600px) 
{ .flex-item-right, .flex-item-left { flex: 100%; } }

display the code like this

Can you please guide on how to display code like that.I am new to this platform .

Thanks

<!DOCTYPE html>
 <html>
<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <!-- Load an icon library to show a hamburger menu (bars) on small screens -->

 <style>

 * {
   box-sizing: border-box;
 }

.header {
   padding: 30px;
   text-align: center;
   background: white;
 }

body {
   margin: 0;
   font-family: Arial, Helvetica, sans-serif;
 }

 /* Add a black background color to the top navigation */
 .topnav {
   overflow: hidden;
   background-color: #333;
 }

 /* Style the links inside the navigation bar */
 .topnav a {
   float: left;
   display: block;
   color: #f2f2f2;
   text-align: center;
   padding: 14px 16px;
   text-decoration: none;
   font-size: 17px;
 }

 /* Change the color of links on hover */
 .topnav a:hover {
   background-color: #ddd;
   color: black;
 }

 /* Add an active class to highlight the current page */
 .topnav a.active {
   background-color: #4CAF50;
   color: white;
 }

 /* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
   display: none;
 }

 /* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
 @media screen and (max-width: 600px) {
   .topnav a:not(:first-child) {display: none;}
   .topnav a.icon {
     float: right;
     display: block;
   }
 }

 /* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. 
 This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
 @media screen and (max-width: 600px) {
   .topnav.responsive {position: relative;}
   .topnav.responsive .icon {
     position: absolute;
     right: 0;
     top: 0;
   }

 .topnav.responsive a {
     float: none;
     display: block;
     text-align: left;
   }
   
 .flex-container {
   display: flex;
   flex-wrap: wrap;
   }
   
 .flex-item-left {
   background-color: #f1f1f1;
   padding: 20px;
   flex: 50%;
 }

 .flex-item-right {
   background-color: dodgerblue;
   padding: 20px;
   flex: 50%;
 }

 /* Responsive layout - makes a one column-layout instead of a two-column layout */
 @media (max-width: 600px) {
   .flex-item-right, .flex-item-left {
     flex: 100%;
   }
 }


 </style>
 </head>
 <body>

  <div class="flex-container">
   <div class="flex-item-left">
   <h2>Our Vision</h2>
   <h3>True to its name Karunya which means 'Compassion' shall be an institution with social concern to address the problems of humanity through technical education, research and development, products, patents and extension.
   The faculty and students of Karunya will be nurtured in character, ethics and spiritual discernment to serve the society with fervor.</h3>
   </div>

  <div class="flex-item-right">
   <h2>Our Mission</h2>
   <h3>True to its name Karunya which means 'Compassion' shall be an institution with social concern to address the problems of humanity through technical education, research and development, products, patents and extension.
  The faculty and students of Karunya will be nurtured in character, ethics and spiritual discernment to serve the society with fervor.</h3>
  </div>
 </div>
 </body>
 </html>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

Pre-formatted-text

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank you for the help and guidance. Issue was that - a closing parenthesis was missing at the last line. Issue resolved now …

/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. 
 This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
 @media screen and (max-width: 600px) {
   .topnav.responsive {position: relative;}
   .topnav.responsive .icon {
     position: absolute;
     right: 0;
     top: 0;
   }
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.