Responsive Canvas in Bootstrap column? - css

I'm new to bootstrap and working on a project to help figure it out. I also don't know much LESS yet.
I have 2 columns: col-xs-3 and col-xs-9. In the 9 column, I have a canvas that I would like to retain a particular aspect ratio. I don't actually care what the aspect ratio is, as long as it's the same everywhere. Specifically, as wide as the column and a proper height for the given width.
I've tried using percentages for width and height, but even if that did work, it'd be less than ideal in a dynamic height column.

This example works fine for me. I think you need to do two things: remember to set the width and height properties on the canvas, and then you can set the canvas width to 100% and its height to auto. It should cause the canvas to always be the full width of its container and force its height to remain in proportion.
CSS:
canvas {
background-color: blue;
width: 100%;
height: auto;
}
HTML:
<div class="container">
<div class="row">
<div class="col-md-4">
<canvas id="canvas" width="300" height="300">
Sorry, your browser doesn't support the <canvas> element.
</canvas>
</div> <!-- /col-md-4 -->
<div class="col-md-4">
<p>item 1: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div> <!-- /col-md-4 -->
<div class="col-md-4">
<p>item 2: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div> <!-- /col-md-4 -->
</div> <!-- /row -->
</div>
JS:
$( document ).ready(function() {
var c=document.getElementById("canvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
});
A fiddle demo

Related

How to align an image with text such that image sits at top right while text surrounds it in CSS?

I am trying to create a combination of image text layout like this:
And the result should look something like this:
I am not sure how to achieve this. I tried using a grid but the grid would mean splitting the text into two elements and then parsing it however ideally I want the text to take all of the area left and the image to take the top right area and it should be responsive.
Can someone help me out here?
Here's the code that I tried:
<div className='w-4/5 FlashElementGrid h-4/5'>
<div className='border border-red-600 FlashElement_Picture'>Picture</div>
<div className='border border-red-600 FlashElement_Text_1'>Text 1</div>
<div className='border border-red-600 FlashElement_Text_2'>Text 2</div>
</div>
.FlashElementGrid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
}
.FlashElement_Picture {
grid-column: 2 / 3;
grid-row: 1 / 2;
}
.FlashElement_Text_1 {
grid-column: 1 / 2;
grid-row: 1 / 2;
}
.FlashElement_Text_2 {
grid-column: 1 / -1;
grid-row: 2 / 3;
}
This works however I don't want three elements instead I want two elements where image goes top right and text spans into rest of the area.
You can make the image float on the right using float css property.
Margin is used to keep distance outside the image border so the text does not overlap.
.image {
float: right;
margin: 0 0 0 15px;
}
<div>
<img src="some.jpg" alt="" width="200" height="200" class="image"/>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>

How to make ellipsis media heading in second line using Bootstrap Media object

How to make ellipsis media heading in the second line using Bootstrap Media object?
The image below shows 3 lines, how can I limit it only 2 lines then ellipsis
May be something like this using css
.media-body h5 {
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
img {
max-width: 50px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="media">
<img class="mr-3" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Blue_copyright.svg/250px-Blue_copyright.svg.png" alt="image">
<div class="media-body">
<h5 class="mt-0"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</h5>
Description does here
</div>
</div>

Title is displayed above floated image instead of to the right of it

I have an article that contains a title (h4), an image that is floated left and some text.
When the title precedes the image in the HTML declaration, it is displayed above the image.
When the image precedes the title, the title is displayed to the right of the image.
Here is the HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
img {
margin: 1em;
border: 1px solid black;
float: left;
}
</style>
</head>
<body>
<article id="a1">
<h4>Title is above image</h4>
<img src="images/about.jpg" alt="about" /> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</article>
<hr/>
<article id="a2">
<img src="images/about.jpg" alt="about" />
<h4>Title is to the right of image</h4>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</article>
</body>
</html>
The HMTL above is rendered as can be seen below:
How can I use CSS to render the title to the right of the image when the title precedes the image in HTML ? I am looking for a solution where the HMTL is not changed in any way.
The natural thing would be to change the markup - here is a clumsy hack using positioning and negative margins (assuming the image width is fixed) - see demo below:
article {
clear: both; /* clear the float after each article - this is important */
}
img {
margin: 1em;
border: 1px solid black;
float: left;
}
#a1 {
padding-top: 30px; /* put some space at the top */
}
#a1 h4 {
position: absolute; /* positione the title in that space*/
left: 240px;
top: -10px;
}
#a1 img {
margin-top: -15px; /* shift the image to the top */
}
<article id="a1">
<h4>Title is above image</h4>
<img src="https://via.placeholder.com/200" alt="about" /> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing
Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</article>
<hr/>
<article id="a2">
<img src="https://via.placeholder.com/200" alt="about" />
<h4>Title is to the right of image</h4>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</article>
<h4> has a default display of block, which takes up the whole line. Give it the style of display: inline; and it will make the image and the text in the same line as it. Since the image has float: left;, it will automatically go to the left. However, since the text is still next to the <h4>, and a couple <br>'s to make it how you wanted.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
img {
margin: 1em;
border: 1px solid black;
float: left;
}
</style>
</head>
<body>
<article id="a1">
<h4 style="display: inline;">Title is above image</h4>
<img src="images/about.jpg" alt="about" /> <br><br> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled
it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</article>
<hr/>
<article id="a2">
<img src="images/about.jpg" alt="about" />
<h4>Title is to the right of image</h4>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</article>
</body>
</html>

Bootstrap 4 Card with dynamic header and fixed body

I am using a bootstrap 4 card:
<div class="card" style="height:"500px;width:100px">
<div class="card-body">
<div class="top-portion">
This portion can span from one to many lines.
</div>
<div class="content" style="overflow-y">
....
....
</div>
</div>
</div>
I need the ".content" div to occupy the remaining vertical space and be scrollable when needed. I know that I am supposed to put "max-height:..." at its style.
However, the problem is that I do not know the exact value to put because the ".top-portion" section varies in height.
<div class="card" style="height:500px; width:100px;overflow: hidden;">
<div class="card-body d-flex flex-column">
<div class="top-portion mb-auto">
This portion can span from one to many lines.
</div>
<div class="content" style="overflow-y:auto;max-height: 200px;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
</div>
use this code for your card. and "top-portion" height never disturb content. I have use "mb-auto" it means margin-bottom:auto; if you want to put content area bottom of card.

Need help - sticky navbar

So I have this problem, where I have my navigation bar that respondes to screen sizes.
All looks fine, but I need it to be sticky. Whenever I do this, It floats on top of my first hero picture, and with a section of about 40-50px at the top that I can't get rid of.
If someone could please give me a hand with this. It has been doing my head in for 2 weeks now.
Here is the JSfiddle: http://jsfiddle.net/fxar8/
<header>
<nav class="clearfix">
<ul class="clearfix">
<li>Home</li>
<li>Teaching and Learning</li>
<li>News and Events</li>
<li>Contact</li>
<li>Home</li>
<li>Home</li>
</ul>
Menu
</nav>
</header>
<div class="hero-image first">
<h1 class="big">Sample Text</h1>
</div>
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="grid-6">
<h1>About Us</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Read More</p>
</div>
</section>
</div>
</section>
<a name="tl"><div class="hero-image second"></a>
<h1 class="big">Sample Text</h1>
</div>
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="grid-4">
<h1>Teaching & Learning</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="grid-2">
<img src="images/tl.jpg" />
</div>
</section>
</div>
</section>
<a name="ne"><div class="hero-image third"></a>
<h1 class="big">Sample Text</h1>
</div>
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="grid-2">
<img src="images/ne.jpg" />
</div>
<div class="grid-4">
<h1>News and Events</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</section>
</div>
</section>
<a name="contact"><div class="hero-image fourth"></a>
<h1 class="big">Sample Text</h1>
</div>
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="grid-2">
<center><img src="images/2501.jpg" class="rounded" /></center>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="grid-2">
<center><img src="images/2502.jpg" class="rounded" /></center>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="grid-2">
<center><img src="images/2503.jpg" class="rounded" /></center>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</section>
</div>
</section>
<footer class="grid-full">
<p>© BHS 2014.</p>
<p class="right"> Designed by Begintoend</p>
</footer>
Cheers in advanced
So basically you have to modify a few things, because 'Teaching an Learning' doesnt fit.
// This is to fit longer text (Teaching and Learning)
// + padding so it looks nicer
nav a {
min-width: 150px;
padding: 0 15px;
}
// Total width needs to be adjusted
// because we increased the size of navbar (Teaching..)
nav ul {
width: 1000px;
}
// The gap was caused by h1 element's top margin inside hero
.big {
margin-top: 0;
}
Also don't forget to adjust viewports - widths at which to transofrm the menu, since the menus' width has increased

Resources