Reputation: 23
I am trying to basically move what is circled in green to the box that is colored purple.
.counter {
margin-left: 20%;
margin-right: 20%;
width: 382px;
}
.counter-right {
margin-left: 60%;
text-align: right;
}
<div class="counter">
<img class="counter.img" src="https://via.placeholder.com/100" alt="Counter">
<div class="counter-right">
<h1>Counter</h1>
</div>
</div>
Upvotes: 1
Views: 1448
Reputation: 107
if you are not comfortable with display: flex
, here is another simple solution:
Use margin
and padding
for spacing as you desire.
.counter {
width: 100%;
}
.counter-left {
float: left;
}
.counter-right {
float: left;
/* border: 1px solid red; */
line-height: 10px;
padding-left: 10px;
}
<body>
<div class="counter">
<div class="counter-left">
<img class="counter.img" src="https://via.placeholder.com/300" alt="Counter">
</div>
<div class="counter-right">
<h1>Counter</h1>
</div>
</div>
</body>
Upvotes: 0
Reputation: 61063
Big margins aren't really a good way to lay things out. You should use inline-block display or flexbox.
.counter {
margin-left: 20%;
margin-right: 20%;
display: flex; /* defaults to "row" (horizontal orientation) */
background: #ddd;
}
.counter-left {
flex: 1; /* stretch to use all available space */
}
.counter-right {
flex: none; /* use only the space needed by contents */
background: pink;
}
<div class="counter">
<div class="counter-left">
<img class="counter.img" src="https://via.placeholder.com/100" alt="Counter">
</div>
<div class="counter-right">
<h1>Counter</h1>
</div>
</div>
Upvotes: 1