CSS border - but width limited to text - width

I'm currently developing a site which requires headings as such:
My initial idea was to do this with border-bottom, but how would I limit the width of the border so that it doesn't go all the way across? The border needs to stop when it gets to the text.
Is this possible?

h1 {
background-color: #fff;
line-height: 1;
margin: 0;
display: inline;
position:relative;
z-index: 1;
}
h1:after {
content: '';
display: block;
border-bottom: 2px solid;
position: relative;
z-index: 0;
margin-top: -7px;
}

The length of the border is decided by the size of the element it is bordering. You could create another <div> inline with the text with border-bottom: 1px; and the other borders set to 0. You could then change the margin or width of the <div> to alter the length of the line. Note that you'd have to set a width, because an empty <div> has a width of 0 by default, so won't display.
Another possible (but not recommended) way to do it would be to use a <hr> but these are not well supported in HTML 5, so I would choose the first method personally.

A solution I can come up with is to give the title the same background-color as the page's background, and then to either transform: scale() the title up so that it overflows with the border of its parent, either scale the parent down so that its border hides behind the title's background.
See here for an example:
http://jsfiddle.net/WjRqC/1/
Oh, also, scaling can be replaced by making the title position: relative and moving it downwards a few pixels (and giving it a bit more vertical padding if you don't want the text too close to the line). Actually this is probably a better idea than scaling, because it's not CSS3, so it's more compatible.
Lookie here:
http://jsfiddle.net/7affw/1/

Related

How to make the top image url align center instead of shifting to the left in this code?

When I use this code on forums the top image(background) always shifts left instead of staying centered. The bottom image(floating text) works as is.
<div style="background-image: url('https://i.ibb.co/TmkSL8m/bg7.jpg'); color: #000000; background-color: #000000; background-attachment: fixed; text-align: center;"><img src="https://i.ibb.co/L6zQY0S/name96.png" /></div>
tried setting the width to auto but it locks the background image in place and doesn't allow the text to float over it.

Non-react-leaflet overlay on map

just getting started on react-leaflet and leaflet. After clicking on a marker I want to have a full screen overlay above the map to display a graph. But no matter how I set z-index of the and , the overlay always lies below the map.
Couldn't find an answer as most z-index question apply to map layers etc. within the component.
.overlay-wrapper {
position: fixed;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0,0,0,0.5);
z-index: 200;
cursor: pointer;}
It should be pretty straight forward, please point me in the right direction.
As #andreasgroos mentioned in their comment, the z-index value needs to be high enough, i.e. 401 or higher. z-index: "2000 !important" should guarantee that the component will be rendered over the map.

Make text fit in table cell when scaling, adapting font-size

I have a table which adapts its total width when the width of the screen is changed. Unfortunately this results in text overflowing the table cell because it's too large. I have tried the vw and vh units but that makes the text too small too fast. It should "just fit" in the table cell.
Do you have any ideas how that's possible or thoughts about how I possibly can change my table to function better?
<div id="fit">
<div>some text</div>
</div>
With a fixed size
#fitin {
width: 300px;
height: 100px;
border: 1px solid black;
overflow: hidden;
font-size: 1em;
}
This JavaScript will do the job.
$(function() {
while( $('#fitin div').height() > $('#fitin').height() ) {
$('#fitin div').css('font-size', (parseInt($('#fitin div').css('font-size')) - 1) + "px" );
}
});
FitText is an easy solution if it's a good fit for your project, here's a working example
http://codepen.io/panchroma/pen/lDBvc
Sometimes you have to play with the compressor setting to tweak the results for the specifics of your text and the space available ( eg ....fitText(1.2))
Hoe this helps!

Trying to turn long title in to ellipsis on responsive design

I'm designing a responsive web app, and I'd like to encapsulate long text in the title with an ellipsis. How can I do this? It's a responsive page (no fixed-width)...
Here is an example
Can anyone help?
Edit:
I added a max-width and an ellipsis overflow like this:
max-width: 200px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
But this won't work for me because the key here is responsiveness. I don't to target the max-width of the title specifically for iOS mobile browsers, I want the max-width to enlarge or reduce on all smart phones. Any suggestions?
Who knew that you could handle this in straight CSS? I was surprised, but check out the text-overflow property. One of the possible values is ellipsis! https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow
See the fiddle: http://jsfiddle.net/PdRqB/
You need to add three properties to the title:
.title {
width: 100px; /* Need to specify a width (can be any unit). overflow: hidden does nothing unless the width of .title is less than the width of the containing content */
overflow: hidden; /* to hide anything that doesn't fit in the containing element. */
white-space: nowrap; /* to make sure the line doesn't break when it is longer than the containing div. */
text-overflow: ellipsis; /* to do what you want. */
}
One cool part is, no media queries necessary. It is responsive already (try resizing the pane in the fiddle).
Update:
Just saw your update...
Your containing element's width can be set to a percentage, even 100%. Then, overflow: hidden and white-space: nowrap can do their magic on the child title element.
For some reason using text-overflow: ellipsis doesn't work unless you specify fixed width to the element or its parent.
Apply the below style to your text element and wrap that element in a container whose width is 100%.
{
overflow: hidden;
text-overflow: ellipsis;
white-space: initial;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}

Overlaying opaque image over background

I am quite new to XHTML/CSS, but have now got my site laid out nicely. Just one loose end which I can't seem to get past (I've spent a fair bit of time on this & found related info, but nothing quite the same):
All I want to do is overlay a faint image on my background. I don't want to use the "opaque" filters, as they trigger the script security alert on my IE Explorer 8.
I am quite happy to use the opaque gif image I have created.
I can see that z-index is the way to go. However, my image area insists on locating further down the page rather than overlaying.
Here's what I think are the key extracts of the code where I am going wrong [I have snipped detail such as fonts]:
HTML:
body { position:relative; z-index:1;
margin: 0 20px 0 0;
padding: 0;
background: #FFFFFF url(images/ge01.jpg) repeat-y;[snip]}
<div id="transparency">
</div>
CSS:
#transparency {
url(images/transparency.jpg) no-repeat;
width:230px;
height: 1000px;
position: relative; top: 80px; left:0;
z-index:2;
}
Have you tried using position: absolute; on your transparency element?
position: relative means that you will position the transparent element in relation to other content.

Resources