css - 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>
解决方案
我喜欢在 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上查看更多信息
推荐阅读
- laravel - 如何为所有 Lumen 路由使用 auth:api 中间件?
- gradle - 收集父项目构建目录中的文件
- python-3.x - 比较文字字符串与 subprocess.Popen PowerShell 输出失败
- php - 使用 PHP 从查询字符串中获取倒数第二个参数
- android - 如何将 Shrinker (R8) 与 react-native 一起使用
- sql - 将列数据放入正确的目标列sql ssis
- python - 散景装饰器@without_document_lock() 是什么意思?
- java - 如何在 Spring Boot 2 项目中生成 CRUD UI?类似于 Django 的做法
- javascript - 用 Ag-grid 和 Razor Pages 书写口音
- ansible-inventory - 如何从变量文件中识别我的剧本中的主机?