css 使宽度< h3>变小

e7arh2l6  于 2023-10-21  发布在  其他
关注(0)|答案(2)|浏览(97)

我想减少<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>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">
          <!-- 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>

我希望<h3>在宽度上小于<h1>,但我不确定如何做到这一点。我试了很多方法,但都不能让它看起来正确。我以为我已经完成了设计,但后来意识到我想要一个较小的标题,说明我所在的国家的页面。我怎么才能让它工作?

oiopk7p5

oiopk7p51#

在全屏中查看输出。
试试这个,只是在CSS下面修改。

*{
    margin:0;  // to reset default margin for all tags
    }
    header {
    background-color: #ff6600;
    color: #fff;
    padding: 20px;
    text-align: center;
    max-width: 600px;    // <-- added
    margin: 0 auto;      // <-- added
    }
    h3{
    margin:5px 0;   // like that you can adjust height
    }
*{
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 { /* 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>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">
          <!-- 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>
xriantvc

xriantvc2#

尝试在CSS中更改max-width

相关问题