首页 > 解决方案 > Iphone 5 的标题 CSS

问题描述

我想为 iPhone 5 调整我的屏幕

在此处输入图像描述

iPhone 5 的尺寸为320x568

我的问题是元素不在一条线上。

我必须减小字体大小?问题是屏幕不够小。

在此处输入图像描述

@media only screen and (max-width: 374px) and (min-width: 320px) {
    /* Iphone 5 */ 
 
    .top-bar {
        position: relative;
        height: 45px;
        background-color: aqua;
    }

    .container {
        display: flex;
        width: 100%;
    }
}

我目前不知道如何解决我的问题。

这是我的 HTML 和 CSS 代码:

/*******************************/
/********* General CSS *********/
/*******************************/



body {
    margin: 0;
    padding: 0;
    font-family: 'Roboto Slab', serif;
}

a {
    text-decoration: none;
    transition: .3s;
    color: black;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

li {
    display: inline-block;
}

h1,
h2, 
h3, 
h4,
h5, 
h6 {
    margin: 0;
}

p {
    margin: 0;
}

/**********************************/
/********** Top Bar CSS ***********/
/**********************************/

.top-bar {
    position: relative;
    height: 45px;
    background-color: aqua;
}

.container {
    display: flex;
    justify-content: space-between;
    margin: 0 auto;
    width: 80%;
}

.top-bar .top-bar-left {
    display: flex;
}

.top-bar .text {
    display: flex;
    align-items: center;
 /* aligne les éléments sur la même ligne */
    justify-content: center;
    height: 50px;
    margin-right: 10px;
}

.top-bar .text i {
    color: #C22312;
    margin-right: 5px;
}

.top-bar .text h2 {
    font-size: 14px;
    letter-spacing: 1px;
    font-weight: 400;
    text-transform: uppercase;
    margin-right: 10px;
}

.top-bar .top-bar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.top-bar .hyper-text {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 7px;
    text-transform: uppercase;
}

.top-bar .hyper-text i {
    color: black;
    margin-right: 5px;
    margin-left: 5px;
}

@media only screen and (max-width: 374px) and (min-width: 320px) {
    /* Iphone 5 */ 
 
    .top-bar {
        position: relative;
        height: 45px;
        background-color: aqua;
    }

    .container {
        display: flex;
        font-size: 15px;
        width: 100%;
    }
}
<!DOCTYPE html>
<html>
   <head>
      <title>HTML CSS JS</title>
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
      <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet">
   </head>
   <body>
      <div class="top-bar">
         <div class="container">
            <div class="top-bar-left">
               <div class="text">
                  <i class="far fa-calendar"></i>
                  <h2>138 runnings days</h2>
               </div>
               <div class="text">
                  <i class="far fa-envelope"></i>
                  <h2>admin@superbtc.biz</h2>
               </div>
            </div>
            <div class="top-bar-right">
               <div class="hyper-text">
                  <select name="language" id="language-select">
                     <option value="english">English</option>
                     <option value="french">French</option>
                  </select>
                  <a href="#"><i class="fas fa-angle-right"></i>Deposit</a>
                  <a href="#"><i class="fas fa-angle-right"></i>Paidout</a>
               </div>
            </div>
         </div>
      </div>
   </body>
</html>

标签: cssresponsive

解决方案


我喜欢在 CSS 中使用vw%单元来进行响应式网页设计。
有一种简单的方法可以使用以下方法制作响应式字体大小vw

.back {
  background: #e9e9e9;
  text-align: center;
  padding: 0.5vw 0;
}
.fore {
  margin: 5px;
  font-size: 2.5vw;
}
<div class="back">
  <span class="fore">Responsive.</span>
</div>


这是一个工作示例:

body {
    margin: 0;
    padding: 0;
    font-family: 'Roboto Slab', serif;
    height: 100vh;
    width: 100vw;
}

a {
    text-decoration: none;
    transition: .3s;
    color: black;
    font-size: 1.5vw;
    margin-left: 2px;
    padding: 0;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

li {
    display: inline-block;
}

h1,
h2, 
h3, 
h4,
h5, 
h6 {
    margin: 0;
}

p {
    margin: 0;
}

/**********************************/
/********** Top Bar CSS ***********/
/**********************************/

.top-bar {
    position: relative;
    height: 45px;
    background-color: aqua;
}

.container {
    display: flex;
    justify-content: space-between;
    margin: 0 auto;
    width: 80%;
}

.top-bar .top-bar-left {
    display: flex;
}

.top-bar .text {
    display: inline-flex;
    align-items: center;
 /* aligne les éléments sur la même ligne */
    justify-content: center;
    height: 50px;
    margin-right: 10px;
    font-size: 1.2vw !important;
}

.top-bar .text i {
    color: #C22312;
    margin-right: 5px;
}

.top-bar .text h2 {
    letter-spacing: 1px;
    font-weight: 400;
    text-transform: uppercase;
    margin-right: 10px;
}

.top-bar .top-bar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.top-bar .hyper-text {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 7px;
    text-transform: uppercase;
}

.top-bar .hyper-text i {
    color: black;
    margin-right: 5px;
    margin-left: 5px;
}

@media only screen and (max-width: 374px) and (min-width: 320px) {
    /* Iphone 5 */ 
 
    .top-bar {
        position: relative;
        height: 45px;
        background-color: aqua;
    }

    .container {
        display: flex;
        font-size: 15px;
        width: 100%;
    }
}
<!DOCTYPE html>
<html>
   <head>
      <title>HTML CSS JS</title>
      <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0">
      <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet">
   </head>
   <body>
      <div class="top-bar">
         <div class="container">
            <div class="top-bar-left">
               <div class="text">
                  <i class="far fa-calendar"></i>
                  <h2>138 runnings days</h2>
               </div>
               <div class="text">
                  <i class="far fa-envelope"></i>
                  <h2>admin@superbtc.biz</h2>
               </div>
            </div>
            <div class="top-bar-right">
               <div class="hyper-text">
                  <select name="language" id="language-select">
                     <option value="english">English</option>
                     <option value="french">French</option>
                  </select>
                  <a href="#"><i class="fas fa-angle-right"></i>Deposit</a>
                  <a href="#"><i class="fas fa-angle-right"></i>Paidout</a>
               </div>
            </div>
         </div>
      </div>
   </body>
</html>

如果浏览器/设备具有特定的宽度/高度,您可以使用名为“ @media”的 CSS 规则为元素设置样式:

p {
  color: #333;
  font-size: 2.5vw;
  font-family: Arial, Helvetica, sans-serif;
}
body {
  background-color: #f9f9f9;
}
@media only screen and (max-width: 600px) {
  body {
    background-color: #333;
  }
  p {
    color: white;
  }
}
<!DOCTYPE html>
<html>
  <body>
    <p style="text-align: center;">Resize the browser to see the effect.</p>
  </body>
</html>

在https://www.w3schools.com/whatis/whatis_responsive.asp上查看更多信息


推荐阅读