Reputation: 13
I wanted to move an element up, I tried with margin-top, but it seems it doesn't work.
#nextquestion {
margin-left: 80%;
width: 15%;
background-color: #333333;
height: 40%;
color: white;
font-size: 20px;
border: none;
margin-top: 0.01%;
display: inline-block;
}
#question1 {
color: white;
margin-left: 2.5%;
font-size: 31px;
margin-top: 5%;
}
<div style="background-color: #161624; width: 100%; height: 20%; vertical-align: bottom ;">
<a href="#" id="question1" style="display: inline-block;">Question 1/X</a>
<button id="nextquestion">Next Question</button>
</div>
I have added display: inline-block, but it didn't change anything.
enter image description here Margin-top: -..., doesn't change a lot
Upvotes: 1
Views: 134
Reputation: 2297
Use flex and then align-self
:
*{
box-sizing: border-box;
}
#container{
background-color: #161624;
display: flex;
justify-content: space-between;
height: 100px;
align-items: center;
padding: 0 20px;
}
#container div:first-child{
width: 40%;
}
#container div:last-child{
width: 35%;
align-self: flex-start; /*here! remove this if you want placed in the center vertically.*/
}
#nextquestion {
background-color: #333333;
color: white;
font-size: 20px;
border: none;
padding: 10px;
}
#question1 {
color: white;
margin-left: 2.5%;
font-size: 31px;
margin-top: 5%;
text-decoration: none;
}
<div id="container">
<div><a href="#" id="question1">Question 1/X</a></div>
<div><button id="nextquestion">Next Question</button></div>
</div>
Upvotes: 0
Reputation: 16
You can fix it with this code :
div{
background-color: #161624;
width: 100%;
justify-content: space-between;
display: flex;
}
#question1 {
color: white;
margin: 40px;
font-size: 31px;
}
#nextquestion {
width: 15%;
background-color: #333333;
color: white;
font-size: 20px;
height: 44px;
border: none;
}
<div>
<a id="question1" style="display: inline-block;">Question 1/X</a>
<button id="nextquestion">Next Question</button>
</div>
Upvotes: 0
Reputation: 465
Try to add position & top.
add this in your code:
position: relative;
top: -36px;
Upvotes: 0
Reputation: 2036
That's not the right way to do it in my opinion. Using negative margins is not a good practice. I would instead use flex to achieve it:
#question-container {
background-color: #161624;
display: flex;
flex-direction: row;
height: 20%;
justify-content: space-between;
padding: 3rem;
}
#nextquestion {
width: 15%;
min-width: 120px;
background-color: #333333;
color: white;
font-size: 20px;
border: none;
}
#question1 {
color: white;
font-size: 31px;
}
<div id="question-container">
<a id="question1" style="display: inline-block;">Question 1/X</a>
<button id="nextquestion">Next Question</button>
</div>
Upvotes: 2