Html-移动端与响应式

这篇博客介绍了如何使用HTML和CSS实现移动端响应式布局,包括设置元素尺寸、背景图片、导航栏的设计,并展示了在屏幕尺寸小于768px时的样式变化,以及通过媒体查询实现不同设备的适配。内容涵盖了前端开发中关于移动端优化和响应式设计的关键知识点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

width: 15px;

height: 15px;

background-image: url(“…/imag/xiangyou1.png”);

background-position: center center;

background-size: 100% auto;

background-repeat: no-repeat;

}

.picture {

width: 80%;

height: 90%;

height: 281px;

flex: 3;

display: flex;

flex-direction: row;

justify-content: space-around;

margin: 0px;

}

.picture .img_1 {

flex: 1;

}

.picture .img_2 {

flex: 1;

}

.picture .img_3 {

flex: 1;

}

  • {

margin: 0;

padding: 0;

}

.nav {

width: 100%;

height: 44px;

background-color: rgba(0, 0, 0, 0.8);

display: flex;

justify-content: center;

align-items: center;

font-family: “宋体”;

font-size: 12px;

}

.nav a {

color: #fff;

/* 设置a标签下划线为none */

text-decoration: none;

width: 102px;

text-align: center;

}

.nav > .logo {

height: 44px;

width: 44px;

background-image: url(“…/imag/logo.png”);

background-repeat: no-repeat;

background-position: center;

}

.nav > .search {

width: 44px;

height: 44px;

background-image: url(“…/imag/search.png”);

background-repeat: no-repeat;

background-position: center;

}

.nav > .buy {

width: 44px;

height: 44px;

background-image: url(“…/imag/buy.png”);

background-repeat: no-repeat;

background-position: center;

}

label {

width: 44px;

height: 44px;

}

.togglebtn {

width: 44px;

display: none;

position: relative;

flex-direction: column;

justify-content: center;

align-items: center;

}

.togglebtn > .line {

width: 18px;

height: 1px;

background-color: #fff;

display: none;

transition: all 0.5s;

transform-origin: left center;

}

.togglebtn .line:nth-child(1) {

position: absolute;

top: 15px;

}

.togglebtn .line:nth-child(2) {

position: absolute;

top: 27px;

}

/*

设定屏幕小于768像素时的像素

*/

.navpage {

width: 100vw;

overflow: hidden;

display: flex;

height: 0vh;

transition: all 0.8s;

position: fixed;

left: 0;

top: 0;

background-color: #000;

}

.navpage .navmain {

width: 100%;

}

@media only screen and (max-width: 768px) {

.togglebtn {

display: flex;

position: relative;

z-index: 100;

}

.nav > .logo {

position: relative;

z-index: 100;

}

.togglebtn > .line {

display: block;

}

.nav > .text {

display: none;

}

. 《大厂前端面试题解析+Web核心总结学习笔记+企业项目实战源码+最新高清讲解视频》无偿开源 徽信搜索公众号【编程进阶路】 nav {

justify-content: space-between;

}

.nav > a {

width: 50px;

}

.nav .togglebtn {

order: 1;

}

.nav .logo {

order: 2;

}

.nav .buy {

order: 3;

}

#choose:checked ~ .togglebtn .line:nth-child(1) {

transform: rotate(44deg);

}

#choose:checked ~ .togglebtn .line:nth-child(2) {

transform: rotate(-43deg);

}

#choose:checked ~ .navpage {

display: flex;

/*

vw:viewport width 视窗的宽度 ==100vw =100%视窗的高度

vh:viewport height:100vh == 100% viewport height

*/

width: 100vw;

height: 100vh;

color: #fff;

position: fixed;

left: 0;

top: 0;

background-color: #000;

flex-direction: column;

padding-top: 44px;

}

.searchInput {

margin: 0px 28px;

display: flex;

justify-content: flex-start;

align-items: center;

height: 44px;

border-radius: 4px;

color: #ccc;

background-color: rgba(45, 45, 45, 0.98);

}

.searchInput .icon {

width: 32px;

height: 36px;

background-image: url(“…/imag/search.png”);

background-repeat: no-repeat;

background-position: center;

/* 设置图片背景时,一定要考虑 图片的url 位置 尺寸 重复*/

}

.searchInput input {

flex: 1;

margin: 0 10px;

height: 100%;

background: transparent;

border: none;

outline: none;

color: #fff;

}

hr {

border-color: #333;

margin-top: 15px;

}

.navList {

margin: 0 28px;

display: flex;

flex-direction: column;

justify-content: center;

}

.navList a {

width: 100%;

height: 44px;

color: #fff;

text-align: left;

line-height: 44px;

border-bottom: 1px solid #333;

}

.navList a:last-child {

border-bottom: none;

}

}

练习完结版

<meta

name=“viewport”

content=“width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no”

/>

Document

Mac

ipad

iphone

watch

music

TV

SUPPORT


MAC

IPAD

IPHOME

WATCH

TV

MUSIC

SUPORT

让节日,快乐每一个人。

让节日,

快乐每一个人。

新款

更大屏幕腕上见

进一步了解

购买

更大屏幕腕上见

进一步了解

购买

iphonestyle

  • {

margin: 0;

padding: 0;

}

.nav {

width: 100%;

height: 44px;

background-color: rgba(0, 0, 0, 0.8);

display: flex;

justify-content: center;

align-items: center;

font-family: “宋体”;

font-size: 12px;

}

.nav a {

color:rgba(255,255,255,0.82);

/* 设置a标签下划线为none */

text-decoration: none;

width: 102px;

text-align: center;

}

.nav a:hover{

color: #fff;

}

.nav > .logo {

height: 44px;

width: 44px;

background-image: url(“…/imag/logo.png”);

background-repeat: no-repeat;

background-position: center;

}

.nav > .search {

width: 44px;

height: 44px;

background-image: url(“…/imag/search.png”);

background-repeat: no-repeat;

background-position: center;

}

.nav > .buy {

width: 44px;

height: 44px;

background-image: url(“…/imag/buy.png”);

background-repeat: no-repeat;

background-position: center;

}

label {

width: 44px;

height: 44px;

}

.togglebtn {

width: 44px;

display: none;

position: relative;

flex-direction: column;

justify-content: center;

align-items: center;

}

.togglebtn > .line {

width: 18px;

height: 1px;

background-color: #fff;

display: none;

transition: all 0.5s;

transform-origin: left center;

}

.togglebtn .line:nth-child(1) {

position: absolute;

top: 15px;

}

.togglebtn .line:nth-child(2) {

position: absolute;

top: 27px;

}

/*

设定屏幕小于768像素时的像素

*/

.navpage {

z-index: 10;

width: 100vw;

overflow: hidden;

display: flex;

height: 0vh;

transition: all 0.8s;

position: fixed;

left: 0;

top: 0;

background-color: #000;

}

.navpage .navmain {

width: 100%;

}

@media only screen and (max-width: 700px) {

.togglebtn {

display: flex;

position: relative;

z-index: 100;

}

.nav > .logo {

position: relative;

z-index: 100;

}

.togglebtn > .line {

display: block;

}

.nav > .text {

display: none;

}

.nav {

justify-content: space-between;

}

.nav > a {

width: 50px;

}

.nav .togglebtn {

order: 1;

}

.nav .logo {

order: 2;

}

.nav .buy {

order: 3;

}

#choose:checked ~ .togglebtn .line:nth-child(1) {

transform: rotate(44deg);

}

#choose:checked ~ .togglebtn .line:nth-child(2) {

transform: rotate(-43deg);

}

#choose:checked ~ .navpage {

display: flex;

/*

vw:viewport width 视窗的宽度 ==100vw =100%视窗的高度

vh:viewport height:100vh == 100% viewport height

*/

width: 100vw;

height: 100vh;

color: #fff;

position: fixed;

left: 0;

z-index: 10;

top: 0;

background-color: #000;

flex-direction: column;

padding-top: 44px;

}

.searchInput {

margin: 0px 28px;

display: flex;

justify-content: flex-start;

align-items: center;

height: 44px;

border-radius: 4px;

color: #ccc;

background-color: rgba(45, 45, 45, 0.98);

}

.searchInput .icon {

width: 32px;

height: 36px;

background-image: url(“…/imag/search.png”);

background-repeat: no-repeat;

background-position: center;

/* 设置图片背景时,一定要考虑 图片的url 位置 尺寸 重复*/

}

.searchInput input {

flex: 1;

margin: 0 10px;

height: 100%;

background: transparent;

border: none;

outline: none;

color: #fff;

}

hr {

border-color: #333;

margin-top: 15px;

}

.navList {

margin: 0 28px;

display: flex;

flex-direction: column;

justify-content: center;

}

.navList a {

width: 100%;

height: 44px;

color: #fff;

text-align: left;

line-height: 44px;

border-bottom: 1px solid #333;

}

.navList a:last-child {

border-bottom: none;

}

}

banner

@import url(“./hbanner.css”);

.banner {

display: flex;

width: 100%;

height: 580px;

background-color: #edeffe;

flex-direction: column;

justify-content: center;

align-items: center;

}

.copywarp {

flex: 2;

display: flex;

flex-direction: column;

justify-content: flex-start;

align-items: center;

text-align: center;

}

.copywarp .redapple {

margin: 20px 0;

width: 54px;

height: 67px;

background-image: url(“…/imag/applered.png”);

background-position: center;

background-repeat: no-repeat;

}

.copywarp h2 {

width: 500px;

position: inherit;

font-size: 43px;

line-height: 1.08349;

color: #1d1d1f;

padding-left: 20px;

margin-bottom: 20px;

}

.copywarp .rightlogo a {

text-decoration: none;

color: #06c;

}

.copywarp .rightlogo a:hover {

text-decoration: underline;

}

.rightlogo {

position: relative;

}

.rightlogo::before {

position: absolute;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值