Responsive Cross Browser and Flexible way of "cross-background" images - css

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.

Related

Responsive grid with a circular image and cut out div

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.

Prism code block breaks responsive design (using flexbox)

I designed a page layout that is responsive and adjusts fine to smaller screens, but when I added in a code block (and used prism.js to format it), the responsiveness breaks. The code box and text content both spill over the width of the device and you have to scroll back and forth. Ideally, the code block should have its own scroll bar to view the code, but the content still adapts. I've tried playing around with different attributes of the flexbox that contains the content, but it still breaks the layout.
To try to narrow things down I've stripped the page down to:
<!DOCTYPE html>
<head>
<link rel='stylesheet' href='page.css' />
<link href="./external/prism.css" rel="stylesheet" />
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0' />
</head>
<body>
<script src="./external/prism.js"></script>
<div class="article-container">
<article>
<h1 class="title">Test</h1>
<p>Dolorem neque quiquia dolor. Est dolor dolor dolorem adipisci consectetur. Adipisci ipsum velit dolore
consectetur quisquam eius. Non velit est ipsum adipisci adipisci quaerat.</p>
<pre><code class="language-python">def some_code(file_name):
with open("some_path/" + file_name + ".md", "r", encoding="utf-8") as input_file:
return input_file.read()
</code></pre>
</article>
</div>
</body>
</html>
With page.css containing:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.article-container {
width: 100%;
display: flex;
justify-content: center;
}
article {
width: 800px;
}
If I comment out both .article-container and article the page adjusts fine, but if either one of them is present it breaks. Also, if I leave the CSS as is and comment out the code block it's responsive.
Any types on how these components are interacting would be appreciated, thanks!
EDIT: To clarify, when the responsive design doesn't work, the page width does not adapt to the screen size. See screenshots below:
The content in fullscreen mode
How mobile looks without CSS - the code box scrolls like it should, but the rest of the page adapts
How mobile looks with CSS
Note that 2 is also how the site looks with CSS and without the codeblock. So something about the way they are interacting is breaking.
I was able to fix the issue by just adding overflow: auto; to the CSS for the article section.
https://gist.github.com/grahamjpark/0cb9d2cfbe7a972bc20320781806e284#file-test-css-L15
I found the answer here:
Flex item with <pre> content not shrinking
Although this looks useful if that doesn't fix your issue:
https://weblog.west-wind.com/posts/2016/feb/15/flexbox-containers-pre-tags-and-managing-overflow
I think your problem lies within this rule:
article {
width: 800px;
}
That's why the text on top of the code won't adjust itself to the screen.
The code tag itself must have some CSS rules implied that prevents the code from wrapping or "responding" to the screen, because indentaion is important inside that element, and should not be too affected by the screen size.
And maybe you'll want to add an overflow-x:auto; to the element so you can scroll to see more code when the screen isn't wide enough.
This goes for overflow-y also if you want to scroll down inside the code too.

Why does min-height with percentage work without container height?

According to css specification on min/max-height, if I don't provide a fixed height for the containing block any percentage min-height value will be treated as 0. I have the following example showing that this is either implemented with some quirks or I'm missing something very obvious.
What I want to achieve with this layout
A 2 column layout with the container having dynamic height depending on the columns height
The left column should float above the right column
Both the left and the right column should get the height of the largest column (align-items: stretch)
p {
/*Comment out to display more content*/
display: none;
}
.floating-panel-content {
position: relative;
z-index: 1;
background: rgba(0, 100, 0, 0.9);
float: left;
width: 100px;
/*Why does this work? I didn't provide any explicit height.*/
min-height: 100%;
}
.container {
display: flex;
width: 300px;
outline: 1px solid red;
align-items: stretch;
}
.main-panel {
background: blue;
}
img {
display: block;
}
.floating-panel {
flex: 0 0 0;
width: 0;
}
<div class="container">
<div class="floating-panel">
<div class="floating-panel-content">
Floating content
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Atque maxime aperiam saepe, quia error reiciendis dolorem! Natus facere aliquam sit quisquam, mollitia debitis ullam assumenda atque beatae saepe labore ab.
</p>
</div>
</div>
<div class="main-panel">
<img src="http://placehold.it/300x300">
</div>
</div>
Some content after .container
You wrote:
According to css specification on min/max-height, if I don't provide a fixed height for the containing block any percentage min-height value will be treated as 0.
That's 100% correct. That's what the spec says.
<percentage>
Specifies a percentage for determining the used value. The percentage
is calculated with respect to the height of the generated box's
containing block. If the height of the containing block is not
specified explicitly (i.e., it depends on content height), and this
element is not absolutely positioned, the percentage value is treated
as 0 (for min-height) or none (for max-height).
https://www.w3.org/TR/CSS22/visudet.html#min-max-heights
You wrote:
I have the following example showing that this is either implemented with some quirks or I'm missing something very obvious.
Also correct. You're not missing anything, but you're on the right track with "some quirks".
For many years, major browsers adhered to a strict interpretation of spec language with regard to percentage heights. In other words, without an explicitly defined height on the parent, a percentage height on the child wouldn't work as intended. It would resolve to auto or 0 or none, per the respective rule for height, min-height or max-height.
In recent years, however, most major browsers have loosened their interpretation and now accept other forms of height – such as flex heights – as an acceptable parent reference.
The only browser that appears to continue with the strict interpretation is Safari. Without a defined height (using the height property) on the parent, percentage heights on the children will fail.
It doesn't help matters that the height property definition hasn't been updated since 1998 (CSS2). With the advent of multiple new ways to establish box height, this definition is thoroughly obsolete. It appears that browser makers aren't waiting around for an update from the W3C.
For more details and examples see: Chrome / Safari not filling 100% height of flex parent

Text overflow behaviour in CSS with non-left values for text-align

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.

CSS - Nested DIV : Clear Sub Styles

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 {...}

Resources