I have the following:
#container {
width: 200px;
}
#label {
margin: 0;
padding: 0;
}
#parent {
display: flex;
margin: 0;
padding: 0;
}
#url {
margin: auto 0px;
display: inline-block;
overflow: hidden;
flex-grow: 1;
font-size: 14px;
text-align: left;
white-space: nowrap;
text-overflow: ellipsis;
}
#clipboard {
padding: 12px;
flex-grow: 0;
}
<div id="container">
<span id="label">Label</span>
<div id="parent">
<p id="url">Sample URL</p>
<button id="clipboard">Clipboard Icon</button>
</div>
</div>
I’m trying to allow the padding of the clipboard button
to flow out of its parent container, so there isn’t a space between the Label
and Sample URL
. If I use relative positioning to push the clipboard button
upwards, the icon won’t be centered with the Sample URL
text.
I’m trying to get something like this (no space between the Label
and Sample URL
), but with the clipboard button
aligned to the Sample URL
2
Answers
I think your best bet will be something like what I have below. Most importantly, you shouldn’t try to put your
button
and<p>
in the same parent div, if you don’t really want them aligned with one another. Code below usesmargin: auto
for the top and bottom margin of the button, vertically centering it in the#container
. The height of the container is governed only by the sizes of the two pieces of text, so it will grow and shrink if you change font sizes or paddings or whatever.You don’t want the paragraph auto layout so make it a
div
then just give the parent a negative top marginmargin-top: -0.75rem;
.This can probably be cleaned up a bit overall .
Borders added to show what is where only.