I'm tryng to create a baloon as a hint on top of the word in text. The text inside the baloon would have some block layout, so I need to put this layout into a rectangular block and display it relative to the word of interest. I'm trying to define CSS styles for the internals of the baloon, but so far that doesn't work.
Here is an example of the text:
<p>Lorem ipsum dolor sit <span class="needs_hint">amet<span class="baloon">hint</span></span>, consectetur adipiscing elit.</p>
The word "amet" is the one I need the hint for, and I wrap it with an inline span. The staff needed for the hint is extracted into a nested span.
After applying the CSS below I have a hint floating on top of the word "amet", and that is expected and desired:
.needs_hint {
position: relative;
display: inline-block;
}
.baloon {
width: 200px;
position: absolute;
bottom: 125%;
left: -50%;
margin-left: -60px;
border-width: 1px;
border-style: solid;
}
Now I need to add text with more complex layout into the baloon. I'm replacing the word "hint" with a more complex html that contains a <div>:
<p>Lorem ipsum dolor sit <span class="needs_hint">amet<span class="baloon">inline hint<div class="hint">inline-block hint</div></span></span>, consectetur adipiscing elit.</p>
I'm defining the CSS for this <div> line that:
.hint {
position: relative;
display: inline-block;
}
This however extracts the "inline hint" inside the baloon, but leaves the "inline-block hint" part inside the text. What CSS would allow me to display some block html with divs, tables, etc?
I've found an ad hoc solution to my problem here: How to create a pure CSS tooltip with HTML content for inline elements.
The inner <span> has to be replaced with a <button>, as this is the only inline element that allows to contain block elements.
The solution is quite unusual and surprising to me, as <button> has very different semantics, so other solutions are welcome. I would also like to hear the justification for this usage of the button tag.
Related
I need some help here.
I am trying to achieve the following layout - a rectangular div containing text on the left and circular image on the right, similar to this (but reverse order). I'm also using Bootstrap for layout.
example
The issue with the solutions proposed on StackOverflow is that they require definining height and width of the circle and I need it to be responsive.
The closest was to use a radial gradient, however the cut out area from the rectangle did not have the same radius as the circle and the gap was too large.
This is what I've got so far:
<div class="cut-out-grid cut-out-grid--alt">
<div class="cut-out-grid__image-section">
<div class="image-rounded">
<div class="image-rounded__wrap">
<img class="image-rounded__image" src="/images/stock/dog.png">
</div>
</div>
</div>
<div class="cut-out-grid__text-section cut-out-grid__text-section--tertiary">
<div class="cut-out-grid__text">
<h3 class="feature-grid__title">lorem ipsum dolor sit amet.</h3>
<p>lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<span class="button-grid__item">
Lorem ipsum
</span>
</div>
</div>
</div>
</div>
And Sass:
.cut-out-grid {
#extend .row;
#extend .align-items-center;
&__image-section,
&__text-section {
#extend .col-6;
}
}
Any help will be appreciated, thanks! :)
Okay, so I actually ended up finding a solution myself by adding this:
&__image{
border-left: 1.2em #ffcd41 solid;
box-sizing: content-box;
position: absolute;
bottom: -210px;
left: -100px;
}
which seems to have done the trick.
The key was to focus on the image div, not text, as I wanted the cut out shape to be the same radius as the radius of the circle.
This is why previous solutions suggesting radial-gradient on Stack were not applicable in this case.
Box-sizing: content-box; was necessary to ensure the border does not eat into the image.
The border is what creates the cut-out effect. I was experimenting with padding on the image wrap before, but that did not achieve the effect I wanted and made the image smaller despite box-sizing: content-box added. I'm not entirely sure why and need to research this further.
Now I will focus on getting rid of the px values and adding necessary media queries.
Can anyone please point me out, or name some tecnhiques that may exist in order to achieve this effect, on a properly way:
Like this:
and again:
As you may notice, the point is to connect both lines. Some of those lines come from text boxes, that, since we wish to properly use EM unit for font-size, the box around the text, may change.
I have never done this before, I would appreciate any point outs, in order to investigate this "effect" further please.
Thanks in advance.
It doesn't matter if the fonts in the text boxes are in EM. If the font size change, the text boxes size will change, but that it doesn't mean that the space between them also has to change (it could has a fixed height -the background height-).
Here's a really basic example (try changing the body font-size):
<html>
<head>
<style>
body { font-size: 12px;}
.text { border: 1px solid #999; padding: 15px; font-size:1em; }
.line { background: url(http://www.agavegroup.com/images/articles/photoshopCurvedLine/curveFinal.gif) no-repeat center center; height: 50px; }
</style>
</head>
<body>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div class="line"></div>
<div class="text">
Eum, quis consequuntur culpa ex eius totam nemo.
</div>
</body>
</html>
If you do want the space between boxes height changing if the font-size change, you should set it height to EM and use a background images that's, lets say, doubled the container original height (so when the height change, more background it's revealed). You can see this changing height: 50px; to height: 7em; on the .line {} rule (the example image I've used it higher than the container).
This a really basic example. The markup depends on the design. If you need something more accurate (like: you need that the line starts and ends in specific spot), you should probably use absolute/relative positions.
Given the following HTML:
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
</p>
And the following CSS:
p {
border: 1px solid red;
width: 200px;
text-align: right;
white-space: nowrap;
}
What would the expected rendering be? I was expecting the text to butt up against the right hand side of the para and overflow off to the left. Observed results in Fx/Safari/Opera butt the text to the left and overflow to the right though. The same problem is observed with text-align:center; I’d expect the text to overflow equally to both sides.
CSS2.1 and CSS3 Text don’t seem to specify the rendering.
Test link: http://www.webdevout.net/test?0e&raw
I was able to get the result you were after using the direction property, e.g.
p {
direction: rtl;
border: 1px solid red;
width: 200px;
text-align: right;
white-space: nowrap;
}
That worked in current versions of Firefox, Safari and IE.
The "Inline Formatting Context" section of the CSS 2.1 spec says:
When the total width of the inline
boxes on a line is less than the width
of the line box containing them, their
horizontal distribution within the
line box is determined by the
'text-align' property. If that
property has the value 'justify', the
user agent may stretch spaces and
words in inline boxes (except for
inline-table and inline-block boxes)
as well.
When an inline box exceeds the width
of a line box, it is split into
several boxes and these boxes are
distributed across several line boxes.
If an inline box cannot be split
(e.g., if the inline box contains a
single character, or language specific
word breaking rules disallow a break
within the inline box, or if the
inline box is affected by a
white-space value of nowrap or pre),
then the inline box overflows the line
box.
So, the text-align property is only used in cases where the line box length is less than the block width. If the line box is wider than its containing element then the text-align property isn't considered.
You can create outside envelope container limiting size
and inner element showing content floated to right, like:
HTML:
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.</p>
</div>
CSS:
DIV {
width: 200px;
overflow: hidden;
border: 1px solid red;
}
P {
float: right;
white-space: nowrap;
}
In react to Olly Hodgson's idea:
direction: rtl;
is throwing interpunction from end of sentence (from right) as first char (to left) (Google Chrome v. 38)
Oh, I have encountered this before.
The align:right only affects the content within the box, any overflow is ALWAYS left aligned, only reversing the direction of the text with "direction" can change that.
I am sure sure if this is even possible due to the nature of CSS and being cascading, but I will try anyway.
I am creating a Terms and Conditions box which will contain some key elements that the user will select. Since the T&C's will have form components (radio buttons, check boxes). I don't really want to go through the trouble of putting it into an IFrame and getting the user input that way.
I figured using a with the overflow: auto property added, I could create an scrolling box with the T&C's and have the user select their options that way.
Well, because the T&C's have some mark up which would be directly affected by the sites css, I need to figure out a way to have this div not use the main CSS of the site.
Here is some sample code which would be similar to the approach I am trying:
<html>
<head>
<style>
div
{
border: solid 1px #000;
}
div small
{
font-size: 17pt;
}
</style>
</head>
<body>
<div style="overflow: auto; width: 500px; height: 300px;">
<small>This is small text</small>
<div>
<small>This is small text</small>
Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Donec vulputate mi sed nisl blandit sed porttitor massa fringilla.
</div>
</div>
</body>
</html>
The result of this is a pretty little black box with some text and then a sub box with more text and the key item in here is the text wrapped in <small/>.
Is there a way to have anything under a certain div NOT inherit the CSS? Maybe I need to take a completely different approach with this.
Thought? Ideas? Suggestions?
Thanks in advance!
Instead of working directly with tag names, keep two sets of classes ("inner" and "outer") and work with those.
So you can have a div.inner definition, and a div.outer definition, and work on them separately. The inner one would have to explicitly undo the settings outer has, though.
Something like
<div class="outer">
<div class="outer">Some content. <small>Small text.</small></div>
<div class="inner container">
<small>Blah blah blah</small>
More content
</div>
</div>
And in your CSS define whatever you need,
div.outer {
border: 1px solid black;
}
div.outer small {
font: 17pt;
}
div.inner {
border: none;
}
div.inner small {
font: 15pt;
}
div.container {
overflow: auto;
width: 500px;
height: 300px;
}
don't think there is a way to not inherit css. i think the only way is to 'reset' all the styles set on its parents explicitly. see eg http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ for a list of default properties.
There is, as second notes, no way to inherently prevent the cascade of styles, it's the cascade that defines CSS after all. So you are reduced to using the .inner and .outer approach that Welbog suggested.
So you're reduced to defining your styles for the main document as you normally would. However to override those styles for the same elements under the T&C div you would have to explicitly override/re-style. You could use two stylesheets to retain clarity, but you'd have to remember, in the t_and_c.css to explicitly preface every declaration with the id of the enclosing div, for example:
#t&c p {...}
#t&c a:link,
#t&c a:visited {...}
I have a row of divs that must all be the same height, but I have no way of knowing what that height might be ahead of time (the content comes from an external source). I initially tried placing the divs in an enclosing div and floated them left. I then set their height to be "100%", but this had no perceptible effect. By setting the height on the enclosing div to a fixed-height I could then get the floated divs to expand, but only up to the fixed height of the container. When the content in one of the divs exceeded the fixed height, it spilled over; the floated divs refused to expand.
I Googled this floated-divs-of-the-same-height problem and apparently there's no way to do it using CSS. So now I am trying to use a combination of relative and absolute positioning instead of floats. This is the CSS:
<style type="text/css">
div.container {
background: #ccc;
position: relative;
min-height: 10em;
}
div.a {
background-color: #aaa;
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
width: 40%;
}
div.b {
background-color: #bbb;
position: absolute;
top: 0px;
left: 41%;
bottom: 0px;
width: 40%;
}
</style>
This is a simplified version of the HTML:
<div class="container">
<div class="a">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.</div>
<div class="b">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.</div>
</div>
This works, unless you change the min-height to something like 5em (demonstranting what happens when the content exceeds the minimum height), and you can see that while the text doesn't get cutoff, the divs still refuse to expand. Now I am at a lose. Is there any way to do this using CSS?
Here is one of those moments where you can get stuck between being idealistic or realistic. I understand that there is no semantic value to placing non-tabular data in a table strictly for formatting reasons but I don't want to see you bending over backwards to create a non-tabular solution to this problem simply for its own sake.
I am the first to shoot down non-semantic designs, trust me, but sometimes you need to face the fact that CSS + semantic markup does not work for all design scenarios. I don't know the accessibility needs of this site but I would recommend that you look to a more practical solution to this problem.
Cheers to you for approaching this the right way and looking for the proper way to solve it! Unfortunately this is one of the dark corners of CSS (along with vertical positioning within a block) that is just plain impossible to do without faux columns, javascript, or table cells.
Whichever you choose, please don't adhere to a standard for its own sake.
Making them exactly the same height can be a tricky thing, but if they just have to appear to be the same height, you may want to look at the faux columns technique.
I have tried a few other methods, but this is the most reliable way I have found of getting the effect, apart from using tables of course.
OK, the table thing turned out to be a little trickier than I thought it would be. It turns out the Javascript solution is actually the simplest (for my situation), since my app is an AJAX app and the framework uses Prototype.js. All it takes is a few lines of JS:
$$('div.container').each(function (element) {
var longest = 0;
element.descendants().each(function (child) {
if (child.getHeight() > longest)
longest = child.getHeight();
});
element.descendants().each(function (child) {
child.style.height = longest + 'px';
});
});
Thanks again for the help.
You can use JavaScript, but of course it will break without JavaScript enabled. Then there's tables, but this ruins the point of CSS. Perhaps seanb's answer could work, place a background image that creates the illusion that all columns go to the bottom. This is known as the faux background technique.
Or sit tight and wait for display: table-cell to be supported for all/most browsers.
Thanks for the answers, guys. I don't think the background image will work because the widths of the columns can also vary depending on how many columns there are (the user can change it). I guess I'll use tables :(
if your looking for a purely css option, and you can seperate the background of the block from the content then the answer is two have two bits of code for each block, one for the content, one for the background. this is how it's done:
<div id="wrapper">
<div class="content" id='one>
<div class="content" id="two>
<div class="content" id="three>
<div class="background" id="back-one">
<div class="background" id="back-two">
<div class="background" id="back-three">
</div>
Position the content divs using floats. Then position the backgrounds using absolute positioning (and a z-index to put them behind)
This works because the floats can set the height, and the absolutely positioned elements can have 100% height. It's a little bit messy, but does the job.