How to put this Div in center? [duplicate] - html

This question already has answers here:
How do I center floated elements?
(12 answers)
Closed 2 years ago.
Alignment of this div is floating on the left side but I want that to be in center on on desktop browser and in mobile browser too.
It floats on left on desktop browser.
It floats on left on mobile browser.
I just want that to be in center.
<style>
div.logolist {
float: left;
margin: 20;
}
</style>
<div>
<div class="logolist">
<img src="https://i.imgur.com/gCNG37l.png" width="100" height="100" alt="Screen 2">
<p style="text-align:center;">Secure</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/Vc8mFJS.png" width="100" height="100" alt="Screen 3">
<p style="text-align:center;">Guarantee</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/lc7YSqS.png" width="100" height="100" alt="Screen 3">
<p style="text-align:center;">Trust</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/MupBAPH.png" width="100" height="100" alt="Screen 3">
<p style="text-align:center;">Satisfaction</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/vGZi5RJ.png" width="100" height="100" alt="Screen 3">
<p style="text-align:center;">Refund</p>
</div>
</div>

float is designed to move an element to the side and let content that follows it flow up beside it.
It is a terrible tool to try to use for any other kind of layout.
For a long time, it was about the only tool we had for layout, but we've had Flexbox (for single dimension layouts) for years and support for Grid (for two dimension layouts) has good support these days.
Use Flexbox to lay the elements out.
.flex-container {
display: flex;
justify-content: center;
}
.logolist {
text-align: center;
}
<div class="flex-container">
<div class="logolist">
<img src="https://i.imgur.com/gCNG37l.png" width="100" height="100" alt="Screen 2">
<p>Secure</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/Vc8mFJS.png" width="100" height="100" alt="Screen 3">
<p>Guarantee</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/lc7YSqS.png" width="100" height="100" alt="Screen 3">
<p>Trust</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/MupBAPH.png" width="100" height="100" alt="Screen 3">
<p>Satisfaction</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/vGZi5RJ.png" width="100" height="100" alt="Screen 3">
<p>Refund</p>
</div>
</div>
Also, consider representing you list using actual list markup (ul/ol/li) instead of divs. Divs are generic block elements that should only be used as a last resort if no other HTML element has semantics that describe your content.

As another answer mentions, Flexbox is the modern option for laying out data and aligning it. In this case, Flexbox would be the better option, but this is without Flex.
First there is no need for float: left. You can replace with display: inline-block. margin: 0 auto with a width will center the container inside the page. You then add text-align: center to center the content inside the container <div>.
div.logolist {
display: inline-block;
}
.container {
margin: 0 auto;
width: 100%;
text-align: center;
}
<div class="container">
<div class="logolist">
<img src="https://i.imgur.com/gCNG37l.png" width="100" height="100" alt="Screen 2">
<p>Secure</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/Vc8mFJS.png" width="100" height="100" alt="Screen 3">
<p>Guarantee</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/lc7YSqS.png" width="100" height="100" alt="Screen 3">
<p>Trust</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/MupBAPH.png" width="100" height="100" alt="Screen 3">
<p>Satisfaction</p>
</div>
<div class="logolist">
<img src="https://i.imgur.com/vGZi5RJ.png" width="100" height="100" alt="Screen 3">
<p>Refund</p>
</div>
</div>

Related

Add div container around images and center

I am working on a website, and I would like to align 4 circles in the center of the content area. The example can be found at invisionbilling.com/stackoverflow. I have something right now that does the job, but I know there will be issues with different window sizes, different picture sizes, etc. How do I set the height of the div container to automatically wrap around the 4 circles/images? Is there a way to automatically center it using margin-left and margin-right? I tried "auto" for all of these and it wasn't doing the job. Thanks!
HTML
<div class="wrapper">
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Lower-Costs-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-358" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Greater-Cash-Flow-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-363" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Increased-Revenue-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-364" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-
Circles-Emphasis-on-Patient-Care-300x300.png" alt="" width="150"
height="150" class="alignnone size-medium wp-image-361" />
</div>
</div>
CSS
.circles {
display: block !important;
float: left !important;
margin: 10px !important;
}
.wrapper {
height: 175px;
width: 100%;
margin-left: 225px;
}
Try flexbox instead of floating, and try never to use !important:
<!DOCTYPE html>
<html>
<head>
<style>
.circles {
margin: 10px;
}
.wrapper {
height: 175px;
width: 100%;
margin: auto;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Lower-Costs-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-358" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Greater-Cash-Flow-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-363" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Increased-Revenue-300x300.png" alt="" width="150" height="150"
class="alignnone size-medium wp-image-364" />
</div>
<div class="circles">
<img src="http://invisionbilling.com/wp-content/uploads/2018/08/Benefits-Circles-Emphasis-on-Patient-Care-300x300.png" alt="" width="150"
height="150" class="alignnone size-medium wp-image-361" />
</div>
</div>
</body>
</html>

How to align 3 images in an hortizontal row

I have tried different options that I have found in stackoverflow but none of them seems work for my porpouse.
This is what it happend:
Problem description
check this out
#christmas_promotion_boxes {width:1000px; margin:0 auto 0 auto; text-align:center;}
#christmas_promotion_boxes div
{
display:inline-block;
}
<div id="christmas_promotion_boxes">
<div id="christmas_promo_1">
<img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100">
</div>
<div id="christmas_promo_2">
<img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100">
</div>
<div id="christmas_promo_3">
<img src="http://lilliemcferrin.com/wp-content/uploads/2013/09/vivid_flowers-wide.jpg" width="200" height="100">
</div>
</div>

How to have these pictures side by side?

I would like to know how to edit this code to show these pictures centered side by side with each download button centered and underneath each picture, If anybody knows how to edit the code to this, it would be appreciated. Thanks.
The website link that I uploaded the code to, to test it can be seen below:
http://www.tekmillion.com/albums.html
.clearfix {
clear: both;
}
.divWithBtn {
float: left;
text-align: center;
padding: 10px;
}
.divWithBtn img,
.divWithBtn a{
display: block;
margin: 0 auto;
}
<HR>
<div class="container">
</br>
<span class="textformat1"><center><b>Albums</b></span></center>
</br>
<center>
<div class="clear">
<div class="divWithBtn">
<img src="images/london%20To%20Turkey%20-%20Front%20Cover.jpg" alt="london%20To%20Turkey%20-%20Front%20Cover" width="200" height="200">
<a href="LONDON%202%20TURKEY%20VOL.1.zip">
<img src="images/downloadbutton.png" alt="downloadbutton" width="150" height="50"></a>
</div>
<div class="divWithBtn">
<img src="images/LONDON%20TO%20TURKEY%20VOLUME%202%20(FRONT%20COVER).jpg" alt="LONDON%20TO%20TURKEY%20VOLUME%202%20(FRONT %20COVER)" width="200" height="200" border:none;>
<a href="LONDON%202%20TURKEY%20VOL.2.zip">
<img src="images/downloadbutton.png" alt="downloadbutton" width="150" height="50"></a>
</div>
<div class="divWithBtn">
<img src="images/Love%20%26%20Hate%20Volume.1%20(Front%20Cover).JPG" alt="Love%20%26%20Hate%20Volume.1%20(Front %20Cover)" width="200" height="200">
<a href="LOVE%20%26%20HATE%20VOL.1.zip">
<img src="images/downloadbutton.png" alt="downloadbutton" width="150" height="50"></a>
</div>
<div class="divWithBtn">
<img src="images/Gurbet%20Eli%20Volume.1%20(Front%20Cover).JPG" alt="Gurbet%20Eli%20Volume.1%20(Front%20Cover)" width="200" height="200">
<a href="GURBET%20ELI%20VOL.1.zip">
<img src="images/downloadbutton.png" alt="downloadbutton" width="150" height="50"></a>
</div>
</div>
</center>
</br>
Add following css to your code:
This css will make image side by side.
.divWithBtn {
display: inline-block;
}
Following css will make download button below the image.
.divWithBtn > a {
display: block;
}
Hope it helps.
Note: And your current css which you post here is not applied. Make sure it is applied to your html element. Check path for your css file.
add class "display_table" to outer div.
<div class="clear" class="display_table">
add styles for the class "divWithBtn"
.divWithBtn {
float:left;
text-align:center;
margin: 0px 20px;
}
And finally add div to the image tag
<div><img height="200" width="200" src="images/london%20To%20Turkey%20-%20Front%20Cover.jpg" alt="london%20To%20Turkey%20-%20Front%20Cover"></div>
Finall output
<div class="clear" class="display_table">
<div class="divWithBtn">
<div><img height="200" width="200" src="images/london%20To%20Turkey%20-%20Front%20Cover.jpg" alt="london%20To%20Turkey%20-%20Front%20Cover"></div>
<img height="50" width="150" src="images/downloadbutton.png" alt="downloadbutton"> </div>
<div class="divWithBtn">
<div> <img height="200" width="200" src="images/LONDON%20TO%20TURKEY%20VOLUME%202%20(FRONT%20COVER).jpg" alt="LONDON%20TO%20TURKEY%20VOLUME%202%20(FRONT %20COVER)" border:none;=""></div>
<img height="50" width="150" src="images/downloadbutton.png" alt="downloadbutton"> </div>
<div class="divWithBtn">
<div><img height="200" width="200" src="images/Love%20%26%20Hate%20Volume.1%20(Front%20Cover).JPG" alt="Love%20%26%20Hate%20Volume.1%20(Front %20Cover)"></div>
<img height="50" width="150" src="images/downloadbutton.png" alt="downloadbutton"> </div>
<div class="divWithBtn">
<div><img height="200" width="200" src="images/Gurbet%20Eli%20Volume.1%20(Front%20Cover).JPG" alt="Gurbet%20Eli%20Volume.1%20(Front%20Cover)">
<div> <img height="50" width="150" src="images/downloadbutton.png" alt="downloadbutton"> </div>
</div>
</div>
</div>
Css
.display_table { display: table; }
.divWithBtn { float: left; text-align: center; margin: 0px 20px; }

Recomended way to horizontally align elements in div with bootstrap

I want the elements to be side by side and not on top of one another.
When I say best way, I want the elements to not overlap when you change the size of the screen.
Here is my HTML:
<div class="container-fluid" style="text-align:center; background-color: #f6f6ff;">
<div class="col-md-offset-1 col-sm-12 col-md-10" style="background-color: #f6f6ff;">
<img src="media/subversion_logo-384x332.png" alt="Subversion" height="150" width="150">
<h1>2</h1>
<img src="media/github.png" alt="GitHub" height="150" width="150">
</div>
</div>
Here is a picture of what it looks like:
Right now you have an h1 separating the two images. Since heading tags are block level elements by default, it's not possible to line up the images side by side with the h1 separating them. However, if you put each image/heading in their own column, they will line up:
<div class="container-fluid" style="text-align:center; background-color: #f6f6ff;">
<div class="row">
<div class="col-xs-6">
<h1>1</h1>
<img src="http://placehold.it/150x150" alt="Subversion" height="150" width="150">
</div>
<div class="col-xs-6">
<h1>2</h1>
<img src="http://placehold.it/150x150" alt="GitHub" height="150" width="150">
</div>
<div class="clearfix"></div>
</div>
</div>
Bootply
Using the Grid system to scale up to 12 columns, as described here
<div class="row">
<div class="col-md-4">
<img src="media/subversion_logo-384x332.png" alt="Subversion" height="150" width="150">
</div>
<div class="col-md-4">
<h1>2</h1</div>
<div class="col-md-4">
<img src="media/github.png" alt="GitHub" height="150" width="150
</div>
You can change the size of the columns by increasing/decreasing col-md-4
If you want two elements to be side by side, you can use "row" and "col" from the bootstrap grid.
For example, this is how to code 2 images:
<div class="row">
<div class="col-lg-6">
<img src="media/subversion_logo-384x332.png" alt="GitHub" height="150" width="150">
</div>
<div class="col-lg-6">
<img src="media/subversion_logo-384x332.png" alt="GitHub" height="150" width="150">
</div>
</div
The bootstrap answer is the best. I had the same requirement before, only difference being that it was not acceptable to have the content in the different columns visually spread apart too much on large screens. In that case, you would use the original html and use css
.container-fluid div > * {
margin: 0 auto;
display: inline;
}

Converting HTML table over to Divs

I have had a good start at geting my codeded table turned over from a table to Div setup but some where in this part right here it seems to be having a problem. This is what the site should look like: http://db.tt/YeUZiiBy.
Here is the code and CSS Link: http://jsfiddle.net/8WKR9/1/.
Here is my HTML `
<div id="container">
<article>
<div class="item">
<img src="4-cute-cats.jpg" class="centerImage" width="300" height="300"
/>
<p class="centerText">They hunt in packs.</p>
</div>
<div class="item">
<img src="cat_sniping.jpg" class="centerImage" width="256" height="192"
/>
<p class="centerText">Sniper Cat</p>
</a>
</div>
<div class="item">
<img src="LOL1.jpg" class="centerImage" width="300" height="298" />
<p class="centerText">Sneaking Cat</p>
</div>
<div class="item">
<img src="hammercat.jpg" class="centerImage" width="300" height="163"
/>
<p class="centerText">80s Cat</p>
</div>
</article>
<article>
<div class="item">
<img src="kittytrap.jpg" class="centerImage" width="200" height=492 />
<p class="centerText">It's a trap!</p>
</div>
<div class="item">
<img src="chop-cats.jpg" class="centerImage" width="300" height="140"
/>
<p class="centerText">They can strip a car to the frame in under 2:00 minutes.</p>
</div>
<div class="item">
<img src="smartkat.jpg" class="centerImage" width="200" height="338" />
<p class="centerText">Intelligent cat.</p>
</a>
</div>
<div class="item">
<img src="narniacat.jpg" class="centerImage" width="200" height="337"
/>
<p class="centerText">Once a cat of Narnia always a cat of Narnia.</p>
</div>
</article>
<article>
<div class="item">
<img src="lolcats3.jpg" class="centerImage" width="300" height="108" />
<p class="centerText">Tired cat.</p>
</div>
<div class="item">
<img src="lol_cats_1.jpg" class="centerImage" width="300" height="142"
/>
<p class="centerText">Gollum Cat.</p>
</div>
<div class="item">
<img src="Magical-Kitty.png" class="centerImage" width="300" height="180"
/>
<p class="centerText">Super Cat.</p>
</div>
<div class="item">
<img src="sad-kitty.jpg" class="centerImage" width="300" height="188"
/>
<p class="centerText">Sad Kitty.</p>
</div>
</article>
<article>
<div class="item">
<img src="cat-in-your-wallpaper.jpg" class="centerImage" width="300" height="200"
/>
<p class="centerText">Wallpaper cat.</div>
<div class="item">
<img src="thinking-cat.jpg" class="centerImage" width="300" height="475"
/>
<p class="centerText">Thinking cat.</p>
</div>
<div class="item">
<img src="http://3.bp.blogspot.com/_znuneBeHigk/TSOOr5DuoQI/AAAAAAAABFY/-Rpe8S1uRo8/s1600/000.jpg&w=823&h=618&ei=_A4VUfP7L4Gy2QXJ-oHIDQ&zoom=1&ved=1t:3588,r:79,s:0,i:354&iact=rc&dur=2621&sig=108293906633680688065&page=3&tbnh=172&tbnw=231&start=67&ndsp=38&tx=64&ty=72"
class="centerImage" width="300" height="225" />
<p class="centerText">Gamer Kitty.</p>
</div>
<div class="item">
<img src="http://www.dumpaday.com/wp-content/uploads/2013/01/funny-lol-cats-playing-with-toilet-paper1.jpg"
class="centerImage" width="300" height="504" />
<p class="centerText">Couch cat.</p>
</div>
</article>
</article>
<article>
<div class="item"> More Kitties
</div>
</article>
</div>`
I think you had the right idea with the mark up but needed some work on the CSS side of things. The key is to clear your floats or else it the item will go to the next available place. I suggest doing a bit more reading on floating and how they effect block elements and the parent element.
I've done a quick 'bare bones' example for you that you should be able to adapt.
http://jsfiddle.net/ZbfXU/2/
<html></html>
Try setup height in tag img
.item > img {
width: 100%;
height: 100%;
}
you could use max-width and/or max-height on your img tags to make sure they keep ratio instead of transforming.
Go through your code and tidy it up, you've got the right idea of separating into rows then using divs within each row.
Here's one I very quickly mocked up, http://jsfiddle.net/8WKR9/5/ 1st and 3rd height are the same and 2nd and 4th are the same, i'm not getting any display errors so probably best going through your HTML & CSS and tidying it up, that way you can see what each part is doing and work out where it's going wrong, rather than try and find a quick fix, it'll also make your code cleaner and easier to read.
<html></html>