Center a `.img-responsive`, in a `.container-fluid` and `row`, in bootstrap? - css

I don't expect the answers here to add much to the 21st century's understanding of computer science, but I am grateful for the help of the community.
I have an image I'm trying to center in bootstrap. It's in a .container-fluid, a .row, and a .col-xs-6 with .offset-xs-3. The <img...> itself is .img-responsive. You can see the project on this codepen: http://codepen.io/NotAnAmbiTurner/pen/GrGmaq?editors=1000.
The image is not centering - I should be able to get an image that scales with the viewport width (a la SVG) and is in the middle of the page. I can't seem to manage that.
I'm wondering if it has something to do with the fact that I'm taking a "raw" image from dropbox as my src, that the image is a .jpg, or some combination? Then again, I'm a noob at this, so it's equally possible that there's just a typo somewhere I can't seem to find. I have been over the bootstrap docs, and various SO questions to no avail. The only solution I have found is removing the <img...> from the container and row, and assigning ... class="centered-block" .... Unless I'm fundamentally misapprehending something, however, (1) I shouldn't have to do that, and (2) rather than bashing through I'd like to understand what my conceptual error is in any case, for my own learning.
PS - totally unrelated, but my <a ...></a> tags don't seem to be clickable. If anyone has any ideas there, that would be great too.
It turns out the basic issue is that CodePen relies on Bootstrap 4, not (as I had assumed) Bootstrap 3.

You're using classes from Bootstrap 3 but loading the stylesheet from Bootstrap 4; they aren't compatible across the board. img-responsive no longer exists as well as the col-xs-* classes. See Images and Grid Options.
Note: Your links won't work because they aren't valid HTML and you're also closing your h2 with an h3, validate your markup.
Working Example:
#media (max-width: 480px) {
h1 {
font-size: 5vmax;
}
h2 {
font-size: 3.5vmax;
}
h3 {
font-size: 2.5vmax;
}
li {
font-size: 2.5vmax;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="jumbotron">
<h1 class="text-primary">Dr. Clair Cameron Patterson</h1>
<h2 class="text-secondary">The man who first learned the age of the Earth, and helped save a civilization from the dangers of its use of lead.</h2>
<div class="container-fluid">
<div class="row">
<div class="col">
<img src="https://www.dropbox.com/s/91fw6aazyxzb178/image-for-codecamp-tribute-page.jpg?raw=1" alt="Cartoon Image of Clair Cameron Patterson at Congressional Hearing" class="img-fluid mx-auto d-block" style="padding:1.5vmin">
</div>
</div>
</div>
<h3>Academics</h3>
<ul>
<li>Undergraduate, Grinnell College</li>
<li>PhD, University of Chicago</li>
<li>Researcher, California Institute of Technology</li>
</ul>
<h3>Brief Timeline</h3>
<ul>
<li><strong>1956</strong>: found the earth to be 4.55 Billion years old using lead-lead dating and
a fragment of a metorite that fell in Arizona. This calculation has been largely undisturbed since.</li>
<li><strong>1965</strong>: began campaign against lead in various products, especially gasoline, which at that time was emitting lead into the atmosphere.</li>
<li><strong>1978</strong>: wrote a 78-page minority opinion as part of a National Research Council (NRC) panel stating that controls on lead in various products had to start immediately, including gasoline, food containers, paint, glazes, and water distribution
systems.
</li>
<li>by the late <strong>1990s</strong>: levels of lead in Americans' blood has dropped by up to 80%. Though connections with Dr. Patterson's work are not clear, as the leading researcher in the area, and constant campaigner against the use of lead, it
is likely he was a major antecedant of this change.</li>
</ul>
</div>

Related

How to display paragraph as column with abbr inside?

I practice css on zengarden.
I want something like this, but with no h3 column.
HTML
<div class="preamble" id="zen-preamble" role="article">
<h3>The Road to Enlightenment</h3>
<p>Littering a dark and dreary road lay the past relics of browser-specific tags, incompatible
<abbr title="Document Object Model">DOM</abbr>s, broken <abbr title="Cascading Style Sheets">CSS</abbr>
support, and abandoned browsers.</p>
<p>We must clear the mind of the past. Web enlightenment has been achieved thanks to the tireless efforts of folk like the
<abbr title="World Wide Web Consortium">W3C</abbr>,
<abbr title="Web Standards Project">WaSP</abbr>
, and the major browser creators.</p>
<p>The CSS Zen Garden invites you to relax and meditate on the important lessons of the masters. Begin to see with clarity. Learn to use the time-honored techniques in new and invigorating fashion. Become one with the web.</p>
</div>
I also try.
.preamble :not(h3){
display: flex;
}
I got this.
Maybe It's because of abbr inside p tag.
Is there a way to achieve what I want?
It seems CSS columns could fit here. If the heading should span the whole width, you can set the column-span property.
You may also need to style the paragraph to your liking (e.g. adjust margin).
See MDN Multiple-column layout for more information.
.preamble {
columns: 3;
}
h3 {
column-span: all;
}
<div class="preamble" id="zen-preamble" role="article">
<h3>The Road to Enlightenment</h3>
<p>Littering a dark and dreary road lay the past relics of browser-specific tags, incompatible
<abbr title="Document Object Model">DOM</abbr>s, broken <abbr title="Cascading Style Sheets">CSS</abbr> support, and abandoned browsers.</p>
<p>We must clear the mind of the past. Web enlightenment has been achieved thanks to the tireless efforts of folk like the
<abbr title="World Wide Web Consortium">W3C</abbr>,
<abbr title="Web Standards Project">WaSP</abbr> , and the major browser creators.</p>
<p>The CSS Zen Garden invites you to relax and meditate on the important lessons of the masters. Begin to see with clarity. Learn to use the time-honored techniques in new and invigorating fashion. Become one with the web.</p>
</div>
You need remove h3 from that div for centered it
.preamble {
display: flex;
}
h3{
text-align: center;
}
<h3>The Road to Enlightenment</h3>
<div class="preamble" id="zen-preamble" role="article">
<p>Littering a dark and dreary road lay the past relics of browser-specific tags, incompatible
<abbr title="Document Object Model">DOM</abbr>s, broken <abbr title="Cascading Style Sheets">CSS</abbr> support, and abandoned browsers.</p>
<p>We must clear the mind of the past. Web enlightenment has been achieved thanks to the tireless efforts of folk like the
<abbr title="World Wide Web Consortium">W3C</abbr>,
<abbr title="Web Standards Project">WaSP</abbr> , and the major browser creators.</p>
<p>The CSS Zen Garden invites you to relax and meditate on the important lessons of the masters. Begin to see with clarity. Learn to use the time-honored techniques in new and invigorating fashion. Become one with the web.</p>
</div>

why doesn't this simple bulma example work? (straight from their site)

I copied a basic example from the site and included the css file, but the columns aren't being styled. What am I missing?
https://jsfiddle.net/bLm2rgoz/6/
Here's the template:
<div class="columns">
<div class="column">1</div>
<div class="column">2</div>
<div class="column">3</div>
<div class="column">4</div>
<div class="column">5</div>
</div>
Of course, I'm including https://cdnjs.cloudflare.com/ajax/libs/bulma/0.2.3/css/bulma.css
This will only address the responsiveness of the 5 columns! You can demonstrate the responsiveness by widening and shrinking the fiddler-view. (Hint: Drag the left-side of the view panel to do so)
Expected & Observed: row of 1 2 3 4 5 when the view is wide, column of
1
2
3
4
5
when the view is not wide.
If you're trying to style the columns, please be more specific on which styles you want : )
It doesn't work because they are not even using the same CSS library they tell you to use to get that result (and yes, that sucks!)
If you view the source code on the example site, you see that it is actually:
<p class="bd-notification is-primary">First column</p> and not just First column.
So we edit our HTML and it still doesn't work. So back to the source and we discover that the CSS being referenced is in bulma-docs.min.css, and not in the CSS from the CDN or download that you are told to use (which is just bulma.min.css or bulma.css).
So we look at that and add some new CSS to the <head> of our HTML...
<style>
p.nice {
background-color: #00d1b2;
color: white;
border-radius: .375em;
font-weight: 600;
padding: 1.25rem 0 1.25rem 0;
position: relative;
text-align: center;
}
</style>
and change the example to be like this...
div class="columns">
<div class="column"><p class="nice">First column</p></div>
<div class="column"><p class="nice">Second column</p></div>
<div class="column"><p class="nice">Third column</p></div>
<div class="column"><p class="nice">Fourth column</p></div>
</div>
and then it finally looks like the example on the web site.
Dear library/framework developers... We love you and the work you do, especially when you document it and make nice examples. But when you claim using your framework is "very simple" and "just copy this code", then the result should look the same as your example. Don't use different code to what you are putting in the example, unless you also state very clearly that it will look/act differently and why. Remember, even experienced programmers are "newbies" to your framework, and having to waste time trying to figure out why it isn't working like the example can be really infuriating.

Automatically assign width of <div> to contained <img> where width of image is not known

Not sure I worded the title optimally, but here's a simple explanation of my problem.
I have an HTML structure like so:
<div class="media-container" style="float: left">
<img src="..." />
<p class="caption">Here is a long caption that will extend beyond the width of the image.</p>
</div>
This is what it ends up looking like:
I want the caption text to line-break once it hits the width of the image so it instead looks like this:
I can get it the way I want by setting a fixed with on the container div, but I don't know that width ahead of time, so there's no way.
Are there any solutions to this problem I'm overlooking that are possible in pure CSS without involving JavaScript?
Use display: table;
.media-container {
display: table;
}
.caption {
display: table-caption;
caption-side: bottom;
}
<div class="media-container" style="float: left">
<img width="100" src="https://d1ra4hr810e003.cloudfront.net/media/27FB7F0C-9885-42A6-9E0C19C35242B5AC/0/D968A2D0-35B8-41C6-A94A0C5C5FCA0725/F0E9E3EC-8F99-4ED8-A40DADEAF7A011A5/dbe669e9-40be-51c9-a9a0-001b0e022be7/thul-IMG_2100.jpg" />
<p class="caption">Here is a long caption that will extend beyond the width of the image.</p>
</div>
Fiddle: https://jsfiddle.net/4pL4wm9h/
Add the following to the parent element:
width: -moz-min-content;
width: -webkit-min-content;
width: min-content;
Details on min-content can be found here
PLUNKER
SNIPPET
<!DOCTYPE html>
<html>
<head>
<style>
figure {
float: left;
width: -moz-min-content;
width: -webkit-min-content;
width: min-content;
}
</style>
</head>
<body>
<p>One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by
arches into stiff sections.</p>
<p>The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream.</p>
<figure>
<img src="http://i.imgur.com/sbxyLKX.png">
<figcaption>Here is a long caption that will extend beyond the width of the image.</figcaption>
</figure>
<p>His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had
recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then
turned to look out the window at the dull weather. Drops</p>
<p>A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so
happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When,
while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the
trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel
the presence of the Almighty, who formed us in his own image, and the breath</p>
</body>
</html>

Is it possible to have sidenav start open in W3.CSS?

W3.CSS is a very new web technology and I cannot find any information about it other than w3schools.com. I was wondering if anyone here knows how to have their sidenav start out open?
Here is a working example that shows one in action:
https://jsfiddle.net/8orgp5xv/
#import 'http://www.w3schools.com/w3css/w3full.css';
<nav id="id01" class="w3-sidenav white w3-depth-2">
Close ×
Link 1
Link 2
Link 3
Link 4
Link 5
</nav>
<div class="w3-content">
<div class="w3-header teal">
☰
<h1>My Header</h1>
</div>
<img src="img_car.png" alt="Car" width="100%">
<div class="w3-panel">
<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
Most definitions of the term specify that cars are designed to run primarily on roads,
to have seating for one to eight people,
to typically have four wheels. (Wikipedia)
</p>
</div>
<div class="w3-footer teal">
<h5>Footer</h5>
<p>Footer information goes here</p>
</div>
</div>
I just need to know how to make it start open when the page loads.
I tried messing with w3-sidenav and w3-closenav with no luck. Anyone know?
The relevant bit of code appears to be:
.w3-sidenav:target {
width: 25%;
display: block;
}
.w3-sidenav:target + .w3-content {
margin-left: 25%;
}
.w3-sidenav:target + .w3-content .w3-opennav {
display: none !important;
}
.w3-sidenav:target + .w3-content .w3-closenav {
display: block !important;
}
This means that the navigation show/hide and the surrounding layout changes are driven by CSS :target and hash fragments. Which means unless you rewrite or duplicate these rules and use .w3-sidenav:not(:target) and change the a element triggering the sidenav, or something similar, it's going to be difficult to tell the layout to load with the sidenav open in pure CSS.
Needless to say, this is made trivial by either setting the appropriate hash on page load, or better yet, rewriting the entire component to use JavaScript instead of hash fragments and :target.
First, W3.CSS is not a "very new web technology". It's just a stylesheet.
If you want to know how to use it, see the documentation of the authors, or learn CSS to understand it directly.
In this case, the code that opens the sidenav is
.w3-sidenav:target {
width: 25%;
display: block;
}
The :target is a pseudo-class that matches the element whose ID (or name) equals the fragment identifier (the part of the URI after #).
Therefore, you should use some JS to set the fragment identifier to the id of the element when the page loads. This can be done using hash:
document.location.hash = 'id01';
document.location.hash = 'id01';
#import 'http://www.w3schools.com/w3css/w3full.css';
<nav id="id01" class="w3-sidenav white w3-depth-2">
Close ×
Link 1
Link 2
Link 3
Link 4
Link 5
</nav>
<div class="w3-content">
<div class="w3-header teal">
☰
<h1>My Header</h1>
</div>
<img src="img_car.png" alt="Car" width="100%">
<div class="w3-panel">
<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
Most definitions of the term specify that cars are designed to run primarily on roads,
to have seating for one to eight people,
to typically have four wheels. (Wikipedia)
</p>
</div>
<div class="w3-footer teal">
<h5>Footer</h5>
<p>Footer information goes here</p>
</div>
</div>

do you keep class/id on the same div or break them up?

Since I couldn't find anything on yui3 documentation, I kindly ask your opinion on below. What is the best practice and why?
<div class="yui3-u-1-3" id="logo">
... content
</div>
or
<div class="yui3-u-1-3">
<div id="logo">
..... content
</div>
</div>
Regards,
Castle
I consider best practice to use ID's on the purely layout specific HTML.
eg.
#outer-container
#wrapper
#sidebar
Having said that if there is any chance, even a remote one that you may have multiple instances of these in your page, then play safe and use classes.
There are some performance benefits (although it's almost negligible now, with faster browser rendering engines and speeds):
ID selectors are slightly faster in your CSS
ID selectors are more efficient as hooks using JS
Read this great section from Jonathan Snook's SMACSS e-book: https://smacss.com/book/type-layout
I would rather use CLASS over ID until something explicit, have been using yui3 grid since last 2 years for now. so far going great..
<div class="yui3-u-1-3 logo">
content
</div>
or
<div class="yui3-u-1-3">
<h5 class="logo">logo goes here</h5>
</div>

Resources