I cannot figure out how to align these three elements. I have this scheme:
<div class="main_box">
<span class="title">Title</span>
<p>Text goes here</p>
<a class="button" href="#">Button</a>
</div>
CSS is:
.title{
float:left;
display:inline-block;
}
p{
display: inline;
float: left;
width:100px;
}
.button{
display: inline;
float: right;
}
I put the width on p
, because it's width is the width of container (and I don't want that).
With this, the button (anchor) is aligned with the paragraph, but I'd like to center it more, somewhere between title and paragraph.
What am I doing wrong? :\\ Should I just use negative margin on the anchor?
EDIT: I wasn't clear enough, I need vertical alignment of these elements. I've figured out the problem. I can use negative margins.
I'm not sure what you're exactly going for but I think it's something like this:
You can change the width of the <p>
to whatever is appropriate!
Update your CSS like below.
.title{
float:left;
}
p{
float:left;
width:100px;
padding:0;
margin:0;
}
.button{
float:right;
}
Simply you can use here display: inline-block;
no need to use float
.title, p, .button{
display: inline-block;
vertical-align: middle;
}
p{
width:100px; /* you can add width if you want */
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.