Reduce the width of the <h3> element

I need help adjusting the width of the <h3>

HTML

 body {
          font-family: Arial, sans-serif;
          background-color: #f0f0f0;
          margin: 0;
          padding: 0;
          overflow: hidden;
        }

        header {
          background-color: #ff6600;
          color: #fff;
          padding: 20px;
          text-align: center;
        }

        h1 {
          font-size: 28px;
          margin: 0;
        }

        main {
          display: flex;
          flex-direction: column;
          align-items: center;
          width: 100%;
          height: 100vh;
          overflow: hidden;
        }

        #content-wrapper {
          background-color: #fff;
          border-radius: 4px;
          box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
          padding: 20px;
          width: 100%;
          max-width: 1000px; /* Adjust this value to fit your screen */
          text-align: center;
          margin: 0 auto;
          overflow-x: hidden;
          max-height: 100%;
        }

        #story-number {
          padding: 10px 16px;
          font-size: 14px;
          border: 1px solid #ccc;
          border-radius: 4px;
          width: 200px;
          height: 30px;
          margin-bottom: 10px;
        }

        #get-container {
          display: flex;
          flex-direction: column;
          align-items: center;
        }

        #get,
        #getRandom,
        #clear,
        #back { /* Style for the "Back" button */
          background-color: #ff6600;
          color: #fff;
          border: none;
          padding: 10px 20px;
          font-size: 16px;
          cursor: pointer;
          border-radius: 4px;
          transition: background-color 0.3s ease;
          margin-bottom: 10px;
          outline: none;
        }

        #get:hover,
        #getRandom:hover,
        #clear:hover,
        #back:hover { /* Hover effect */
          background-color: #ff9933; /* Change the background color on hover */
        }

        #story-container {
          background-color: #fff;
          text-align: center;
          display: none;
          max-height: 320px; /* Set the maximum height here */
          overflow-y: auto; /* Add this line for the vertical scrollbar */
          padding: 0 20px; /* Add padding to the left and right */
        }

        #generated-text {
          font-size: 18px;
          line-height: 1.5;
          margin-bottom: 10px;
          color: #333;
          text-align: center;
        }

        #generated-text span {
          font-weight: bold;
          color: #000;
          font-size: 20px;
        }

        #back { /* Style for the "Back" button */
          display: none;
          margin: 10px auto;
        }

        @media (min-width: 601px) {
          #content-wrapper {
            max-width: 600px;
          }
        }

        @media (max-width: 600px) {
          #content-wrapper {
            max-width: 90%; /* Adjust width as needed */
            max-height: 80vh; /* Adjust height as needed */
            overflow-y: auto; /* Add vertical scrollbar */
          }
          #story-container {
            max-height: 58vh; /* Adjust the value as needed for your device */
          }
          #get,
          #getRandom,
          #clear,
          #back { /* Style for smaller screens */
            font-size: 10px !important;
            padding: 20px 20px !important;
          }
        }
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Stories - USA</title>
    <link rel="stylesheet" href="../CSS/country.css">
</head>
<body data-country="usa">
    <header>
        <h1>Title Placeholder</h1>
        <h3>Country Name</h3>
    </header>
    <main>
      <div id="content-wrapper">
        <div id="get-container">
          <input type="text" id="story-number" placeholder="Enter story number">
          <button id="get" type="button">Get Story</button>
          <button id="getRandom" type="button">Random Story</button>
        </div>
        <div id="story-container">
          <!-- Story content will be displayed here -->
          <div id="generated-text"></div>
          <button id="back" type="button">Back</button>
        </div>
      </div>
    </main>
    <script src="Scripts/argentina.js"></script>
</body>
</html>

I am struggling with making the <h3> width narrower than the <h1>. Can you provide guidance on how to achieve this? I initially thought I had completed my design, but now I realize that I require a smaller heading to indicate the current country page. How can I achieve this without compromising the layout?

Answer №1

Click to view the output in fullscreen.

Give this a shot: just tweak the CSS below.

*{
    margin:0;  // reset default margin for all elements
}
header {
    background-color: #ff6600;
    color: #fff;
    padding: 20px;
    text-align: center;
    max-width: 600px;    // <-- added for width adjustment
    margin: 0 auto;      // <-- added for centering
}
h3{
   margin:5px 0;   // adjust height as needed
}

*{
margin:0;
}
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
overflow: hidden;
}
h3{
 margin:5px 0;
 }
header {
background-color: #ff6600;
color: #fff;
padding: 20px;
text-align: center;
max-width: 600px;
margin: 0 auto;
}
h1 {
font-size: 28px;
margin: 0;
}
main {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
height: 100vh;
overflow: hidden;
}
#content-wrapper {
background-color: #fff;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 100%;
max-width: 1000px; /* Adjust this value to fit your screen */
text-align: center;
margin: 0 auto;
overflow-x: hidden;
max-height: 100%;
}
#story-number {
padding: 10px 16px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 4px;
width: 200px;
height: 30px;
margin-bottom: 10px;
}
#get-container {
display: flex;
flex-direction: column;
align-items: center;
}
#get,
#getRandom,
#clear,
#back { /* Styling for "Back" button */
background-color: #ff6600;
color: #fff;
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s ease;
margin-bottom: 10px;
outline: none;
}
#get:hover,
#getRandom:hover,
#clear:hover,
#back:hover { /* Hover effect */  
background-color: #ff9933; /* Change background color on hover */
}
#story-container {
background-color: #fff;
text-align: center;
display: none;
max-height: 320px; /* Set maximum height */
overflow-y: auto; /* Add vertical scrollbar */
padding: 0 20px; /* Add padding left and right */
}
#generated-text {
font-size: 18px;
line-height: 1.5;
margin-bottom: 10px;
color: #333;
text-align: center;
}
#generated-text span {
font-weight: bold;
color: #000;
font-size: 20px;
}
#back { /* Style for "Back" button */ 
display: none;
margin: 10px auto;
}
@media (min-width: 601px) {
#content-wrapper {
max-width: 600px;
}
}
@media (max-width: 600px) {
#content-wrapper {
max-width: 90%; /* Adjust width as necessary */
max-height: 80vh; /* Adjust height as necessary */
overflow-y: auto; /* Add vertical scroll */
}
#story-container {
max-height: 58vh; /* Adjust value accordingly */
}
#get,
#getRandom,
#clear,
#back { /* Style for smaller screens */
font-size: 10px !important;
padding: 20px 20px !important;
}
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Stories - USA</title>
    <link rel="stylesheet" href="../CSS/country.css">
</head>
<body data-country="usa">
    <header>
        <h1>Stories</h1>
        <h3>Argentina</h3>
    </header>
    <main>
      <div id="content-wrapper">
        <div id="get-container">
          <input type="text" id="story-number" placeholder="Enter story number">
          <button id="get" type="button">Get Story</button>
          <button id="getRandom" type="button">Random Story</button>
        </div>
        <div id="story-container">
          <!-- The story content will appear here -->
          <div id="generated-text"></div>
          <button id="back" type="button">Back</button>
        </div>
      </div>
    </main>
    <script src="Scripts/argentina.js"></script>
</body>
</html>

Answer №2

Consider adjusting the max-width attribute within your CSS

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

How to embed HTML code within PHP using a conditional variable

I've encountered an issue with a PHP code that sends emails containing HTML templates. The HTML template includes PHP variables such as Name and Email. <strong>Name: {name} </strong> As the email template is lengthy, I have included ...

loading xml data into a table partially using jquery

Currently, I am utilizing AJAX to load and parse XML data. I have constructed a table where I am inserting the data from the XML using a loop. The issue lies in the fact that only around 3000 rows are being inserted into the table even though the XML conta ...

What are the steps to integrate <br> in a JavaScript code?

I have recently started learning about web development and I'm facing a challenge with this implementation. var obj = [[{ name: "John", age: 30, city: "New York"}, { name: "Ken", age: 35, city: "New Orleans"}]]; ...

Creating user-friendly options for multi-checkbox forms using Django enums

I am facing an issue with my code where it only displays the shorter variable values for 'Plan 1' and 'Plan 2', rather than their longer human-readable forms that I have defined in the model. I am creating checkboxes in an HTML templat ...

Adjust the number of images in each row based on the width of the screen

I have experimented with various methods, but none seem to work flawlessly. My goal is to neatly display around 50 images in rows and columns, adjusting the length of each row based on the screen width. Here are the approaches I've tried: Placing ...

Troubleshooting: Issues with Angular form validation functionality

I am completely new to Angular and attempting to create a signup form. Despite following tutorials, the form I've built doesn't seem to be validating properly. Below is the code that I have been using: <div class="signup-cont cont form-conta ...

What is the most efficient method for clearing the innerHTML when dealing with dynamic content?

Is there a more efficient method for cleaning the innerHTML of an element that is constantly changing? I created a function to clean the containers, but I'm not sure if it's the most efficient approach. While it works with the specified containe ...

Angular 11.0.3 displaying ngClass issue (Unable to bind ngClass as it is not recognized as a property of div)

While working on an angular project, I implemented a light and dark theme using mat-slide-toggle to switch between themes. The theme is stored as a boolean called isDark in a Behavioral Subject service. There are two lazy-loaded modules - one for the home ...

Utilize AngularJS's nested ng-repeat to showcase information from two distinct JSON strings simultaneously

I am dealing with two different JSON strings from databases. [{ sport: football, sportid: 1 },{ sport: tennis, sportid: 2 },{ sport: golf, sportid: 3 },{ sport: swimming, sportid: 4 }] and [{ personid: 1, name: ...

Using Modernizr to determine the presence of nth-child in a test

I'm attempting to utilize modernizr in order to check for browser support of the :nth-child selector, but I am unsure of how to proceed. I came across this particular example on http://jsfiddle.net/laustdeleuran/3rEVe/ which tests for :last-child. How ...

Unfortunately, the header and footer are not lining up correctly with the main body on our mobile site

I've been tasked with creating a fully responsive website, but I'm encountering difficulties with the mobile design. Specifically, when I switch to mobile dimensions like an iPhone 12, the header and footer don't line up properly with the ma ...

Update the color of the angular material input text box to stand out

Hey there, I'm currently using Angular Material and I want to change the color of the input focus when clicked. At the moment, it's displaying in purple by default, but I'd like it to be white instead. https://i.stack.imgur.com/vXTEv.png ...

Interpreting HTML using a PHP script and running PHP commands embedded in the file

Does anyone know how to execute PHP code within an HTML file that is being opened inside a PHP file? Here's the scenario: I have an HTML file structured like this: <html> <head> <title></title> </head> ...

How can I create spacing between squares in an HTML div element?

Currently, I am working on my project using Laravel 5. I retrieve some integer values from a database and use them to create square divs in HTML. Below is the current output of my work. https://i.stack.imgur.com/sy2ru.png You may notice that there is spa ...

A difference in the way content is displayed on Firefox compared to Chrome, Edge, and Safari

Recently, I encountered an issue with a tool I had developed for generating printable images for Cross-Stitch work. The tool was originally designed to work on Firefox but is now only functioning properly on that browser. The problem at hand is whether th ...

What is the problem with locating elements in Selenium with Java?

I've been encountering difficulties in finding elements on a webpage structured like this: <tr id="filter100" style="...." idx=0 <td> <div onclick=... style=... <table dir = "fil"> <tbody> ...

Integrating foundation-sites with webpack, unable to apply styles

Delving into the world of webpack for the first time has been quite a daunting experience! I'm attempting to set up the foundation for sites, but I feel completely lost when it comes to configuring it properly. Here is my Webpack configuration: var ...

Utilize styling only when both classes are actively used within media queries or bootstrap

Despite specifying to apply the text-align to 'md-3' instead of 'sm', it still applies when the browser is resized to use the 'sm' style. Simply put, I only want the style to be applied if the media queries interpret my devic ...

What is the process for activating JavaScript and embedding it into an HTML document?

I am currently utilizing a JavaScript API that contains several functions. How can I incorporate it into an HTML file? One of the functions, "api.ping()", performs well on PowerShell, but I am encountering difficulties with displaying it on an HTML file. ...

Dealing with a syntax error in JavaScript (Codecademy)

I have been working my way through the JavaScript course on Codeacademy and for the most part, I've been able to figure things out on my own. However, I've hit a roadblock with my code and can't seem to get it right. Here is the code I&apos ...