This question already has answers here:
Center one and right/left align other flexbox element
(11 answers)
Center flex items with one at the end of the row [duplicate]
(3 answers)
Closed 3 years ago.
I have a div that contains two divs inside. First div has to be aligned to the left , second div has to be
aligned to the center relatively parent div.Please could you help me .Here is my jsfiddle : https://jsfiddle.net/armakarma/zy3L9a7h/
html
<div class='test'>
<div class='logo'>logo</div>
<div class='title'> title </div>
</div>
css
.test{
display:flex;
border:1px solid black;
}
.title{
margin: 0 auto;
}
.logo{
width:160px;
border:1px solid red;
}
Related
This question already has answers here:
How do I vertically align text in a div?
(34 answers)
How can I horizontally center an element?
(133 answers)
Closed 2 years ago.
I am trying to put a div in the middle of another div, but always left aligns it.
How I do it easily?
<div>
<div>
<p>This I want center</p>
</div>
</div>
The question is answered with the easiest google search, but the most obvious way is to give them CSS classes and then style them with CSS
<div class="parent">
<div class="child">
<p>Centred</p>
</div>
</div>
And in CSS
.parent{
display: grid;
place-items: center;
background-color: red;
}
.child{
background-color: blue;
}
If it's just text you can use:
text-align: center;
If you want to align the div, give to the div you want to center a margin:auto, but make sure to give it a width first, otherwise it will not work. For example:
width: 500px;
margin: auto;
This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Vertically align text next to an image?
(26 answers)
How to center text vertically with a large font-awesome icon?
(15 answers)
Closed 3 years ago.
The structure is like this:
css
.toolBarHolder {
height: 42px;
line-height: 42px;
}
<div class='toolBarHolder'>
<icon class='toolBarIcon'>near_me</icon>
<span class='toolBarText'>lake area</span>
</div>
with this the span can be vertically centered, but the icon failed.
Just give the properties display:flex; align-items:center; justify-content:center; to .toolBarHolder. There's no need to use line-height;
It would be like this:
css
.toolBarHolder {
height: 42px;
display:flex;
align-items:center;
justify-content:center;
}
P.D.: Since we're using justify-content: center, you will also have to set a width (div content is centered horizontally aswell).
This question already has answers here:
Make a div fill the height of the remaining screen space
(41 answers)
Flexbox: center horizontally and vertically
(14 answers)
How do I vertically center text with CSS? [duplicate]
(37 answers)
How can I vertically align elements in a div?
(28 answers)
Vertically centering a div inside another div [duplicate]
(24 answers)
Closed 4 years ago.
Currently I have something like the following:
<div class="wrapper">
<div id="imageWrapper">
<img src="https://picsum.photos/200/300?image=0" alt="" width="100%">
</div>
<div class="contentWrapper">
<div class="title">
sample
</div>
<div class="summary">
sample
</div>
</div>
</div>
and css:
.wrapper {
border: 1px solid;
height: 600px; //This is for test purposes and will be 100% of available height in flexbox grid
text-align: center;
justify-content:center;
}
.contentWrapper {
display: flex;
align-items: center;
flex-direction: column;
}
I am trying to vertically align the text content but it is refusing to be vertical aligned. I don't want to set any height on the image as don't want to ruin it's aspect ration, but need content to always be aligned in the remaining space left at all screen sizes.
below is a jsfiddle:
https://jsfiddle.net/a4n7drxf/
Any ideas on how to acheive this would be greatly appreciated
This question already has answers here:
What is the best way to clear the CSS style "float"?
(14 answers)
Why doesn't the height of a container element increase if it contains floated elements?
(7 answers)
What methods of ‘clearfix’ can I use?
(29 answers)
Closed 4 years ago.
I have this in my css file and html file.
.prodhome-boxshadow{
padding: 10px;
box-shadow: 5px 10px 18px #888888;
}
.prodhome-category {
width:22%;
float:left;
margin:0 1.65% 3.55%;
}
.prodhome-category img {
max-width:60%;
height:auto;
margin:0 5%;
align-content: center;
}
<div class="prodhome-boxshadow">
<div class="prodhome-category">
<h1>Product-title</h1>
<img src="" />
</div>
</div>
<div class="clearrow"></div>
what I get is the box shadow does not encompass the product title and image. Instead I get the box shadow display above where the products are and ends before the Producttiles are displayed. How can I accomplish this?
This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 9 years ago.
I'm trying to horizontally center a div-block containing images (playing cards placed there by Javascript), but somehow it doesn't work (images are still left-aligned). Here's the HTML:
<div id="dealerarea">
<div id="dealercards">
<!--Images by Javascript-->
</div>
</div>
And here's the CSS:
#dealerarea{
position:absolute;
width:100%;
height:96px;
top:15px;
}
#dealercards{
display: block;
margin-left: auto;
margin-right: auto;
}
What i'm doing wrong? Thanks in advance!
Edit: I can't give a fixed "width" to inner div, because it changes every time (depending on the number of card images).
You need to give your #dealercards a width and margin:0 auto ;
#dealercards
{
display: block;
margin:0 auto;width:200px;
}
DEMO HERE