Adding vertical space below a element in a table












0















I have some fixed-width content I would like to put in a table header cell
with a little bubble around it to distinguish from non-fixed-width text.



The example below looks great except the bubble bottom covers up the cell border.



enter image description here



I would like to fix by moving the text up by 1, can't seem to figure it out; in effect, I think I want the baseline of the code.literal text to be 1-2px higher than the normal <th> baseline.



Is there a way to do this?






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>












share|improve this question


















  • 1





    If you add position: relative; top: -1px; to your code.literal rule it will jump up 1px

    – LGSon
    Nov 16 '18 at 21:42













  • You could also add bottom padding to your cells .table td, table th { padding-bottom: 1px; }

    – wahwahwah
    Nov 16 '18 at 21:44
















0















I have some fixed-width content I would like to put in a table header cell
with a little bubble around it to distinguish from non-fixed-width text.



The example below looks great except the bubble bottom covers up the cell border.



enter image description here



I would like to fix by moving the text up by 1, can't seem to figure it out; in effect, I think I want the baseline of the code.literal text to be 1-2px higher than the normal <th> baseline.



Is there a way to do this?






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>












share|improve this question


















  • 1





    If you add position: relative; top: -1px; to your code.literal rule it will jump up 1px

    – LGSon
    Nov 16 '18 at 21:42













  • You could also add bottom padding to your cells .table td, table th { padding-bottom: 1px; }

    – wahwahwah
    Nov 16 '18 at 21:44














0












0








0








I have some fixed-width content I would like to put in a table header cell
with a little bubble around it to distinguish from non-fixed-width text.



The example below looks great except the bubble bottom covers up the cell border.



enter image description here



I would like to fix by moving the text up by 1, can't seem to figure it out; in effect, I think I want the baseline of the code.literal text to be 1-2px higher than the normal <th> baseline.



Is there a way to do this?






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>












share|improve this question














I have some fixed-width content I would like to put in a table header cell
with a little bubble around it to distinguish from non-fixed-width text.



The example below looks great except the bubble bottom covers up the cell border.



enter image description here



I would like to fix by moving the text up by 1, can't seem to figure it out; in effect, I think I want the baseline of the code.literal text to be 1-2px higher than the normal <th> baseline.



Is there a way to do this?






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>








code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>





code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>






html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 21:38









Jason SJason S

107k135488820




107k135488820








  • 1





    If you add position: relative; top: -1px; to your code.literal rule it will jump up 1px

    – LGSon
    Nov 16 '18 at 21:42













  • You could also add bottom padding to your cells .table td, table th { padding-bottom: 1px; }

    – wahwahwah
    Nov 16 '18 at 21:44














  • 1





    If you add position: relative; top: -1px; to your code.literal rule it will jump up 1px

    – LGSon
    Nov 16 '18 at 21:42













  • You could also add bottom padding to your cells .table td, table th { padding-bottom: 1px; }

    – wahwahwah
    Nov 16 '18 at 21:44








1




1





If you add position: relative; top: -1px; to your code.literal rule it will jump up 1px

– LGSon
Nov 16 '18 at 21:42







If you add position: relative; top: -1px; to your code.literal rule it will jump up 1px

– LGSon
Nov 16 '18 at 21:42















You could also add bottom padding to your cells .table td, table th { padding-bottom: 1px; }

– wahwahwah
Nov 16 '18 at 21:44





You could also add bottom padding to your cells .table td, table th { padding-bottom: 1px; }

– wahwahwah
Nov 16 '18 at 21:44












1 Answer
1






active

oldest

votes


















1














If you add a display: inline-block; to your code.literal, the table will contain the element as a block level item instead. Which I think is what you are going for here.






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>








share|improve this answer
























  • thanks, that looks nice!

    – Jason S
    Nov 16 '18 at 21:47






  • 1





    @JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

    – LGSon
    Nov 16 '18 at 21:56













  • @JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

    – Temani Afif
    Nov 16 '18 at 22:04













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345771%2fadding-vertical-space-below-a-code-element-in-a-table%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you add a display: inline-block; to your code.literal, the table will contain the element as a block level item instead. Which I think is what you are going for here.






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>








share|improve this answer
























  • thanks, that looks nice!

    – Jason S
    Nov 16 '18 at 21:47






  • 1





    @JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

    – LGSon
    Nov 16 '18 at 21:56













  • @JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

    – Temani Afif
    Nov 16 '18 at 22:04


















1














If you add a display: inline-block; to your code.literal, the table will contain the element as a block level item instead. Which I think is what you are going for here.






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>








share|improve this answer
























  • thanks, that looks nice!

    – Jason S
    Nov 16 '18 at 21:47






  • 1





    @JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

    – LGSon
    Nov 16 '18 at 21:56













  • @JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

    – Temani Afif
    Nov 16 '18 at 22:04
















1












1








1







If you add a display: inline-block; to your code.literal, the table will contain the element as a block level item instead. Which I think is what you are going for here.






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>








share|improve this answer













If you add a display: inline-block; to your code.literal, the table will contain the element as a block level item instead. Which I think is what you are going for here.






code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>








code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>





code.literal {
background: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
padding: 1px 3px;
font-weight: normal;
font-family: Consolas,Menlo,"Liberation Mono",Courier,monospace;
display: inline-block;
}

th, td {
font-family: Arial, sans-serif;
}
.small {
font-size: 75%;
}

table {
border-collapse: collapse;
}
table td, table th {
border: 1px solid black;
padding-bottom: 0;
padding-top: 0;
}

<table>
<tr><th>Aluminum <code class="literal small">foo.bar.baz.quux</code></th>
<th>Barium <code class="literal small">jabberwocky</code></th>
</tr>
<tr><td>1</td><td>2</td></tr>
</table>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 21:45









brianespinosabrianespinosa

1,573716




1,573716













  • thanks, that looks nice!

    – Jason S
    Nov 16 '18 at 21:47






  • 1





    @JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

    – LGSon
    Nov 16 '18 at 21:56













  • @JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

    – Temani Afif
    Nov 16 '18 at 22:04





















  • thanks, that looks nice!

    – Jason S
    Nov 16 '18 at 21:47






  • 1





    @JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

    – LGSon
    Nov 16 '18 at 21:56













  • @JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

    – Temani Afif
    Nov 16 '18 at 22:04



















thanks, that looks nice!

– Jason S
Nov 16 '18 at 21:47





thanks, that looks nice!

– Jason S
Nov 16 '18 at 21:47




1




1





@JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

– LGSon
Nov 16 '18 at 21:56







@JasonS This is probably the better way to go, though it will keep both text at the same baseline, and if you still think you want the code.literal higher, the position: relative I suggested will solve that.

– LGSon
Nov 16 '18 at 21:56















@JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

– Temani Afif
Nov 16 '18 at 22:04







@JasonS worth to note that the issue here is the use of padding that is not considered when the element is inline by default, adding inline-block will make this padding to be considered and the element will remain an inline level element (not a block level one)

– Temani Afif
Nov 16 '18 at 22:04




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345771%2fadding-vertical-space-below-a-code-element-in-a-table%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini