Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Allow padding of child element to go out of parent

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

You don’t want the paragraph auto layout so make it a div then just give the parent a negative top margin margin-top: -0.75rem;.
This can probably be cleaned up a bit overall .

Borders added to show what is where only.

#container * {
  border: dotted red 1px;
}

#container {
  width: 200px;
}

#label {
  margin: 0;
  padding: 0;
}

#parent {
  display: flex;
  margin-top: -0.75rem;
  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">
    <div id="url">Sample URL</div>
    <button id="clipboard">Clipboard Icon</button>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading