gpt4 book ai didi

html - 如何使标题在手机上保持粘性?

转载 作者:行者123 更新时间:2023-12-05 01:11:20 25 4
gpt4 key购买 nike

目标

当此响应式 HTML5 模板调整为手机尺寸时,使标题具有粘性。

问题

我似乎无法找到正确的元素来添加 CSS position 属性。无论我将“粘性”类添加到哪个 DIV,它都不会固定在屏幕顶部。

在行动

桌面模式运行良好

Works

手机尺寸不合格

Wont Stick

失败的尝试

我试过附加一个类,像这样......

.makeSticky {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
}

...到每个元素,甚至远离标题。我只是找不到合适的,无法正常工作。

直播

这是在服务器上运行的页面:http://stpete.epizy.com/en/index.html

代码

  <header class="header-area header-3">
<div class="desktop-nav d-none d-lg-block">
<div class="header-nav">
<div class="container-fluid custom-container">
<div class="header-nav-wrapper d-flex justify-content-between">
<div class="header-static-nav">
<p>Get FREE Shipping with <span class="text">$35!</span> Code: FREESHIPPING</p>
</div>
<div class="header-menu-nav">
<ul class="menu-nav">
<li>
<div class="dropdown">
<button type="button" id="setting" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Setting <i class="icon ion-chevron-down"></i></button>

<ul class="dropdown-menu" aria-labelledby="setting">

<li><a href="checkout.html">Checkout</a></li>
<li><a href="login.html">Sign in</a></li>
</ul>
</div>
</li>

<li>
<div class="dropdown">
<button type="button" id="langue" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="images/1.jpg" alt=""> English <i class="icon ion-chevron-down"></i></button>

<ul class="dropdown-menu" aria-labelledby="langue">
<li><a href="http://123globalelecronicsllc.com/en"><img src="images/1.jpg" alt=""> English</a></li>
<li><a href="http://123globalelecronicsllc.com/sp"><img src="images/2.jpg" alt=""> Spanish</a></li>
</ul>
</div>
</li>
</ul>
</div> <!-- header menu nav -->
</div> <!-- header nav wrapper -->
</div> <!-- container -->
</div> <!-- header nav -->

<div class="header-middle">
<div class="container-fluid custom-container">
<div class="row">
<div class="col-lg-3">
<div class="header-logo-contact d-flex ">
<div class="desktop-logo">
<a href="index.html">
<img src="images/logo-white.png" alt="Global Eletronics, LLC">
</a>
</div> <!-- desktop logo -->
</div>
</div>
<div class="col-lg-9">
<div class="header-search-cart d-flex align-items-center">
<div class="header-contact d-flex align-items-center">
<i class="icon ion-ios-telephone-outline"></i>
<div class="phone media-body">
<p>24/7 Support</p>
<a href="tel:+7276230753">+727-623-0753</a>
</div>
</div>
<div class="header-search media-body">
<form action="#">
<div class="search-category">
<select>
<option value="">All categories</option>
<option value="audio">Audio Parts</option>
<option value="accessories">- - Accessories</option>
<option value="buzzers">- - Buzzers</option>
<option value="batteries">Battery Products</option>
<option value="batteries">- - Primary Batteries</option>

</select>
</div>
<input id="search-box" type="text" placeholder="Part #">
<button><i class="icon ion-android-search"></i></button>
</form>
</div>
<div class="header-cart">
<div class="cart-btn">
<a href="cart.html">
<i class="icon ion-calculator"></i>
<span class="text">RFQ Parts :</span>

<span class="count">0</span>
</a>
</div>
<!--
<div class="mini-cart">
<ul class="cart-items">
<li>
<div class="single-cart-item d-flex">
<div class="cart-item-thumb">
<a href="cart.html"><img src="images/cart-1.jpg" alt="product"></a>
<span class="product-quantity">1x</span>
</div>

</div>
</li>

</ul>
<div class="price_content">
<div class="cart-subtotals">

</div>
<div class="cart-total price_inline">
<span class="label"># Items</span>
<span class="value">12</span>
</div>
</div>
<div class="checkout text-center">
<a href="checkout.html" class="main-btn">Send RFQ</a>
</div>
</div>
-->
</div>
</div> <!-- header search cart -->
</div>
</div> <!-- row -->
</div> <!-- container -->
</div> <!-- header middle -->

<div class="header-menu">
<div class="container-fluid custom-container">
<div class="row">
<div class="col-lg-3">
<div class="header-menu-vertical">
<h4 class="menu-title">
<span>Parts by</span>
Category
</h4>
<ul class="menu-content menu-expand">
<li class="menu-item">
<a href="products.html?cat=semiconductor">Semiconductor </a>

</li>
<li class="menu-item">
<a href="products.html?cat=semiconductor">Passives </a>

</li>
<li class="menu-item"><a href="products.html?cat=semiconductor">ElectroMechanical</a></li>
<li class="menu-item"><a href="products.html?cat=semiconductor">Power & Circuit</a></li>
<li class="menu-item"><a href="products.html?cat=semiconductor">Automation</a></li>
<li class="menu-item"><a href="products.html?cat=semiconductor">Connectors</a></li>
<li class="menu-item"><a href="products.html?cat=semiconductor">Cables & Wires</a></li>
<li class="menu-item"><a href="products.html?cat=semiconductor">Test</a></li>

</ul> <!-- menu content -->
</div> <!-- header menu vertical -->
</div>
<div class="col-lg-9 position-static">
<div class="header-horizontal-menu">
<ul class="menu-content">
<li class="active"><a href="index.html">Home </a>

</li> <li class="position-static"><a href="products.html?cat=all">Products <i class="fal fa-chevron-down"></i></a>
<ul class="mega-sub-menu d-flex flex-wrap">
<li>
<a class="menu-title" href="#">Shop Grid</a>
<ul class="submenu-item">
<li><a href="shop-3-column.html">Shop Grid Column 3</a></li>
<li><a href="shop-4-column.html">Shop Grid Column 4</a></li>
<li><a href="shop-left-sidebar.html">Shop Grid left sidebar</a></li>
<li><a href="shop-right-sidebar.html">Shop Grid Right sidebar</a></li>
</ul>
</li>
<li>
<a class="menu-title" href="#">Shop List</a>
<ul class="submenu-item">
<li><a href="shop-list.html">Shop List</a></li>
<li><a href="shop-list-left-sidebar.html">Shop List Left sidebar</a></li>
<li><a href="shop-list-right-sidebar.html">Shop List Right sidebar</a></li>
</ul>
</li>
<li>
<a class="menu-title" href="#">Shop Single</a>
<ul class="submenu-item">
<li><a href="single-product.html">Shop Single</a></li>
<li><a href="single-product-variable.html">Shop Variable</a></li>
<li><a href="single-product-affiliate.html">Shop Affiliate</a></li>
<li><a href="single-product-group.html">Shop Group</a></li>
<li><a href="single-product-tabstyle2.html">Shop Tabs 2</a></li>
<li><a href="single-product-tabstyle3.html">Shop Tabs 3</a></li>
</ul>
</li>
<li>
<a class="menu-title" href="#">Shop Single</a>
<ul class="submenu-item">
<li><a href="single-product-slider.html">Shop Slider</a></li>
<li><a href="single-product-gallery-left.html">Shop Gallery Left sidebar</a></li>
<li><a href="single-product-gallery-right.html">Shop Gallery Right sidebar</a></li>
<li><a href="single-product-sticky-left.html">Shop Sticky Left sidebar</a></li>
<li><a href="single-product-sticky-right.html">Shop Sticky Right sidebar</a></li>
</ul>
</li>
<li class="custom-banner">
<a href="shop-4-column.html"><img src="images/custom_banner.jpg" alt="" class="img-responsive"></a>
</li>
</ul>
</li>

<li><a href="#">Services <i class="fal fa-chevron-down"></i></a>
<ul class="sub-menu">
<li><a href="about.html">About</a></li>

</ul>
</li>


<li><a href="#">Resources <i class="fal fa-chevron-down"></i></a>
<ul class="sub-menu">
<li><a href="#">BOM Upload Tool</a></li>
<li><a href="#">Global Learning Lab</a></li>
<li><a href="#">Product Advisor</a></li>
<li><a href="#">Articles</a></li>
</ul>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div> <!-- header horizontal menu -->
</div>
</div> <!-- row -->
</div> <!-- container -->
</div> <!-- header menu -->
</div> <!-- desktop nav -->

<div class="mobile-nav d-lg-none">
<div class="container-fluid">
<div class="mobile-nav-top">
<div class="row align-items-center">
<div class="col-sm-4 col-3">
<div class="mobile-toggle">
<a class="mobile-menu-open" href="javascript:;"><i class="fal fa-bars"></i></a>
</div>
</div>
<div class="col-sm-4 col-5">
<div class="mobile-logo text-center">
<a href="index.html">
<img src="images/logo-white.png" alt="Logo">
</a>
</div> <!-- mobile logo -->
</div>
<div class="col-sm-4 col-4">
<div class="mobile-account-cart">
<ul class="account-cart text-right">
<li>
<div class="dropdown">
<button type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fal fa-user"></i></button>

<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li><a href="#">My account</a></li>
<li><a href="#">Checkout</a></li>
<li><a href="#">Sign in</a></li>
</ul>
</div>
</li>
<li class="header-cart">
<a href="#">
<i class="fal fa-envelope-open-dollar"></i>
<span>0</span>
</a>
<div class="mini-cart">
<ul class="cart-items">
<li>
<div class="single-cart-item d-flex">
<div class="cart-item-thumb">
<a href="single-product.html"><img src="images/cart-1.jpg" alt="product"></a>
<span class="product-quantity">1x</span>
</div>
<div class="cart-item-content media-body">
<h5 class="product-name"><a href="single-product.html">New Balance Fresh Foam LAZR</a></h5>
<span class="product-price">€18.90</span>
<span class="product-color"><strong>Color:</strong> White</span>
<a href="#" class="product-close"><i class="fal fa-times"></i></a>
</div>
</div>
</li>
<li>
<div class="single-cart-item d-flex">
<div class="cart-item-thumb">
<a href="single-product.html"><img src="images/cart-2.jpg" alt="product"></a>
<span class="product-quantity">3x</span>
</div>
<div class="cart-item-content media-body">
<h5 class="product-name"><a href="single-product.html">New Balance Fresh Foam LAZR</a></h5>
<span class="product-price">€18.90</span>
<span class="product-color"><strong>Color:</strong> White</span>
<a href="#" class="product-close"><i class="fal fa-times"></i></a>
</div>
</div>
</li>
</ul>
<div class="price_content">
<div class="cart-subtotals">
<div class="products price_inline">
<span class="label">Subtotal</span>
<span class="value">€30.80</span>
</div>
<div class="shipping price_inline">
<span class="label">Shipping</span>
<span class="value">€7.00</span>
</div>
<div class="tax price_inline">
<span class="label">Taxes</span>
<span class="value">€0.00</span>
</div>
</div>
<div class="cart-total price_inline">
<span class="label">Total</span>
<span class="value">€37.80</span>
</div>
</div> <!-- price content -->
<div class="checkout text-center">
<a href="checkout.html" class="main-btn">Checkout</a>
</div>
</div> <!-- mini cart -->
</li>
</ul>
</div>
</div>
</div> <!-- row -->
</div> <!-- mobile nav top -->

<div class="header-search">
<form action="#">
<div class="search-category">
<select>
<option value="0">All categories</option>
<option value="12">Laptop</option>
<option value="13">- - Hot Categories</option>
<option value="19">- - - - Dresses</option>
<option value="20">- - - - Jackets &amp; Coats</option>
<option value="21">- - - - Sweaters</option>
<option value="22">- - - - Jeans</option>
<option value="23">- - - - Blouses &amp; Shirts</option>

</select>
</div>
<input type="text" placeholder="Enter your search key ... ">
<button><i class="icon ion-android-search"></i></button>
</form>
</div>
</div> <!-- container -->

<div class="mobile-off-canvas-menu">
<div class="mobile-canvas-menu-top">
<ul class="menu-nav">
<li><a href="compare.html"><i class="fal fa-repeat"></i> Compare (0)</a></li>
<h6 class="custom-title">Women is Clothes &amp; Fashion</h6>
<p>Shop women is clothing and accessories and get inspired by the latest fashion trends.</p>
</div>
</div>
<div class="col-lg-4 col-md-12">
<div class="menu-block">
<h6 class="custom-title">Simple Style</h6>
<p>A new flattering style with all the comfort of our linen.</p>
</div>
</div>
<div class="col-lg-4 col-md-12">
<div class="menu-block">


</ul>
</li>
<li class="menu-item-has-children">
<a href="#"><span>Outerwear & Jackets</span></a>

<li><a href="shop-left-sidebar.html">Bags & Cases</a></li>

</ul> <!-- menu content -->
</div> <!-- mobile main menu -->
</div> <!-- mobile off canvas menu -->
<div class="overlay"></div>
</div> <!-- mobile nav -->
</header>

CSS

/*===== header 3 =====*/
.header-3 {
background-color: #1c2454; }
.header-3 .header-nav {
background-color: #000;
border-bottom: 0; }
.header-3 .header-nav .header-nav-wrapper .header-static-nav p {
color: #fff; }
.header-3 .header-nav .header-nav-wrapper .header-static-nav p .text {
color: #fff; }
.header-3 .header-nav .header-nav-wrapper .header-menu-nav .menu-nav li + li {
margin-left: 30px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.header-3 .header-nav .header-nav-wrapper .header-menu-nav .menu-nav li + li {
margin-left: 20px; } }
.header-3 .header-nav .header-nav-wrapper .header-menu-nav .menu-nav li + li::before {
color: rgba(255, 255, 255, 0.4); }
.header-3 .header-nav .header-nav-wrapper .header-menu-nav .menu-nav li a {
color: #fff; }
.header-3 .header-nav .header-nav-wrapper .header-menu-nav .menu-nav li .dropdown button {
color: #fff; }
.header-3 .header-contact i {
color: #fff; }
.header-3 .header-contact .phone p {
color: #fff; }
.header-3 .mobile-toggle a {
color: #fff; }
.header-3 .mobile-account-cart .account-cart li .dropdown button {
color: #fff; }
.header-3 .mobile-account-cart .account-cart li .dropdown button i {
font-size: 24px; }
.header-3 .mobile-account-cart .account-cart li a {
color: #fff; }
.header-3 .header-menu {
background-color: #1c2454;
border-top: 1px solid rgba(255, 255, 255, 0.4); }
.header-3 .header-menu.sticky {
border-top: 0; }

我继承了这个元素,HTML是从一些模板公司购买的。我没有编写 HTML - 所以任何帮助将不胜感激。

谢谢。

最佳答案

粘性位置需要空间,为了让它工作,.header-area 类需要粘性。仅将此规则添加到您的媒体查询中!我刚刚试过了,粘性位置是这样工作的:

.header-area {
position: sticky;
top: 0;
z-index: 9999;
}

关于html - 如何使标题在手机上保持粘性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63443350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com