Responsive CSS behaviour of a centered image - html

I cannot get the image container (.colored-logo) to span the width of the browser when I shrink it to mobile size. I have created a fiddle here so you can see the behaviour.
Apologies but I have placed all my CSS in here to make sure that whatever it is affecting it is included.
I am working on an email template and I am centering horizontally and vertically a logo into a boxed area with rounded corners.
My HTML is:
<div class="row invoice-top-header">
<div class="column third colored-logo">
<div class="logo">
<span class="image-center"></span><img src="http://s24.postimg.org/ebd3rwub5/fresh_creations_logo.png"/>
</div>
</div>
<div class="column third">...</div>
<div class="column third">...</div>
</div>
The row class adds a 15px internal padding which I offset in the container (colored-logo) with a -15px margin left and right.
The CSS I apply is this:
.colored-logo {
background: #989898;
height: 128px;
margin: 0px -15px 10px -15px;
padding: 15px;
width: 100%;
}
.logo {
white-space: nowrap;
text-align: center;
}
.image-center {
display: inline-block;
height: 100%;
vertical-align: middle;
}
Why is the logo container (div with class colored-logo, dark grey background) not filling the browser horizontally once in mobile mode? It looks to be 30px too short to cover the browser horizontally.Thanks!

It seems you have padding both to your row class and your column.
Try this css if you want your changes to take effect only in mobile screens:
#media screen and (max-width: 640px) {
.colored-logo, .row {
padding: 0;
margin: 0;
}
}

<div class="invoice-top-header">
<div class="column third colored-logo">
<div class="logo">
<span class="image-center"><img src="http://s24.postimg.org/ebd3rwub5/fresh_creations_logo.png"/>
</div>
</div>
<div class="row">
<div class="column third">
<div class="biller-details">
<span><strong>BILLER NAME PTY LTD</strong></span>
<span>ADDRESS LINE 1</span>
<span>ADDRESS LINE 2</span>
<span class="desktop">TEL: 02 3333 4444</span>
<span class="mobile">TEL: 02 3333 4444</span>
<span>ABN: 12345678</span>
<span>ACN: 09876543</span>
<span>sample#email.com</span>
<span>my-website.com.au</span>
</div>
</div>
<div class="column third">
<div class="customer-details">
<span><strong>CUSTOMER NAME PTY LTD</strong></span>
<span>ADDRESS LINE 1</span>
<span>ADDRESS LINE 2</span>
<span class="desktop">TEL: 02 5555 7777</span>
<span class="mobile">TEL: 02 5555 7777</span>
<span>ABN: 12345678</span>
<span>ACN: 09876543</span>
<span>sample#email.com</span>
<span>customer-website.com.au</span>
</div>
</div>
</div>
</div>
Change your HTML into this one above
Remove margin css property from .colored-logo
If you are coding a newsletter you should really consider using tables and avoid css3 properties as many of the email clients still doesnt support lot of things. Here you can find a list with email clint which does and doesnt support media queries:
https://litmus.com/help/email-clients/media-query-support/
Just tested and it works

Disabling these values / properties seems to work
.row {
margin: 0 auto;
/* padding: 15px; */
max-width: 1040px;
width: 100%;
}
.colored-logo {
background: #989898;
height: 128px;
/* margin: 0px -15px 10px -15px; */
padding: 15px;
width: 100%;
}
Just adjust as required in your media queries.
JSfiddle Demo

Related

What css styling to achieve to ensure Highchart fits within the outer container and resizes on window resize (i.e. they are responsive)

Context:
I am trying to create 3 charts on 1 row (each has a minimum width) such that on window resize, the charts should also resize and may go to next row depending on the browser total width.
Problem:
Currently, I am missing something in the css because the chart is overflowing within the demo container below. The tooltip looks fine, but only half of the chart is seen in the container and both the axes are also hidden.
Has someone implemented something similar before? I want to understand how to load the charts in the div.
P.S. In the code below, highcharts-container is the inbuilt div which contains the charts. I am using the latest version of Highcharts and Angular 7.
My current html code -->
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 col-md4 demo>
<div class="demo-container">
<highcharts-chart [Highcharts]="Highcharts" [options]="options1" [callbackFunction]="cb1">
</highcharts-chart>
</div>
</div>
<div class="col-lg-4 col-md4 demo>
<div class="demo-container">
<highcharts-chart [Highcharts]="Highcharts" [options]="options2" [callbackFunction]="cb2">
</highcharts-chart>
</div>
</div>
<div class="col-lg-4 col-md4 demo>
<div class="demo-container">
<highcharts-chart [Highcharts]="Highcharts" [options]="options3" [callbackFunction]="cb3">
</highcharts-chart>
</div>
</div>
</div>
</div>
My css code (The main part) -->
.container-fluid{
width:100%
}
.demo{
margin: 20px 0;
min-width: 448px;
}
.demo-container{
position: relative;
border: 1px solid transparent;
box-shadow: 0 0 20px #1793f5;
width: 100%;
height: 100%;
}
.highcharts-container{
height: 100% !important;
width: 100% !important;
display: inline-block;
vertical-align: middle;
}
You could try to include the following CSS as a part of demo-container or container-fluid... one of it should do the deal for you.
height: 100% !important;
width: 100% !important;
Update
one of the harder challenges i have encountered, but add this to the style.css
and you have your contents dynamic inside its container.
.highcharts-background, .highcharts-root, .highcharts-container {
max-height: 100%;
max-width: 100%;
}
is this what you are looking for?
This was made using images of the graphs in the links you posted. I also used flexboxes which seems to be what you are looking for.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.container-fluid div {
width: auto;
border: 2px solid red;
min-width: 33%;
}
.container-fluid{
display: flex;
flex-wrap: wrap;
border: 2px solid blue;
justify-content: center;
}
<div class="container-fluid">
<div class="chartOne">
<img src="https://i.gyazo.com/161954d0841b7a398d5f0d63e1b2bcc4.png" alt="">
</div>
<div class="chartOne">
<img src="https://i.gyazo.com/161954d0841b7a398d5f0d63e1b2bcc4.png" alt="">
</div>
<div class="chartOne">
<img src="https://i.gyazo.com/161954d0841b7a398d5f0d63e1b2bcc4.png" alt="">
</div>
</div>

Why is my paragraph exceeding the hr line which is below the paragraph on resizing?

The problem is that I have an image on the left side of my screen and I have a paragraph on the right side of my screen and I have an hr line below the paragraph and the image. So whenever I resize the browser window, the paragraph just goes below the hr line because it gets compressed(squashed) on resizing. I don't want the paragraph to go below the hr line even if I resize the browser window. I want the paragraph to go below the image but not exceeding the hr line. If you want to see what is the problem please check out my website and resize the browser window to see the problem.
Link to website: http://www.greenfield-school.com/AboutUs.html
Thanks
This is the HTML:
<h3><b>About Us</b></h3>
<hr style="border: 2px solid green; width: 88%">
<div class="row2">
<div class="column2" style="background-color:;">
<img class="pic img-responsive" src="Icon.jpeg" style="height: 200px; height: 230px">
</div>
<div class="column" style="background-color:;">
<h5 class="welcome"><b>Mission</b></h5>
<p class="paragraph" style="font-family: book antiqua"><li class="vision1">To care for, respect and encourage all children equally, regardless of gender or ability.</li>
<li class="vision1">To encourage our pupils to develop a sense of self worth, self discipline, personal responsibility and consideration for others.</li>
<li class="vision1">To provide an enjoyable, challenging and purposeful atmosphere for our pupils.</li>
<li class="vision1">To value and encourage the special talents and strengths of pupils.</li></p>
</div>
</div>
And this is the CSS:
.vision1 {
list-style-type: square;
font-family: book-antiqua;
}
.row2{
display: flex;
padding: 2rem 6rem;
}
.column {
flex: 60%;
height: 200px; /* Should be removed. Only for demonstration */
}
.column2{
flex: 0%;
height: 0px; /* Should be removed. Only for demonstration */
}
h3{
padding: 5rem 5rem 0rem;
color: green;
}
Let me offer you an alternative - I can't seem to trigger that auto-adjust on the container height. But this works seamlessly:
This is your HTML:
<div class="container">
<div class="column one"> Column 1 - this is where your picture is</div>
<div class="column two"> Column 2 - this is where your paragraph is</div>
</div>
<hr />
This is CSS:
.container{
width: 100%;
overflow: auto;
height: auto;
clear: both;
display: block;
}
.column{
float: left;
}
.column.one{
//style for column one here
}
.column.two{
//style for column two here
}
hr{
clear: both;
}
This will adjust the height of the container based on on the biggest height of either column one or column two
I have checked this code here CodePen

Centering a BootStrap well

I am trying to center a Bootstrap Well that says "Resource Booker" within a div so that it aligns properly with the two boxes below it. Ive tried adding padding but it adds padding inside of the well. I provided a picture and my code below.
Page Screenshot
<div class="col-sm-8 text-left">
<br>
<br>
<div class="well well-lg" style="background-color:rgb(0,50,0); color:white;"><h1> Resource Booker </h1> </div>
<br>
<br>
<div class="row">
<div class="column">
<div class="card" id="hi" style="width:400px; height:300px;">
<p><i class="fa fa-user"></i></p>
<h1>Book</h1>
<p>Book A Room</p>
<p> <span class="glyphicon glyphicon-book" style="font-size:150px;"></span></p>
</div>
</div>
<center>
<div class="column">
<br>
</div>
<div class="column">
<div class="card" id="bye" style="width:400px; height:300px;>
<p><i class="fa fa-coffee"></i></p>
<h1>Calender</h1>
<p>Check Availability</p>
<p> <span class="glyphicon glyphicon-calendar" style="font-size:150px;"></span></p>
</div>
</div>
</div>
</div>
</center>
</div>
The CSS for the cards underneath the well is:
/* Float four columns side by side */
.column {
float:left;
width: 27%;
padding: 0px 50px 0px 90px;
}
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive columns */
#media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 10px;
}
}
/* Style the counter cards */
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #444;
color: white;
}
.fa {font-size:200px;
Try adding the container class wrapped around the div. You can also add margin-left to the same. Further, please add a codepen of your project so that we mobile users can play around for the solution.
If you add margin-left to div then you have to adjust that margin in media query it's better to give max-width to well dive and give them margin: 0 auto and width: 100%.
Your css will like this
.well{max-width: 400px; width: 100%; margin: 0 auto;}

Centering grouped inline elements issue

I have a section that I want to look as if it is centered on the page. I have four boxes that appear inline and I believe the reason they do not like they are centered is because everything is aligned naturally to the left. The thing is, I do not want the content that is in these boxes to be centered, I want them aligned left.
So how can I make the boxes appear as if they are centered within the page, but not have it affect my text?
#contact-connect {
width: 80%;
height: auto;
margin: 0 10%;
padding: 80px 0;
}
#contact-connect-box-container {
margin: 0 auto;
width: auto;
}
.contact-connect-box {
width: 25%;
margin: 60px 0 0 0;
display: inline-block;
border: 1px solid black;
vertical-align: top;
transition:1s; -webkit-transition:1s;
}
<div id="contact-connect">
<div id="contact-connect-box-container">
<div class="contact-connect-box">
<h2 class="contact-connect-title">Call</h2>
<div class="contact-connect-description">vcxv</div>
</div>
<div class="contact-connect-box">
<h2 class="contact-connect-title">Write</h2>
<div class="contact-connect-description">
Reach out to us
<br>
<div id="scroll" class="contact-connect-link">Fill out our contact form.</div>
</div>
</div>
<div class="contact-connect-box">
<h2 class="contact-connect-title">Visit</h2>
<div class="contact-connect-description">
fgrge
</div>
</div>
<div class="contact-connect-box">
<h2 class="contact-connect-title">Connect</h2>
<div class="contact-connect-description">
<div class="contact-connect-link">Visit us on Facebook</div>
<div class="contact-connect-link">See us on Youtube</div>
<div class="contact-connect-link"></div>
</div>
</div>
</div>
</div>
You can just add "display: flex" on your #contact-connect-box-container
#contact-connect-box-container {
margin: 0 auto;
width: auto;
display: flex;
}
DEMO :
https://jsfiddle.net/w776Lq1u/8/
The problem is the margin on the right side of "Connect." I would recommend using flexbox and using display: flex; justify-content: space-around; That way you won't need any margins at all.
EDIT: plnkr

Trouble with divs?

Okay, I'm very new to CSS and only minimally familiar with HTML so I'm still kind of fumbling around with both of them. I'm building a practice site and I can't figure out what I'm doing wrong here. My goal is to have the image box to the left of the header and paragraph, but have the title on the same line as the top of the image. Here's what I have:
<img src="" />
<div class="bios">
<h4>First Last</h4>
<p>This is my bio</p>
</div>
Paired with this CSS:
.bios {
height: 100px;
width: auto;
display: inline;
background-color: #a78ffc;
clear: left;
display: inline;
/** top, right, bottom, left **/
margin: 1px 1px 1px 10px;
/** top, right, bottom, left **/
padding: 1px 1px 1px 10px
}
img {
height: 100px;
width: 100px;
float: left;
clear: left;
display: inline;
}
I added the background color to really see what's going on in the preview and I'm more confused than ever. This is how it's displaying:
http://i1126.photobucket.com/albums/l618/spenciecakes/Screen%20Shot%202016-05-13%20at%2010.41.45%20AM_zps50dajzko.png
EDIT
Okay, I've added the additional code as requested and I've added the display: inline to both elements but honestly it all appears the same..
I can't solve your problem with only the code you provided (what's the code for the images?), but I can tell you what's wrong with the current code. First, in order for the width and height property to work, the display property needs to be set to either inline-block or block.
Secondly, the float property does not have a value center. It can only take the values left and right (you need to the first one in this case).
The negative margin trick works like a charm (Explanation in code comments)
.bio {
overflow: hidden; /* Prevent negative margin from leaking out */
}
.bio-inner {
overflow: hidden; /* Clearfix */
margin-left: -1em; /* A) Remove spacing between items when they are against the left side (Must be negative B) */
}
.bio-thumbnail {
height: 3em;
width: auto;
background-color: #a78ffc;
}
.bio-thumbnail,
.bio-info {
float: left;
margin-left: 1em; /* B) Add spacing between items (Must be positive A) */
}
.bio-info-heading {
margin: 0em; /* Just removing default margins */
}
.bio-info-text {
margin-top: 0.5em;
}
<div class="bio">
<div class="bio-inner">
<img class="bio-thumbnail" src="http://i.stack.imgur.com/7bI1Y.jpg">
<div class="bio-info">
<h4 class="bio-info-heading">First Last</h4>
<p class="bio-info-text">This is my bio</p>
</div>
</div>
</div>
This, I have found, works best in cases where screens may be too small to fit the image and text side-by-side.
You can use display: inline-block.
.inline {
display: inline-block;
}
.title {
font-weight: bold;
}
<div>
<div class="inline">
<img src="http://placehold.it/50x50" />
</div>
<div class="inline">
<div class="title">Item 1</div>
<p>Item 1 description</p>
</div>
</div>
<div>
<div class="inline">
<img src="http://placehold.it/50x50" />
</div>
<div class="inline">
<div class="title">Item 2</div>
<p>Item 2 description</p>
</div>
</div>