使用 MaterializeCSS 居中图像的问题

如何解决使用 MaterializeCSS 居中图像的问题

我正在制作一个网站作为学校项目,并且添加了一张无法居中图片。我已经尝试了 10 多种将其居中的方法,但没有任何效果。它只是停留在屏幕的左侧。我正在使用 Materialise CSS。所有的 HTML 和 CSS 都在下面。附注如何将相同的图片添加到导航栏以使其适合?我尝试了几种方法,但没有奏效。

nav {
    background-color: #271675 !important;
}

.naw-wrapper {
    position: sticky;
    z-index: 1;
}

.buttons {
    margin-top: 15vh;
    opacity: 0;
    transition: .5s ease-in-out;
}

.title {
    color: #543cc0 !important;
    font-size: 40px;
    font-weight: 500;
    font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Open Sans','Helvetica Neue',sans-serif;
    margin-top: 2vh;
}

p {
    color: #646464;
}

.text {
    font-size: 25px;
    font-family: -apple-system,sans-serif;
}

.btn {
    font-size: 25px !important;
    margin: 5px;
    font-family: -apple-system,sans-serif;
    border-radius: 7px;
}

.buildGuide {
    margin-top: 20vh;
}

.buttons .text {
    margin: 3vh;
    margin-left: 10vw;
    margin-right: 10vw;
}

img {
    display: block;
    margin: 0 !important;
    padding: 0 !important;
}

.modal-content .title {
    margin: 0;
}

.buttons .title {
    font-family: 'Courier Prime',monospace;
}

.components {
    margin-bottom: 15vh;
}

.left-arrow,.right-arrow {
    border-radius: 100%;
    color: white;
    background-color: #543cc0;
    padding: 0;
    margin: 5vh;
}

.left-arrow {
    float: right;
}

.right-arrow {
    float: left;
}

.carousel {
    margin-bottom: 0;
    padding-bottom: 0;
    margin-top: 0;
    padding-top: 0;
    height: 30vh;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <!--CSS and Meta tags-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="main.css">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <Meta charset="UTF-8">
    <Meta http-equiv="X-UA-Compatible" content="IE=edge">
    <Meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>PC Configurator | Home</title>

</head>

<body>
    <!--Navbar-->
    <nav>
        <div class="nav-wrapper">
            <a class="brand-logo">PCC</a>
        </div>
    </nav>

    <!--Top text and buttons-->
    <div class="row buttons" id="topText">
        <div class="col s12 m12 l12 center-align">
            <img class="responsive-img" src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\logo.png">
            <p class="text flow-text">PC Configurator is a webiste designed to make PC building easy and accessible to
                everyone.
                We have a selection of PC building guides and tools at your disposal. The best part - it's totally
                free!</p>
            <a href="#" class="btn deep-purple darken-4 waves-effect flow-text">Build a PC<i
                    class="material-icons right flow-text">build</i></a>
            <p class="text">OR</p>
            <a href="#" class="btn deep-purple darken-4 waves-effect flow-text">Auto Builder<i
                    class="material-icons right flow-text">edit</i></a>
        </div>
    </div>

    <!--Building guide-->
    <div class="buildGuide row">
        <div class="col s12 m12 l12 center-align">
            <p class="title flow-text">Choosing the right components</p>
            <p class="text flow-text">Choosing the right components for your brand new PC can be hard,especially if you
                kNow nothing about PCs. In this guide,we will show you all you need to kNow about PC components. Simply
                click on one of the components to learn about it.</p>
        </div>
    </div>
    <!--Carousel-->
    <div class="carousel components center-align">
        <div class="carousel-item col s12 m6 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#cpuModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\cpu.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item col s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#gpuModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\gpu.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item col s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#mbModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\mb.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item col s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#ramModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\ram.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item col s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#storageModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\storage.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item col s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#psuModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\psu.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item col s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#caseModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\case.png" class="responsive-img">
            </a>
        </div>
        <div class="carousel-item cl s12 m12 l3 center-align">
            <a class="waves-effect waves-light modal-trigger title flow-text" href="#coolingModal">
                <img src="C:\Users\Jakov\Desktop\edit\zadnjiProjekt\resources\cooling.png" class="responsive-img">
            </a>
        </div>
    </div>
    <div class="row center-align">
        <div class="col s6 m6 l6">
            <i class="small material-icons flow-text center-align left-arrow" id="prev">keyboard_arrow_left</i>
        </div>
        <div class="col s6 m6 l6">
            <i class="small material-icons flow-text center-align right-arrow" id="next">keyboard_arrow_right</i>
        </div>
    </div>
    <!--Modals-->
    <div>
        <!--cpu-->
        <div id="cpuModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Processor</p>
                <p class="text flow-text">The processor,also kNow as the <b>cpu</b>,is the brain of your computer.
                    It does
                    all of the calculations and operations you throw at it. There are only two processor brands.
                    <b>Intel</b> and <b>AMD</b>. While both of them make good processors,Intel is better for
                    gaming,while
                    AMD is better for workstations. You should spend between 20% and 30% of your budget on your
                    processor.
                </p>
            </div>
        </div>
        <!--GPU-->
        <div id="gpuModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Graphics card</p>
                <p class="text flow-text">The graphics card,also kNown as the <b>GPU</b>,is probably the most
                    important
                    component if you are want a gaming or workstation based PC. There are two graphics card chip
                    makers:
                    <b>Nvidia</b> and <b>AMD</b>. There are also a lot of 3rd party brands that use those chips and
                    just
                    make the rest of the graphics card. Those are the ones you will most likely find,as the
                    so-called
                    <b>"founder's edition"</b> graphics cards(that are entirely 1st party) are very rare. You should
                    spend
                    around 40% of your budget on your graphics card. Some processors have intergrated graphics,and
                    don't
                    need dedicated graphics cards. Those processors have a <b>G</b> at the end of their name(AMD) or
                    don't
                    have <b>K</b>,<b>X</b> or <b>F</b> at the end of their name(Intel).</p>
            </div>
        </div>
        <!--motherboard-->
        <div id="mbModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">motherboard</p>
                <p class="text flow-text">The motherboard makes all of your components communicate. Every component
                    is
                    plugged into it. They all differ mainly by their <b>chipset</b> and <b>socket</b>. Depending on
                    which
                    cpu you have,you will need a diffirent socket(<b>AM</b> for AMD and <b>LGA</b> for Intel). It
                    is
                    recommended that you spend less than your cpu on your motherboard. For most users,the
                    motherboard
                    features don't even matter.</p>
            </div>
        </div>
        <!--RAM-->
        <div id="ramModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Memory</p>
                <p class="text flow-text">Memory,also kNown as <b>RAM</b> is where all of your running apps are
                    stored.
                    Once you power off the computer,the memory get wiped clean. There are multiple aspects too look
                    for
                    when choosing memory.<br>
                    <b>Memory speed</b> measures how often your memory communicates with your cpu(measured in MHz).
                    AMD
                    cpus benefit much more from higher memory speed. It is recommended to have a memory speed of
                    3000MHz or
                    higher for AMD cpus.<br>
                    The <b>latency</b> or <b>CAS timing</b> is how much cycles it takes for your RAM to send data
                    requested
                    by the cpu. Generally,everything below <b>CL-20</b> is considered OK,and everything below
                    <b>CL-17</b>
                    is considered fast.<br>
                    The <b>number of memory sticks</b> affects your performance the most. It simply tells you how
                    many
                    sticks of RAM you are getting in the package. One is Ok for simple tasks,but having two or more
                    significantly increases performance,as long as you install them in <b>dual-channel mode</b>.
                    The
                    possible amount of ram sticks can be 1,2,4,8,16 and even 32. Most computers use 1-4 RAM
                    sticks since
                    that is what most motherboards support.<br>
                    The <b>capacity</b> of your RAM simply tells you how much <b>GB</b> of RAM you are getting. 4GB
                    is
                    enough for very slight tasks,8GB is enough for some gaming or every-day tasks,16GB is OK for
                    most
                    games and workstation applications while 32GB+ is only used in expensive beastly computers that
                    can
                    handle everything you throw at them.
                </p>
            </div>
        </div>
        <!--Storage-->
        <div id="storageModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Storage</p>
                <p class="text flow-text">The storage does what the name says - it stores all of your data,even
                    when
                    your
                    PC is off. There are 3
                    types of storage: <b>SSD</b>,<b>HDD</b> and <b>hybrid</b> drives. SSDs are the fastes of them
                    all
                    by a
                    lot. They don't have as much storage as the other parts and cost more. HDDs are the slowest but
                    they
                    have the most storage and cost the least. Hybrid drives or SSHDs are a hybrid of the two. They
                    are
                    faster than HDDs but slower than SSDs but have more storage than SSDs. Their cost is somewhere
                    inbewteen
                    the two. There are mulpitle for factor: <b>3.5"</b>(HDDs and SSHDs),<b>2.5"</b>(SSDs),<b>M.2</b>(SSDs),and <b>PCIe</b>(SSDs).</p>
            </div>
        </div>
        <!--PSU-->
        <div id="psuModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Power supply</p>
                <p class="text flow-text">The power supply,or the <b>PSU</b> is responsible for powering your
                    system.
                    <b>Modular</b> PSUs have all the cables seperate,so you can only plug in the ones you need.
                    <b>Non-modular</b> PSUs have all the cables attached. It is important not to cheap out on your
                    PSU
                    and
                    only buy from trusted brands. Those brands are: <b>Corsair</b>,<b>Coolermaster</b>,<b>Asus</b>,<b>Gigabyte</b>,<b>Silverstone</b>,<b>be quiet!</b>,<b>Phanteks</b>,<b>Thermaltake</b>,<b>Seasonic</b> and <b>Fractal Design</b>. You should always get a PSU with more wattage than
                    you
                    need.
                    For example,if your system uses 400W you should get a 550W PSU. Better PSUs also have power
                    ratings.
                    These tell you how good their power efficiency is. They start with <b>80+</b> and go all the way
                    up
                    to
                    <b>80+ Platinum</b>.</p>
            </div>
        </div>
        <!--Case-->
        <div id="caseModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Case</p>
                <p class="text flow-text">The case houses all of your components. The only performance factor of
                    cases is their airloflow. Some come with preinstalled fans,more intake space and much more. The
                    case is often the cheapest part of any PC.</p>
            </div>
        </div>
        <!--Cooling-->
        <div id="coolingModal" class="modal">
            <div class="modal-content">
                <p class="title flow-text">Cooling</p>
                <p class="text flow-text">Most of your components need cooling. Some of them,like the cpu,GPU and
                    PSU usually come with one or more fans. But sometimes that is not enough,especially for more
                    powerful hardware. There are 3 types of coolers. <br><b>cpu coolers</b> cool the cpu. They can
                    be water coolers or air coolers.<br><b>GPU coolers</b> cool the GPU. Most GPUs come with
                    excelent air-cooling but you can step it up further with a custom water cooler.<br><b>Case
                        coolers</b> or <b>case fans</b> are as they sound - fans that are mounted inside the case
                    and help with the intake of cold air and with the exhaust of hot air.</p>
            </div>
        </div>
    </div>
    <!--Scripts-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
    <script src="main.js"></script>

</html>

The image I want to center

解决方法

首先,您应该添加徽标 img 标签,然后将导航栏显示为 flex。之后你可以使用 justify-content:center; .不要忘记在您的 css 样式中调整徽标尺寸

示例

nav {
    background-color: #271675 !important;
    justify-content: center;
    display: flex;
}

html 代码

    <!--Navbar-->
    <nav>
        <div class="nav-wrapper">
            <img class="pcclogo"src="https://i.ibb.co/mb1Mjqy/logo.png">
        </div>
    </nav>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?