container is not centering on the page - CSS/HTML [duplicate] - html

This question already has answers here:
How do I center floated elements?
(12 answers)
Closed 1 year ago.
I am having an issue trying to centre the elements within the .footer-strip-container on the page. It doesn't seem to shift to the centre unless I add some side padding for #text-5 element and I am not sure why that is. I want the elements to be centred if the screen is max 1364.
Below is my html and CSS:
#text-5{
width:100% !important;
}
.footer_wrap_inner > .content_wrap{
width:100% !important;
}
.footer-strip-container{
width:100%;
}
.float-child{
width:50%;
float:left;
}
.footer-strip-col1{
text-align:left;
}
.float-text{
font-size:24px;
padding-left:50px;
}
.float-text,
.float-img{
float:left;
}
.footer-strip-col2{
text-align:right;
}
#media only screen and (max-width: 1364px) {
.float-child {
width:100%;
float:none;
clear:right;
}
}
<aside id="text-5" class="widget_number_7 column-1_3 widget widget_text">
<div class="textwidget">
<div class="footer-strip-container">
<div class="float-child">
<div class="footer-strip-col1-text">
<img src="https://shop.balancecoffee.co.uk/wp-content/uploads/2021/07/ezgif.com-gif-maker-1.gif" alt="Join Balance" class="float-img"><br>
<span class="float-text">Join Balance and get 20% off your first order</span>
</div>
<p></p>
</div>
<div class="float-child">
<div class="klaviyo-form-Re6W9v footer-strip-col2 klaviyo-form form-version-cid-2"></div>
</div>
</div>
</div>
</aside>

All you need to do is to add to replace your .footer-strip-container code with this
.footer-strip-container{
width: 50%;
margin: auto;
}
and your div would be centered
if you want your parent container to be 100%
then use this code
#media only screen and (max-width: 1364px) {
.float-child {
width: 50%;
float: none;
clear: right;
margin: auto;
}
}

You shouldn't use float use flexbox instead
.footer-strip-container {
display : flex;
justify-content : center;
width: 100%;
}
.float-child {
max-width : 50%;
}
.footer-strip-col1 {
text-align: left;
}
.footer-strip-col1-text {
display : flex;
align-items : center;
}
.float-text {
font-size: 24px;
padding-left: 50px;
}
.footer-strip-col2 {
text-align: right;
}
<aside id="text-5" class="widget_number_7 column-1_3 widget widget_text">
<div class="textwidget">
<div class="footer-strip-container">
<div class="float-child">
<div class="footer-strip-col1-text">
<img src="https://shop.balancecoffee.co.uk/wp-content/uploads/2021/07/ezgif.com-gif-maker-1.gif"
alt="Join Balance" class="float-img">
<span class="float-text">Join Balance and get 20% off your first order</span>
</div>
<p></p>
</div>
<div class="float-child">
<div class="klaviyo-form-Re6W9v footer-strip-col2 klaviyo-form form-version-cid-2"></div>
</div>
</div>
</div>
</aside>

display:flex will reduce a lot of unnecessary CSS code.
Here's a complete guide on Flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.footer-strip-col1-text {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.float-text {
font-size: 24px;
padding-left: 50px;
text-align: center;
}
/*define media query size, for demonstration I used 991px*/
#media only screen and (max-width: 991px) {
.footer-strip-col1-text {
flex-direction: column;
}
.float-text {
padding-left: 0;
padding-top: 20px;
}
}
<aside id="text-5" class="widget_number_7 column-1_3 widget widget_text">
<div class="textwidget">
<div class="footer-strip-container">
<div class="float-child">
<div class="footer-strip-col1-text">
<img src="https://shop.balancecoffee.co.uk/wp-content/uploads/2021/07/ezgif.com-gif-maker-1.gif" alt="Join Balance" class="float-img">
<span class="float-text">Join Balance and get 20% off your first order</span>
</div>
<p></p>
</div>
<div class="float-child">
<div class="klaviyo-form-Re6W9v footer-strip-col2 klaviyo-form form-version-cid-2"></div>
</div>
</div>
</div>
</aside>

Related

Trying to center opening hours on footer underneath navigation

I am attempting to have our opening days aligned to the left and our hours aligned to the right but sit in the center of our navigation bar. I am using squarespace. Currently I have it like this but not sufficiently close and on the mobile version it looks silly, any help would be appreciated thanks.
HTML Code Block:
<center>
<div class="contactfield">
<div class="contact">
<div class="date">Mon-Wed</div><div class="time">5PM - 11PM</div>
<div class="date">Thu</div><div class="time">12PM - 11PM</div>
<div class="date">Fri-Sat</div><div class="time">12PM - 1AM</div>
<div class="date">Sun</div><div class="time">12PM - 11PM</div>
</div></center>
<center> <span><img class=“sm_icons“ src="https://static1.squarespace.com/static/615e86638bf80f2683975e8f/t/630ff2cac2a9b76708e4df5d/1661989587824/phone.png" width= 12px ></span> 03 8591 3000
<div class="smaller">hello#trinitystkilda.com</div>
</center>
CSS:
p.smaller {
line-height: 0px;
}
p.smaller{
margin-top:-25px;
}
.navbar{
text-align:center;
.header-nav-list{
width: 100%;
max-width:800px;
margin:0 auto;
justify-content:space-evenly;
}
}
p.contact {
line-height: 0px;
}
p.contact{
margin-top:0px;
}
.contact .date{
font-size: 14px;
width:30%;
display:inline-block;
box-sizing:border-box;
text-align:left;
}
.contact .time{
font-size: 14px;
text-align:right;
padding-right:10px;
width:70%;
display:inline-block;
box-sizing:border-box;
}
p.email {
line-height: 0px;
}
p.email{
margin-top:5px;
color: white;
}
Images:
Mobile
Web
Just give your date & time class with some wrapper (Heres I gave wrapper with class name .date-time), and use flex to make the child center.
.contact {
display: flex;
flex-direction: column;;
}
.date-time {
display: flex;
justify-content: space-around;
}
.date, .time {
width: 50%;
text-align: center;
}
<div class="contact">
<div class="date-time">
<div class="date">Mon-Wed</div>
<div class="time">5PM - 11PM</div>
</div>
<div class="date-time">
<div class="date">Thu</div>
<div class="time">12PM - 11PM</div>
</div>
<div class="date-time">
<div class="date">Fri-Sat</div>
<div class="time">12PM - 1AM</div>
</div>
<div class="date-time">
<div class="date">Sun</div>
<div class="time">12PM - 11PM</div>
</div>
</div>

How to centre two images next to each other in css/html [duplicate]

This question already has answers here:
CSS - center two images in css side by side
(5 answers)
How to place two divs next to each other? [duplicate]
(13 answers)
Closed 4 years ago.
I am fairly new to html and css, and I was trying to make two images go side by side in the center of the screen (automatically adjusting themselves when the screen is scaled).
I have only been able to get the two images to go next to each other and not been able to center them or make them automatically scale.
<head>
<style>
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.row::after {
clear: both;
display: table;
}
</style>
</head>
<body>
<div class="row">
<div class="column">
<img src="img_snow.jpg" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="img_forest.jpg" alt="Forest" style="width:100%">
</div>
<div class="column">
<img src="img_mountains.jpg" alt="Mountains" style="width:100%">
</div>
</div>
</body>
</html>
The two images should go next to each other in the centre of the screen, scaling themselves on different sized browser windows and when browser is zoomed in or out. I should be able to change the size of the images to what I need.
Here is a way to do it with flexbox
JSFiddle demo here
* {
height: 100%;
}
img {
display: block;
height: auto;
max-width: 100%;
}
.images {
display: flex;
justify-content: center;
align-items: center;
margin: auto 0;
padding: 0 200px;
}
#media screen and (max-width: 768px) {
.images {
flex-direction: column;
padding: 0;
}
}
<div class="images">
<img src="https://placekitten.com/600/400">
<img src="https://placekitten.com/600/400">
</div>
Add the following css-
body
{
text-align:center;
}
.row
{
display:inline-block;
}
I hope this will help you.
<html>
<head>
<style>
* {
box-sizing: border-box;
}
.ul_class {
width: 100%;
display:block;
text-align: center;
}
.li_class {
width: 33.33%;
display:inline-block;
margin-right: -4px;
}
</style>
</head>
<body>
<ul class="ul_class">
<li class="li_class"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTpVNXBVaIl8ne-AYJfYxls2Js2dcYJohl5e-d3ompbZxrjtzlk" alt="Snow" style="width:100%"></li>
<li class="li_class"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTpVNXBVaIl8ne-AYJfYxls2Js2dcYJohl5e-d3ompbZxrjtzlk" alt="Snow" style="width:100%"></li>
</ul>
</body>
</html>
Use below code in your css.
OR
You can use flex. check below link.
https://www.w3schools.com/cssref/css3_pr_justify-content.asp
.row{ width:80%; margin:0 auto; }
try using flex on the row element
.row {
display: flex;
justify-content: center;
align-items: center;
}

Responsive Image Container

I'm trying to get a set of 8 images (all with same dimensions), to display in-line with equal spacing and respond to browser width.
Starting with 4 images over 2 rows then as the browser width decreases, for them to shrink to a certain point that they are still clearly legible, then move to 2 images over 4 rows. I've noticed that it does this without any styling but it also has a stage in between where it pushes one image down onto a new row, so 3-1-3-1. I want to avoid this.
Here's what I'm currently working with.
.features {
width: 100%;
display: block;
text-align: center;
}
.features img {
width: 220px;
margin: 10px;
}
<div class="features">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-lighweight-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-pocket-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-solar-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-battery-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-apple-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-compatible-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-connector-black.png?9028853389915552257">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-led-black.png?9028853389915552257">
</div>
Hope that makes sense. I'd like to do this just using CSS and HTML assuming that's possible.
A grid system using media queries to set the breakpoints for where you want the columns to change width is what you want. https://codepen.io/anon/pen/EmXrMm
CSS tricks has a good article on rolling your own grids here https://css-tricks.com/dont-overthink-it-grids/.
Or you could do the same using flexbox depending on the support constraints.
Note: border box stops the padding declaration adding additional width to the columns. cf is a clearfix, makes the container grow in size relative to the floated elements inside. Rest is pretty straight forward.
* {
box-sizing: border-box;
}
.cf:after {
content: " ";
display: table;
}
.cf:after {
clear: both;
}
.cf {
*zoom: 1;
}
.features__col {
width: 100%;
float: left;
padding: 15px;
}
.features__col img {
width: 100%;
}
#media (min-width: 400px) {
.features__col {
width: 50%;
}
}
#media (min-width: 800px) {
.features__col {
width: 25%;
}
}
<div class="features cf">
<div class="features__col">
<img src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" alt="" />
</div>
<div class="features__col">
<img src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" alt="" />
</div>
<div class="features__col">
<img src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" alt="" />
</div>
<div class="features__col">
<img src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" alt="" />
</div>
</div>
</div>
if you want the images to shrink you'll need to set some breakpoints with media queries and try using flexbox
.features{
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.features img {
padding: 10px;
width: 310px;
height: 381px;
}
#media all and (max-width: 600px) {
.features img {
width: 50%;
height: 50%;
}
Try This :
.col {
width: 25%;
float: left;
text-align: center;
box-sizing: border-box;
}
#media screen and (max-width: 1285px) {
.col {
width: 50%;
float: left;
}
}
#media screen and (max-width: 670px) {
.col {
width: auto;
float: none;
}
img {
min-width: 220px;
}
}
#media screen and (max-width: 365px) {
img {
width:100%;
}
}
<div class="features">
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-lighweight-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-pocket-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-solar-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-battery-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-apple-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-compatible-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-connector-black.png?9028853389915552257">
</div>
<div class="col">
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-icon-led-
black.png?9028853389915552257">
</div>
</div>

Two images one left one right and center vertically

I have this code, which aligns two images to left and right side of the page with space between:
.center {
width: 100%;
display: table;
}
.leftk {
display: table-cell;
}
.rightk {
display: table-cell;
text-align: right;
vertical-align: middle;
}
<div class="center">
<div class="leftk">
<img src="http://loremflickr.com/300/200" />
</div>
<div class="rightk">
<img src="http://loremflickr.com/400/100" />
</div>
</div>
<span>Text</span>
I tried to do the same with inline-block, but I am unable to align vertically right image to center. Can you please show me a quick example to how to get same result with inline-block?
Edit: If page size is smaller than image width, I want to display them under each other.
Here is how you do it with inline block:
jsFiddle
.center {
font-size: 0; /*remove white space*/
text-align: justify;
}
.center:after {
content: "";
display: inline-block;
width: 100%;
}
.leftk,
.rightk {
font-size: 16px;
display: inline-block;
vertical-align: middle;
}
<div class="center">
<div class="leftk">
<img src="//dummyimage.com/200x200" />
</div>
<div class="rightk">
<img src="//dummyimage.com/100x100" />
</div>
</div>
you can use css3 flexbox instead,
use display:flex instead of display:table
add justify-content:space-between;
it's works fine.
.center {
width: 100%;
display: flex;
justify-content:space-between;
align-items:center;
}
.leftk>img {
width:100px;
height:100px;
}
.rightk>img {
width:50px;
height:50px;
}
<div class="center">
<div class="leftk" style="display: table-cell;">
<img src="https://i.stack.imgur.com/wwy2w.jpg"/>
</div>
<div class="rightk">
<img src="https://i.stack.imgur.com/wwy2w.jpg"/>
</div>
</div>
<span>Text</span>

Extra spacing on eft col content when floating two divs side by side content

I am floating two divs side by side, my problem is the content on the left has a huge space on top. The height otherwise adjusts great. Is there any way to have the content horizontally aligned properly eliminating the huge space? Please see the link provided http://jsfiddle.net/darlene1624/zey0macx/.
<div class="row">
<div class="col">
<div class="event">
<img src="http://ima.gs/800x400.png" alt="event 1" />
</div>
</div>
<div class="col">
<div class="eventdesc">
<div class="eventtitle">
<h2>Carnival Party</h2>
</div><p><strong>Where: </strong>TBA<br>
<strong>When: </strong>19/09/2014<br>
<strong>End Date: </strong>18/12/2014<br>
<strong>Time: </strong>7:00 pm<br>
<strong>Contact: </strong><br></p><br>
<div class="readmore">
Read More
</div>
</div>
.row {
display: table;
}
.col {
display: table-cell;
width: 50%;
padding: 1em;
border-bottom: 1px solid #F5F8F9;
}
.event img{
width:100%;
}
.eventdesc{
padding-left: 15px;
padding-right: 15px;
}
.readmore {
text-align:right;
color: #FBE321;
}
.readmore a{
color: #FBE321;
}
Thanks,
D.
You need to set:
.col {
vertical-align: top;
}
h2 {
margin-top: 0;
line-height: 1em;
}
Fiddle