HTML/Bootstrap Align variable elements in table - html

I'm stuck on a problem here where I need to align two elements (one's a <span> and the other's an <a>) horizontally in a table. The <span> works as an indenter as I'm trying to display a tree in a table. The problem now is that the button (<a>) has a variable length due to its text inside (when you click on the button you can edit the text) and the <span> has a variable length due to the number of parents of the button.
Whenever the text in the button gets too long it breaks into the line below the indenter.
Look at this fiddle:
<table style="width:70%;">
<tr>
<td>
<span class="indenter" style="width:120px;display:inline-block;">
<a>
</a>
</span>
<a href="#" class="btn">
text inside the a tag text inside the a tag
</a>
</td>
</tr>
</table>
I do not know the width of the indenter because it is calculated by some js plugin therefore calculating the width for the <a> tag with css does not work.
Furthermore I need the span to be always exactly the width it has so display: flex doesn't work either.
Do you have an idea on how to
Thank you!

Use display: tabel-cell for button and span
.indenter {
border: 1px solid black;
vertical-align: center;
}
.indenter a:after {
content:"-";
}
.btn {
display: tabel-cell;
color: #eb8b02;
border: 1px solid #ccc;
text-align: center;
padding: 4px 12px;
line-height: 20px;
vertical-align: middle;
cursor: pointer;
background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
border-radius: 4px;
text-decoration: none;
}
<table style="width:70%;">
<tr>
<td>
<span class="indenter" style="width:120px;display:tabel-cell;">
<a>
</a>
</span>
<a href="#" class="btn">
text inside the a tag text inside the a tag
</a>
</td>
</tr>
</table>

Related

CSS "hover" menu being hidden by other hover-able text

I'm working on a popup that appears when the user hovers over text. A portion of text can be hovered over, which will make a small box appear below it containing additional text that's normally hidden.
The issue arises when there's another hover-able text portion where the box would display - the box is hidden behind it.
The Fiddle: CSS Issue
.hovertext {
position: relative;
display: inline-block;
background: #CCEEFF;
padding: 4px 6px;
border-radius: 6px;
z-index: 1;
}
.hovertext .hovertexttext {
visibility: hidden;
background: #AAAAEE;
position: absolute;
white-space: pre-line;
padding: 4px 6px;
border-radius: 6px;
z-index: 2;
}
.hovertext:hover .hovertexttext {
visibility: visible;
}
<!-- this often happens on tables, where "hover" spots are below one another -->
<table>
<tr>
<td>
<div class="hovertext">
hover here to see the issue
<span class="hovertexttext">secret text!
more secret text!
even more secret text!
but you can't see all of it...
it's being blocked by the other element
</span>
</div>
</td>
</tr>
<tr>
<td>
<div class="hovertext">
i'm blocking the text aaaa
<span class="hovertexttext">oh no</span>
</div>
</td>
</tr>
</table>
I've tried:
Removing the position:absolute tag from hovertext - this causes the entire "invisible" text to hide in the same area as the rest, pushing the rest of my HTML around.
Removing position:relative tag in hovertexttext - HTML gets pushed around.
Adjusting the z-index values, as well as removing them completely - doesn't have noticeable effect.
Changing the <div> tags to <span>, and vice versa - doesn't have noticeable effect.
The hover menu is overlapping its parent div without any issues, so I'm led to believe it could overlap another <div> that's the same class, but I'm more or less stuck with how to proceed. Did I overlook something obvious?
You've got a few issues going on. Nested elements with conflicting indexes, display visible retains it's original sizing / nesting on the first measure arrange pass, and finally abusing box model semantic positioning. Hope this helps, cheers!
.hovertext {
background: #CCEEFF;
padding: 4px 6px;
border-radius: 6px;
cursor: help;
}
.hovertexttext {
display: none;
background: #AAAAEE;
position: absolute;
white-space: pre-line;
padding: 4px 6px;
border-radius: 6px;
}
.hovertext:hover .hovertexttext {
display: block;
}
<!-- this often happens on tables, where "hover" spots are below one another -->
<table>
<tr>
<td>
<div class="hovertext">
hover here to see the issue
<span class="hovertexttext">secret text!
more secret text!
even more secret text!
but you can't see all of it...
it's being blocked by the other element
</span>
</div>
</td>
</tr>
<tr>
<td>
<div class="hovertext">
i'm blocking the text aaaa
<span class="hovertexttext">oh no</span>
</div>
</td>
</tr>
</table>

Render a button like a couple of spans in CSS

I want to render a couple of submit buttons (they stands in the center of a paragraph, right under a form) exactly as in this html code:
span {
background-color: #cbaa5c;
padding: 4px;
color: #ffffff;
text-transform: uppercase;
}
<p style="text-align:center;">
<span>
<span style="border-right-width:2px; border-right-style:solid; border-right-color:#ffffff;">
Login
</span>
<span>
>
</span>
</span>
<span>
<span class='butleftspan' style="border-right-width:2px; border-right-style:solid; border-right-color:#ffffff;">
Register
</span>
<span>
>
</span>
</span>
</p>
The code above generate these two spans that are the result I aim to achieve:
This is exactly how I want that the two working buttons (and not only two spans) appear.
I tried to obtain the same result as in the picture and code above defining buttons,tables inside of buttons, spans an everything possible in the world, but I can't achieve my purpose. Any help will be super-appreciate! Thanks in advance!
In simple terms I'd want to have a Login and a register button that appears exactly as in the picture (that i obtained from the HTML code above).
As far I understand from your question you want the same result but using a button tag, in that case you can use ::after to insert the ">" symbol and achieve with CSS this:
p {
text-align: center;
}
button {
background: #cbaa5c;
border: none;
color: white;
line-height: 2;
padding: 0 8px;
}
button:after {
content: ">";
display: inline-block;
padding-left: 8px;
margin-left: 8px;
border-left: 1px solid white;
}
<p>
<button>LOGIN</button>
<button>REGISTER</button>
</p>

Why is my background color not filling all of my table?

I'm having a problem with an image within my table row. For some reason, the background color will not extend and fill the table row in when I have a picture floating to the left.
p.more {
color: rgb(255, 255, 255);
font-family: Arial;
font-size: 18px;
line-height: 140%;
margin: 0px;
text-align: center;
background-color: #cccccc;
}
img.more {
float: left !important;
margin: 0px 15px 15px 0px;
width: 330px;
}
span.more {
line-height: 100%;
text-align: center;
font-size: 18px;
}
span.moreweelove {
color: rgb(255, 255, 255);
}
<table>
<tr>
<td>
<p class="more">
<a href="http://blog.weespring.com/weelove-littlehipsqueaks-knotted-headbands/">
<img class="more" src="http://www.weespring.com/media/weelove_littlehipsqueeks.jpg">
</a>
<br>
<span class="more"><span class="moreweelove"><strong>Modern, Comfy, and Fun Staples</strong></span></span>
</p>
<p class="readmore">
<strong class="subheading">BIG LOVE FOR JUNE & JANUARY</strong>
<br>
<br>
<a href="http://blog.weespring.com/weelove-littlehipsqueaks-knotted-headbands/">
<img src="http://www.weespring.com/media/read-more.png">
</a>
<br>
<br>
</p>
</td>
</tr>
</table>
If want to fullfill an entire row with a background-color, youu should apply a css style to the corresponding < tr > tag.
Since you applied the background color the <p>, only the <p> itself will get colored. If the last line doesn't take up the full width of the container, e.g.
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxx
then only the parts with the x will get the background treatment. But if you apply the color to the containing <td>, which surrounds the paragraph, like so:
+------------------------+
|xxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxx |
+------------------------+
Then that final partial line will ALSO be colored, because the entire box of the <td> is colored, not just where the text is.
It's because you're giving style to "p.more" not to the table.
Try giving the background color to the table.

CSS padding overlapping parent element

My HTML:
<table style="width:100%;">
<tbody>
<tr style="cursor:pointer; border-bottom:1px solid #ACACAC; height:60px;">
<td style="text-align:right; vertical-align:middle; padding:10px 10px 10px 0px;">
<span style="color:#F87E20;">Copy</span>
<div style="display:inline; color:#ACACAC;"> | </div>
<span style="color:#F87E20;">Export</span>
<div style="display:inline; color:#ACACAC;"> | </div>
<span style="color:#F87E20;">Delete</span>
</td>
</tr>
</tbody>
</table>
The result:
This is all fine, and is working wonderfully. I want to make some QOL changes, though, and while looking into some of the changes I wanted to make, ran into something that is confusing me quite a bit.
The entire row is clickable, as well as the Copy, Export and Delete spans. This becomes a problem when I try to click on Export, but miss by 2 or 3 pixels, and instead navigate away from this area. I wanted to make the clickable area for the spans bigger, so I gave the a style property like so: padding:10px 0px 10px 0px;
The padding works as intended, enlarging the clickable area around the spans, making it easier to click on them. However, I was expecting the padding to also make the entire row taller, but instead it's as if the spans' padding is just flowing over the padding on the parent.
Here are some images to help explain the situation:
Parent:
And Child:
I don't understand why the child's padding is flowing outside it's container, and I don't want to go on in this direction without understanding what's going on. I was wondering if anyone could please help me understand what's happening here?
Your spans are inline elements. Top and bottom padding is ignored in case of inline elements.
By default, spans are inline, and divs are block. However, you can always override these with display: block; or display: inline;. Block elements (also inline-blocks) have full padding support.
See:
table {
width: 100%;
border-bottom: 1px solid #ACACAC;
}
tr {
cursor: pointer;
height: 60px;
}
td {
text-align: right;
vertical-align: middle;
padding: 10px 10px 10px 0px;
background-color: #e0c000;
}
span {
display: inline-block;
color: #F87E20;
background-color: #f0e000;
}
.padded {
padding: 10px 0 10px;
}
div {
display: inline;
color: #ACACAC;
}
<table>
<tbody>
<tr>
<td>
<span>Copy</span>
<div> | </div>
<span class="padded">Export</span>
<div> | </div>
<span>Delete</span>
</td>
</tr>
</tbody>
</table>
See also this article for more on this.

Vertical align text with a link inside a div block

Can't center text vertically with a link, this is my html code:
<div style="background: #F7C0B9;width: 645px;height: 70px;margin: 0 auto;outline: 1px solid #FFF;text-align: center;vertical-align: middle;line-height: 70px;">
<p style="">
Text <br />
<a href="#">
Link
</a>
</p>
</div>
I've tried to specify vertical align, to p tag, also tried line-height, but no success, link still is out of position.
jsfiddle : http://jsfiddle.net/85q6wqjx/
You can realize this layout as follows.
First, set display: inline-block to the p, that way you can align it with
the baseline of the content box.
Second, you need to reset the line-height within p to some reasonable
value to get the line spacing to look right.
Third, apply vertical-align: middle to the p element for it to have the
desired effect.
This approach will work with any number of text lines, as demonstrated.
See fiddle: http://jsfiddle.net/audetwebdesign/1mwkbr0q/
.panel {
background:#F7C0B9;
width:645px;
height:170px;
margin:0 auto;
outline:1px solid #FFF;
text-align:center;
line-height: 170px;
}
.panel p {
vertical-align: middle;
display: inline-block;
border: 1px dotted gray;
line-height: 1.25;
}
<div class="panel">
<p>Text<br /> Link<br>a 3rd line for example</p>
</div>
If you want the Link under the text but still both in middle:
<div style="background:#F7C0B9;width:645px;height:70px;margin:0 auto;outline:1px solid #FFF;text-align:center;vertical-align: middle;">
<p style="display:inline-block;">
Text <br />
<a href="#">
Link
</a>
</p>
</div>
JsFiddle
Your line-height was pushing it outside the div and the p being a block element was stopping it from going under. You needed to make p an inline-block element.
If you want them both on the same line, remove <br> from the html.
JsFiddle
br is a line break and line-height effects by that.
Please remove <br> tag you will get what you want
and update your code snippet with
<div style="background:#F7C0B9;width:645px;height:70px;margin:0 auto;outline:1px solid #FFF;text-align: center;padding: 17px 0;box-sizing: border-box;">
<p style="margin: 0;">Text</p>
Link
</div>
http://jsfiddle.net/85q6wqjx/10/
Just add following code to your css file
a {
margin-top: -8%;
display: block;
}
give class/id name to anchor tag if you want to add style particular anchor tag