Why is the background image not showing? - css

Background image is not showing for the banner, but I'm pretty sure my code is correct.
I'm trying to put a background image as a banner on my index page, which will have text over the top. I'm following a tutorial on YouTube (I know, I'm sorry) and I'm pretty sure that I've followed the example code perfectly (I will change it eventually but I just wanted a reference).
<main>
<section class="index-banner">
<h2>FILM. MODELING.<br>DESIGN.</h2>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tellus velit, blandit ut nisi in.</h1>
</section>
</main>
.index-banner {
width: 100%;
height: 100vh;
background-image: url('img/tom.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
I should be getting a background image behind my <h1> and <h2> tags, but I'm not seeing anything. I tried removing the formatting but that's still not sorting it.

I found the problem was actually in a meta tag. Where I had...
<meta name="viewport" content="width=device-width, initial-scale=1.0 ">
...there was a space after the 1.0 still within the "". This obviously created the image issue.

Related

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.

how to enable the main body scroll when the height of a dialogue box is large in angular material

In angular material i want to enable the main scroll when the content of dialogue is become larger. by default the background scroller is locked. i tried to enable it by changing overflow property of css but it doesn't work. is there anyone who can help me?
Insert all content on
<md-content>
Lorem ipsum dolor sit amet, ne quod novum mei.
</md-content>
And than
md-content {
overflow: auto;
}

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

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.

Text-indent bug in safari, or expected behavior?

I've put a little demo of the problem I'm trying to debug here: http://jsfiddle.net/bvDBb/7/.
The text-indent works as expected (or at least the way I expect it to) in Chrome, Firefox and Opera - it indents the first line of the text and then performs the wrapping again to keep the padding correct.
However, when viewed in Safari (5.1.7 on OS X 10.7.4) instead of wrapping the text, it creates a horizontal scrollbar and just moves the first line to the right - and with a large enough indentation, part of the line gets hidden and you have to scroll to see it.
Is that a bug in Safari, or am I just lucky that the rest of the browsers support it?
EDIT:
As Keith's idea of adding a <p></p> around the text fixes the layout (at least on Safari, haven't tried FF on Win), the question remains more like: what is the correct behavior and why?
try adding overflow-x:hidden; under overflow-y:auto; in .content
You should be using the actual CSS property text-indent for a text-indent like this. Such as:
<div class="contentWrapper">
<div class="content" style="text-indent: 100px;">
<img src="image.jpg" alt="some image" />
<p class="indent-me">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec porta mattis lectus, in fringilla magna posuere vitae.</p>
</div>
</div>​
p.indent-me {
text-indent:30px;
}
use 'em' instead of 'px'
text-indent:30em;
You can try the following, it works perfect both on desktop and mobile Safari.
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
text-indent: 30px;
}

Making a row of divs all be the same height using CSS

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.

Resources