CSS Cover link text with Image - html

<th>
My Heading
Sort Asc
</th>
I want to apply CSS to .sort-asc to replace the text "Sort Asc" with a custom 16x16 sort glyph image (/images/asc.png), placing the image directly to the right of the text. Is it possible?
NOTE: I can't change the markup. I can only apply styles; the following is my feeble attempt:
a.sort-asc {
float: left;
width: 16px;
height: 16px;
padding: 0;
margin: 5px;
display: block;
text-indent: -2000px;
overflow: hidden;
background: url("/images/asc.png") no-repeat;
}
Currently, the image shows up all the way to the left of the table header cell. I need it to the right of the text "My Heading".

a.sort-asc {
width: 16px;
height: 16px;
padding: 0;
display:inline-block;
text-indent: 200px;
overflow: hidden;
background: url("/favicon.ico") no-repeat;
}
Removed float - you don't need it, it's on the right position. Text indent does nothing with inline, try inline-block: http://jsbin.com/abeme
Another hack is to add color: transparent, and a small size, but that too hacky.

If you remove the display block, you won't be able to set your width, height or use text-indent to hide the copy within the A. Try changing display:block to display:inline (since you're floating) instead - it may give you what you need.

Remove float and display:block for the text to appear next to the "My Heading" text.

Related

Sort icon change place after click on column

css is in index.html
When I click on column for sorting data, sort icon change her place.
The icon should stay at the same place.
https://stackblitz.com/edit/angular-jwppgq-qfu2jh
How can I fix the problem?
edit your css styling like this (set text-align: center for centering the text horizontal, with a fixed width and line-height for "centering" vertical in your case):
th[sortable].desc:before, th[sortable].asc:before {
content: 'a';
display: inline-block;
width: 22px;
height: 22px;
float: right;
margin-right: 10px;
text-align: center;
line-height: 1.2;
}
notice that you have to adjust this styling, if you change the font-size (line-height) or you set a icon-font or whatever instead of a normal letter.

'Div' and 'Input' tag acting differently

I am making a search tool, and the search bar was originally a div, and everything was fine, but when I change it to input tags, the margin on the left disappears. Can someone please explain why this might be happening.
Here's my code (with header HTML removed for security reasons): http://jsfiddle.net/k3pv5cmh/
I have tried margin: auto, margin: 0 auto, and margin-left: auto with margin-right: auto. But none of these fix the problem.
On the JS Fiddle you can change the input tags to div tags and see the difference.
An input element is an inline element by default. A div is a block level element. So change your css to this:
#search-bar {
height: 50px;
width: 60%;
max-width: 800px;
background-color: white;
border: 2px solid rgb(230, 230, 230);
border-radius: 15px;
margin-right: auto;
margin-left: auto;
margin-top: 20%;
display:block;
}
Note: display:block;
Just add display: block; to your #search-bar definition. Input is basically line element, that means margin: auto; has no effect.
Inputs by default have style: display: inline-block;
Divs on the other hand, by default have style: display: block
The difference is in how much of container does each style takes.
You can see their differences here
If you want the same behaviour, you just have to put
style="display: block" in your input element and override its default style.
You can also add #container { text-align: center; } if you want to keep input tag inline. In this case you can get rid of left and right margins of input tag and put something next to it (may be button).

Collapsing margin alignment in Firefox

TLDR: this codepen works fine in Chrome, but the alignment is off in Firefox.
I'm building a jQuery plugin which modifies a text input to give it a dropdown button on the left. In order to get the positioning right, I add a wrapper div, which is the same height as the input, so the button can be absolutely positioned on top of the input, and yet still have the same height:
#wrapper {
position: relative;
}
#overlay {
position: absolute;
top: 0;
bottom: 0;
width: 30px;
}
This works fine until the input has vertical margin: then the container grows to include the margin, and so the dropdown button grows with it. My solution to this was margin collapsing: I gave the input display:block which meant that the container ignored it's margin. All good.
input {
margin: 20px 0 40px; /* testing */
display: block;
}
But now the problem is that by default, inputs are inline elements e.g. you might want to have a submit button next to the input. So I wrapped the whole thing in a container div with display:inline-block, so another inline element like a button can happily sit next to it.
#container {
display: inline-block;
}
This works fine in Chrome, but has weird alignment issues in Firefox when there's any vertical margin on the input. Below I've added the final markup. There's also a codepen link at the top.
<div id="container">
<div id="wrapper">
<input>
<div id="overlay"></div>
</div>
</div>
<button>Submit</button>
Edit: the point is that this is a plugin and I'm trying to work with the user's existing markup and CSS e.g. they have this markup:
<input><button>Submit</button>
and their existing CSS has vertical margin on the input, and I want them to be able to just initialise my plugin on the input and it just work, without forcing them to change their markup/CSS. Now because the plugin needs to add lots of markup around the input (for the overlay and the dropdown list), I wrap it all up in a container div. This container div is the limit of our reach (and does not include the button element, or anything else they choose to put next to their inputs).
To fix this, you'll need to define a line-height in your parent div#test2. Without it, different browsers will give it different values. This will cause Firefox to cause this weird result.
Now, the line-height isn't the only problem, also the vertical-align's baseline value will generate a different result for inline elements than it is for inline-block elements that have a different height than the surrounding inline content. To fix this, change the value to top for the #container element (since that's the inline-block element).
The final result would have the following changed (only pasting the parts that changed):
#test2 {
background-color: green;
line-height:70px;
#container {
// replicate the inline nature of the input
display: inline-block;
vertical-align:top;
}
//the rest of the #test2 nested code
}
That would look like this.
Reply to comment
I've made something that does work by the requirements set. Since you said the extra code (so the divs around the input) are made by the plugin itself, I've taken the liberty of changing that a bit to make this work.
The way it can work quite easily is just not using inline-blocks at all, and sticking with the inline elements. This would change the styles to the following:
#container {
// replicate the inline nature of the input
display: inline;
}
#wrapper {
display: inline;
position: relative;
}
input {
// you'll want to make sure the typed text doesn't appear behind the overlay
padding-left:35px;
}
#overlay {
position: absolute;
top: 0px;
bottom: 0px;
left: 1px;
width: 30px;
background-color: #00C2FF;
}
Notes:
I didn't bother making the overlay cover the full height of the input, since your plugin would just make it a flag anyway. To make it cover the full height, just set negative top and bottom styles on the overlay, equal to the computed padding-top and padding-bottom (resp.) on the input. In this case, you'd have to change them to top:-5px;bottom:-5px;. (you can get the computed style via jQuery's $(input).css('padding-top'))
You could actually also remove the whole #container from it, since the only style it has now is display:inline which really doesn't add anything to the whole thing.
I've added a padding-left to your input, because otherwise you'd have to type behind the overlay, which is just silly.
Is the HTML generated by the plugin and it needs to stay exactly the same? I'm not sure I can figure out exactly why the second example is not working, but you seem to have too many div elements there. You could make since simpler:
HTML
<div id="test1">
<div id="wrapper">
<input>
<div id="overlay"></div>
<button>submit</button>
</div>
</div>
SCSS
input, button {
border: 1px solid black;
padding: 5px;
}
input {
display: inline-block;
padding-left: 35px;
}
#test1 {
background-color: yellow;
padding: 20px 0 40px 0;
#wrapper {
position: relative;
#overlay {
position: absolute;
top: 1px;
left: 1px;
width: 30px;
background-color: #00C2FF;
}
}
}
Codepen example
I've removed the margin, and instead used padding on the parent, it achieves the same thing. You'll also want some padding-left on your input field so the entered text doesn't disappear behind your overlay div.
EDIT: In case you are unable to change the markup:
SCSS:
#test2 {
background-color: green;
#container {
// replicate the inline nature of the input
display: inline-block;
padding: 20px 0 40px 0;
}
#wrapper {
// this is just here to be display:block and ignore the margin on the input
display: block;
position: relative;
}
input {
// tell parent to ignore margin
//display: block;
margin: 0;
}
#overlay {
position: absolute;
top: 1px;
bottom: 1px;
left: 1px;
width: 30px;
background-color: #00C2FF;
}
}
codepen demo
Removed the block and margin declarations from the input field, and moved the spacing to padding of the #container element.
"Disclaimer": Let me just start by saying that I did not find exactly what is causing the problems in Firefox, but I did think of an alternative way you could do it.
The way this works in both Firefox and Chrome is just to use the exact same HTML as you used for your #test1, but on top of that, also using the CSS :before pseudo-element (instead of using the #container and #wrapper). The code I used was:
#test2 {
background-color: green;
position:relative;
&:before {
content:"";
display:block;
position:absolute;
left:1px;
top:1px;
bottom:1px;
margin:20px 0 40px 0;
width:30px;
background:#00C2FF;
}
}
demo
The way this works is to simply position the :before overlay on exactly the same place as the divs previously were. As you can see, I've used most of the same styles as you did, but instead, I've put them on the :before pseudo-class.
Other answers don't know why it doesn't work on Firefox. Well, I think that Firefox has the right behavior and it's a Chrome problem.
In short, you want to align an input with a button. But the input is inside a wrapper. Then, you can use vertical-align to control the vertical aligning between the wrapper and the button, but not between the input and the button.
Here you can see an screenshot with different vertical-align:
See the code.
If you want to align the input and the button (last case in the image), you have a problem, because any of the keywords you can use with vertical-align does that. Only in case that input's top margin and bottom margin are equal, then vertical-align: middle works.
But in general, you have have another solution: vertical-align also accepts a <length> value.
And, to get a perfect alignment, you should use the formula
vertical-align: -(input bottom margin)
Or, if you want to align them even if the button has a bottom margin, then
vertical-align: -(input bottom margin) + (button button margin)
The code formula above works with inline-block <div>, but not with <buttons>.
The formula must be fixed to
vertical-align: -(input bottom margin) -(input offsetHeight)/2 + 6
In your example
(Input bottom margin) = 40px
(Input offsetHeight) = 31px
Then, you need
vertical-align: -(input bottom margin) -(input offsetHeight)/2 + 6
Demo
I could achieve it with the following.Codepen You will have to know the css applied to input and apply it to button as well
button{
position:absolute;
margin-left:5px;
}
input, button {
display: inline-block;
margin: 20px 0 40px 0;
}
please update below in your code.
input, button {
border: 1px solid #000000;
margin: 20px 0 40px;
padding: 5px;
vertical-align: top;
}
hope it will work
http://codepen.io/anon/pen/Isycu

Text overflow in table with variable size

I was looking to implement the following design to the HTML/CSS.
I have got problems with the text overflow in the column. Currently the table column width is given in the percentage format so that the column width will change depending on the screen size, but there is a minimum width too. In the first text column, you can see that the content is extending and produced a second line due to the long size. How to avoid this problem using the text overflow? Or any other solution? Also, you can see that a set of icons are appearing in the same row when the mouse hover takes place. At this time, the text below the icons should hide and it should be shortened as shown in the design. Can you advise me to get a solution to this problem? I have tried text-overflow: ellipsis. But I'm getting problem when the screen width changes. Since I don't have a minimum width due to the variable column width, how to cut short the text in this field? Also in the hover case ??
Please let me know if you want to know anything else.
If you don't want the text to split in multiple rows, add white-space:nowrap rule.
Then, set a max-width for the cell.
For the icons, position them in absolute to the right, with a z-index higher then the text. You'll have to add a relative position to the containing cell also.
To keep them visible over text, i've added a background color (and some left padding).
EDIT: Fix for Mozilla
Mozilla seems to ignore position:relative; for td elements.
To fix it, you've to wrap the td contents inside another div, and apply this style
.tables td {
font-weight: 400;
font-size: 13px;
border-bottom: 1px solid #E1E1E1;
line-height: 38px;
text-align: right;
white-space: nowrap;
max-width: 200px; /* just an example */
}
.tables td > div {
overflow: hidden;
width:100%;
position: relative;
}
.linkFunctions {
display: none;
padding-top: 14px;
position: absolute;
right: 0;
z-index: 999;
background-color: #FFF9DC;
padding-left: 3px;
width: 100%;
max-width: 120px; /* just an example */
text-overflow: ellipsis;
overflow: hidden;
}
It's not exactly what you want (regarding the elipsis) but comes very close.
For the <a> inside the <td> add
td a{
display:block;
overflow:hidden;
width:100%;
white-space:nowrap;
}
(You might need to add a class to them to more easily target them and not ALL <a> inside <td>s).
And regarding the hover. Float the div.linkFunctions right, add the yellow background to it and it will look like it cuts the text accordingly.
All of those require a width to be set, which doesn't make tables fluid as they are intended to be. Use this: http://jsfiddle.net/maruxa1j/
That allows you to automatically set widths on <td> as percentages and the :after automatically sizes the overflowed <span>

position of text in a link displayed as block element

i want to know whats the best way to position text inside a block element.
foo
normal link but styled as display block with a background
display: block;
width: 100px;
height: 100px;
background: #000000;
the text now is top left.
now the question: what the best way to get this text to example: bottom-left or bottom-right?
i prefer CSS solution without any new elements inside the A-Tag. Some opinions?
You could also make use of display:table-cell - however, that won't work in <=IE7
http://jsfiddle.net/QU9gy/
you can't select content to sit along the bottom. By using padding (padding-top) you can manually make it look like ist's justified to the bottom.
so in the above example try
display: block;
width: 100px;
height: 14px;
background: #000000;
padding-top: 86px
You can try this too.
display: block;
width: 100px;
height: 100px;
background: #000000;
line-height:188px;
font-size:12px;
color:#fff;
text-decoration:none;
If you change your font-size than reduce than value from 200px :) means if you are using 18px font than line-height would be 182px so total no will be 200px;