gpt4 book ai didi

html - 为什么我的图像在使用 CSS 时不会移动

转载 作者:行者123 更新时间:2023-12-04 03:30:50 25 4
gpt4 key购买 nike

我试图制作一个网站,其中文本将位于图像旁边,为此我需要将图像向右移动,但无论我做什么,它都不会让我这样做。我尝试了各种方法,例如向右浮动等许多其他方法,但都没有用。谁能帮忙?

html,
body {
margin: 0 auto;
}

.header {
height: 4.6rem;
width: 100%;
background-color: #555555;
border-bottom: 1px solid black;
font-size: 0;
padding-left: 20px;
margin-bottom: 25px;
}

.btn {
background-color: #555555;
padding: 26px;
padding-right: 45px;
padding-left: 45px;
border: none;
margin: 0;
font-size: 1.2rem;
color: #F5F5F5;
font-family: Garamond, serif;
}

.btn:hover {
background-color: #696969;
}

.btn:active {
outline: none;
border: none;
}

.btn:focus {
outline: none;
border: none;
}

.title {
margin-left: 385px;
font-size: 2rem;
font-family: Garamond, serif;
}

.child {
position: relative;
float: right;
}
<div class="header">
<header>
<form target="_blank">
<input class="btn" type="submit" value="Home" id="button1" onclick="reloadWebpage()">
<input class="btn" type="submit" value="Processors" id="button2" action="">
<input class="btn" type="submit" value="Motherboards" id="button3" action="">
<input class="btn" type="submit" value="Graphics Cards" id="button4" action="">
<input class="btn" type="submit" value="Power Supplys" id="button5" action="">
</form>
</header>
</div>

<h1 class="title"> Personal Computers Technology </h1>

<img class="child" src="https://cdn.glitch.com/8282fc98-4236-406a-9a5e-f9535f41553b%2FPC.jpg?v=1604156880410" width="200" height="300">

最佳答案

你应该flex,使用justify-content:center;

html,
body {
margin: 0 auto;
}

.header {
height: 4.6rem;
width: 100%;
background-color: #555555;
border-bottom: 1px solid black;
font-size: 0;
padding-left: 20px;
margin-bottom: 25px;
}

.btn {
background-color: #555555;
padding: 26px;
padding-right: 45px;
padding-left: 45px;
border: none;
margin: 0;
font-size: 1.2rem;
color: #F5F5F5;
font-family: Garamond, serif;
}

.btn:hover {
background-color: #696969;
}

.btn:active {
outline: none;
border: none;
}

.btn:focus {
outline: none;
border: none;
}

.title {
font-size: 2rem;
font-family: Garamond, serif;
}

.child {
position: relative;
}

.container {
display:flex;
justify-content:center;
}
<div class="header">
<header>
<form target="_blank">
<input class="btn" type="submit" value="Home" id="button1" onclick="reloadWebpage()">
<input class="btn" type="submit" value="Processors" id="button2" action="">
<input class="btn" type="submit" value="Motherboards" id="button3" action="">
<input class="btn" type="submit" value="Graphics Cards" id="button4" action="">
<input class="btn" type="submit" value="Power Supplys" id="button5" action="">
</form>
</header>
</div>

<div class="container">

<h1 class="title"> Personal Computers Technology </h1>

<img class="child" src="https://cdn.glitch.com/8282fc98-4236-406a-9a5e-f9535f41553b%2FPC.jpg?v=1604156880410" width="200" height="300">

</div>

关于html - 为什么我的图像在使用 CSS 时不会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66846325/

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