AlexStan0
AlexStan0

Reputation: 45

Why will my image not move when using CSS

I was trying to make a website where the text would be next to the image and to do that I need to move the image to the right and it would not let me no matter what I did. I tried all sorts of methods such as floating to the right and many other methods but none of them worked. Could anyone help?

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">

Upvotes: 2

Views: 122

Answers (1)

en0ndev
en0ndev

Reputation: 692

You should flex, with 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>

Upvotes: 3

Related Questions