This question already has answers here:
How to vertically align an image inside a div
(37 answers)
Center image using text-align center?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Closed 2 years ago.
I am trying to create circle cards using HTML and CSS. Upon click I am trying to open a web URL which is working perfectly fine for me.
But then I am not able set the alignment properly.
I tried display: flex to get the images side by side but the space between circle card is more but minimize space?
And I am not able to set the name of the circle in the center of the image. Can anyone please help me how to do this?
.circle {
background: rgba(15, 28, 63, 0.125);
border-radius: 50%;
height: 8em;
object-fit: cover;
width: 8em;
}
h1 {
text-align: center;
}
.row {
display: flex;
}
.circle-one, .circle-two, .circle-three {
flex: 33.33%;
padding: 5px;
}
<div>
<!-- your widget template -->
<h1> Hello World </h1>
<div class="row">
<div class="circle-one">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1555448248-2571daf6344b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" alt="Tyler">
</a>
<h5> Circle One</h5>
</div>
<div class="circle-two">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDk0fQ&auto=format&fit=crop&w=1000&q=80" alt="Tyler">
</a>
<h5> Circle Two</h5>
</div>
<div class="circle-three">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://cdn.pixabay.com/photo/2015/02/24/15/41/dog-647528_960_720.jpg" alt="Tyler">
</a>
<h5>Circle Three</h5>
</div>
</div>
</div>
This is what I get
use display flex
use align-items:center
.circle {
background: rgba(15, 28, 63, 0.125);
border-radius: 50%;
height: 8em;
object-fit: cover;
width: 8em;
}
h1 {text-align: center;}
.row {
display: flex;
align-items:center;
justify-content:space-around;
}
.circle-one, .circle-two, .circle-three {
flex: 33.33%;
padding: 5px;
display:flex;
flex-direction:column;
align-items:center;
}
<div>
<!-- your widget template -->
<h1> Hello World </h1>
<div class="row">
<div class="circle-one">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1555448248-2571daf6344b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" alt="Tyler">
</a>
<h5> Circle One</h5>
</div>
<div class="circle-two">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDk0fQ&auto=format&fit=crop&w=1000&q=80" alt="Tyler">
</a>
<h5> Circle Two</h5>
</div>
<div class="circle-three">
<a href="{{data.my_profile_url}}" target="_blank">
<img class="circle" src="https://cdn.pixabay.com/photo/2015/02/24/15/41/dog-647528_960_720.jpg" alt="Tyler">
</a>
<h5> Circle Three</h5>
</div>
</div>
</div>
well, It is quite a simple task,
can be done in many ways. one of them is,
add div around your text (circle one , circle two, and circle three) and (img + a) tag
and apply css properties to the classes in css.
display: flex;
align-items: center;
justify-content-center;
Related
I've created an image gallery but I am unsure about how to center the images in the middle of the page horizontally and vertically.
<div class="gallery">
<a target="_blank" href="Icon_pyro.jpg">
<img src="Icon_pyro.jpg" alt="Pyro" width="256" height="256">
</a>
<div class="desc">Pyro</div>
</div>
With my CSS classes being
div.gallery {
display: block;
margin: 0 auto;
text-align: center;
}
div.gallery img {
margin: 5px;
}
It shows up stacked on top, I am stumped on how to make them side by side
Current webpage
You can use display:flex property to fix your problem.
I will give you some Idea........................
horizontally center
if you use display:flex; all div elements are show as row. Then if you use justify-content:center; you row element will be center horizontally.
.html
<div class="imageContainer">
<div class="img">
<img src="https://via.placeholder.com/256x256">
</div>
<div class="img">
<img src="https://via.placeholder.com/256x256">
</div>
<div class="img">
<img src="https://via.placeholder.com/256x256">
</div>
</div>
.css
.imageContainer{
display:flex;
justify-content:center;
}
.img{
margin:5px;
}
jsFiddle example
Vertically center
You have to only add align-items: center; and min-height: 100vh;
.imageContainer{
display: flex;
align-items: center;
min-height: 100vh;
}
jsFiddle Example
horizontally and vertically Center.
just add (here has both above css propertise. have a look and get the idea)
.imageContainer{
display:flex;
justify-content:center;
align-items:center;
min-height:100vh;
}
jsFiddle Example
As well as check following example it will show you how to center columns items vertically and horizontally (just added flex-direction:column;)
.imageContainer{
display:flex;
align-items:center;
min-height:100vh;
flex-direction:column;
justify-content:center;
}
jsFiddle Example
Here is the tutorial if you want to follow and get some idea about flex
Can you please check the below code? Hope it will work for you.
You have to add one parent element for all the gallery elements and give flex utility property to that parent. You need to set the height of gallery parent element as per requirements (currently, we have set viewport height for the below demo).
Please refer to this link: https://jsfiddle.net/yudizsolutions/b2fq8dhr/
It sounds like you will want to wrap the images using flex to get them side by side.
In that case, I would create a gallery-wrapper div that wraps around all of your gallery divs. You can style the gallery-wrapper to get flex, which will make it's children side-by-side by default. Also, add justify-content: center, to center things horizontally. Check out this jsFiddle / my updated answer, and consider learning more about Flexbox styling - it's the best.
.gallery-wrapper {
display: flex;
justify-content: center;
}
<body>
<div class="gallery-wrapper">
<div class="gallery">
<a target="_blank" href="Icon_pyro.jpg">
<img src="Icon_pyro.jpg" alt="Pyro" width="256" height="256">
</a>
<div class="desc">Pyro</div>
</div>
<div class="gallery">
<a target="_blank" href="Icon_scout.jpg">
<img src="Icon_scout.jpg" alt="Scout" width="256" height="256">
</a>
<div class="desc">Scout</div>
</div>
<div class="gallery">
<a target="_blank" href="Icon_spy.jpg">
<img src="Icon_spy.jpg" alt="Spy" width="256" height="256">
</a>
<div class="desc">Spy</div>
</div>
<div class="gallery">
<a target="_blank" href="Icon_soldier.jpg">
<img src="Icon_soldier.jpg" alt="Soldier" width="256" height="256">
</a>
<div class="desc">Soldier</div>
</div>
</div>
</body>
Trying to vertically center align text next to an image in a three across grid alignment. Have tried many things but either one of two things happens:
- text vertically center aligns for one row of text, but wraps under the image if there is more than one row of text
- text wraps properly for multiple rows of text, but won't vertically center align, as shown in the provided code
Any suggestions?
.tile-third {
font-size: 18px;
text-transform: uppercase;
float: left;
width: 25%;
margin-right: 1%;
margin-bottom: 1%;
}
.tile-image {
vertical-align:middle;
float:left;
margin-right: 1%;
background-color:#000;
}
.tile-text {
}
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-outside.png"/>
<div class="tile-text">Department Description One (DD1)</div>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-lowimpact.png"/>
<span class="tile-text">Department Description Two</span>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-fun.png"/>
<span class="tile-text">Department Description Three (DD3)</span>
</a>
</div>
the image and the text is inside in an anchor tag,
change the style of the anchor tag to achieve the required.
example,
.tile-third a {
height: 100%;
display: flex;
align-items: center;
}
Is this what you are looking for??
.tile-third {
display: inline-block;
font-size: 18px;
text-transform: uppercase;
width: 30%;
}
.tile-third > a {
align-items: center;
display: flex;
}
.tile-image {
background-color:#000;
margin-right: 2%;
}
.tile-text {
}
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-outside.png"/>
<div class="tile-text">Department Description One (DD1)</div>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-lowimpact.png"/>
<span class="tile-text">Department Description Two</span>
</a>
</div>
<div class="tile-third">
<a href="#">
<img class="tile-image" src="http://acmebeachandbike.com/wp-content/uploads/2016/05/icon-fun.png"/>
<span class="tile-text">Department Description Three (DD3)</span>
</a>
</div>
I set the display value for the <a> tag under the <div class="tile-third"> to flex which is an easy way to get things to properly align.
This allows the <img> and <div> inside the <a> to properly align.
This question already has answers here:
Vertically align text next to an image?
(26 answers)
Closed 4 years ago.
I have added an image and text. Text has 1 <h6> and 2 <p> tags. I tried using float:left but it does not get displayed side by side.
content.js:
<div className="col l4">
<div className="card1">
<img className="javacardimg" src={java} alt="Java" height="65" width="65"></img>
<h6 className="cardtitle1">New Launch</h6>
<p className="cardcontent1">JAVA</p><p></p>
<p className="cardcontent1">Foundations</p>
</div>
</div>
<div className="col l4">
<div className="card2">
<img className="neuralcard" src={neural} alt="Neural Network" height="65" width="65"></img>
<h6 className="cardtitle2">Enroll Now</h6>
<p className="cardcontent2">Neural Newtwork</p><p></p>
<p className="cardcontent2">Foundations</p>
</div>
</div>
css:
.cardcontent{
float: left;
}
.card1 {
width: 100%;
}
.card1 > h6 {
margin: 0px;
}
I want to display New Launch JAVA Foundations on right of image similarly for card2 but current css does not work I tried few css styling but does not work.
Screenshot:
Try to use Flexbox here...and also wrap your right side content into a div for better practice and readability
.card1 {
display: flex;
align-items: flex-start;
}
h6 {
margin-top: 0;
}
.item {
padding-left: 10px;
}
<div class="card1">
<img className="javacardimg" src="http://via.placeholder.com/100x100?text=JAVA" alt="Java">
<div class="item">
<h6 className="cardtitle1">New Launch</h6>
<p className="cardcontent1">JAVA Foundations</p>
</div>
</div>
This question already has answers here:
vertical-align with Bootstrap 3
(26 answers)
Bootstrap how to get text to vertical align in a div container
(3 answers)
Closed 5 years ago.
I'm using Bootstrap v3.2.0 and i have an html structure like this:
<div class="header-seller-profile col-md-12">
<div class="left-header-content col-md-5">
<div class="seller-banner">
<img src="http://bouquet.developers-server.com/pub/media/avatar/banner-image.png" alt="no image">
</div>
</div>
<div class="middle-header-content col-md-4">
<div class="seller-address">
<div class="wefrom">
<a class="cont-name" title="Search" href="http://bouquet.developers-server.com/marketplace/seller/location/shop/dasdasdad?loc=sadasdasd" target="_blank">
<span>sadasdasd</span>
<img class="piccountry" title="View Map" src="http://bouquet.developers-server.com/pub/static/version1504776489/frontend/Mgs/organie/en_US/Webkul_Marketplace/images/country/countryflags/ID.png">
</a>
</div>
</div>
</div>
<div class="right-header-content col-md-3">
<div class="seller-social-media">
<div class="wk-mp-profile-container storename wk-mp-display-block-css">
<a href="//facebook.com/sadasda" target="blank">
<span class="wk-social-icon wk-icon wk-social-icon-fb" title="Check in Facebook"></span>
</a>
<a href="//twitter.com/dasdsadas" target="blank">
<span class="wk-social-icon wk-icon wk-social-icon-tw" title="Check in Twitter"></span>
</a>
</div>
</div>
</div>
</div>
i tried to make the content inside header-seller-profile class align to bottom but it's not working at all, it keeps stick to the top.
here's my css code:
.header-seller-profile{
background-color: #333333;
color: #fff;
display: inline-block;
}
.middle-header-content,right-header-content,left-header-content{
vertical-align: bottom;
}
.seller-banner img{
width: 100%;
}
Are you looking for this ?
https://codepen.io/swapnaranjitanayak/pen/GvaLNJ
CSS:
.header-seller-profile{
background-color: #333333;
color: #fff;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: flex-end;
}
.header-seller-profile img{
vertical-align:bottom;
}
Replace your css
From :
vertical-align: bottom;
To
vertical-align: text-bottom;
I'm trying to recreate this layout with flexbox only:
I'm trying to keep it as simple as possible with minimal markup, however I'm having a hard time vertically centering everything on one line.
What am I doing wrong?
This is the code:
body {
margin: 0;
}
#p {
background: #26272b;
color: white;
display: flex;
align-items: center;
padding: 1rem;
justify-content: space-between;
}
img {
width: 1rem;
}
.pp {
width: 2rem
}
<div id="p">
<div id="pl">
<img src="http://mortenhjort.dk/synchub/imgs/beamed-note.svg" alt="note">
<h4>A Head Full Of Dreams <span>- Coldplay</span></h4>
</div>
<div id="pc">
<a href="#">
<img src="http://mortenhjort.dk/synchub/imgs/previous.svg" alt="Click to go back">
</a>
<a href="#">
<img class="pp" src="http://mortenhjort.dk/synchub/imgs/play.svg" alt="Click to play">
</a>
<!-- <img class="pp" src="http://mortenhjort.dk/synchub/imgs/pause.svg" alt="Click to pause"> -->
<a href="#">
<img src="http://mortenhjort.dk/synchub/imgs/next.svg" alt="Click to skip">
</a>
</div>
<div id="pr"></div>
<time>00:14 / 00:30</time>
<div></div>
This is the JSFiddle: https://jsfiddle.net/h1k8v16g/
Your primary flex container is working to keep flex items vertically centered.
However, the content of the flex items is still in a block formatting context.
Therefore, make the flex items into flex containers with centering:
div { display: flex; align-items: center; }
revised fiddle
Learn more about the scope of a flex formatting context here: https://stackoverflow.com/a/37844240/3597276