I have a block of cards which are arranged within a container like so:
<div class="projekt_wrapper">
<div class="projekt_card">
<div class="projekt_breadcrumb"><span>Headline</span><span>The title</span></div>
<div class="projekt_container">
<h1>Title again - for you</h1>
<p>Caption for the image</p></div>
</div>
<div class="projekt_card">
<div class="projekt_breadcrumb"><span>Headline</span><span>The title</span></div>
<div class="projekt_container">
<h1>Title again - for you</h1>
<p>Caption for the image</p></div>
</div>
<div class="projekt_card">
<div class="projekt_breadcrumb"><span>Headline</span><span>The title</span></div>
<div class="projekt_container">
<h1>Title again - for you</h1>
<p>Caption for the image</p></div>
</div>
</div>
And I want/do arrange these cards with flexbox like so:
.projekt_wrapper{
width:91.68vw;
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 200vh;
max-height: 8000px;
font-size: 0;
}
.projekt_card{
width:50%;
margin:0;
}
.projekt_card *{
max-width:100%;
}
.projekt_container{
background: url(https://dl.dropboxusercontent.com/u/1207766/projekte-digitalready.jpg) no-repeat;
background-size:cover;
min-height:100vh;
padding-top:20vh;
}
.projekt_container h1, .projekt_container p{
color:red;
text-align:center;
max-width:600px;
margin:0 auto;
padding-bottom: 2vh;
}
.projekt_container p{
border-bottom:1px solid red;
padding-bottom:5vh;
}
.projekt_container img{
margin:8vh 48%;
max-width:4vw;
}
You may also have a look at it right here: http://codepen.io/daiaiai/pen/mRGdaR
And there you'll see the problem that I have by them inner-blocks not breaking into a new line correctly. What do I need to do to make it work correctly?
Thanks a lot!
Related
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>
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>
<div class="wrapper" style="border-bottom: 2px solid black;text-align:center;">
<div class="left" style="float:left;">
<img class="styleLogo" src="ss.png">
</div>
<div class="right" style="float:right;">
<a href="home.html">
<img class="styleHome" src="home.png"></a>
</div>
<div class="center" style="text-align:left; margin:0 auto !important; display:inline-block">
<h2 class="heading1">ss</h2>
<h2 class="heading2">yyyy</h2>
<h5 class="subHeading1">jjjjjj</h5>
<h5 class="subHeading2">yyyyyy</h5>
</div>
</div>
This is the code i tried.pls help.i want to make ss.png float to right and home.png float to left and the headings shouls be in the exact center of div with wrapper class.
Using the "float" method:
If you want the center element to ignore the left and right elements and be centered in the viewport regardless of the sizes of the left and right elements, you will need to position the center absolutely to the wrapper (or use javascript to find the widths of left and right and set margins accordingly). See this fiddle
.wrapper {
position: relative;
width: 100%;
border-bottom: 2px solid black;
text-align: center;
}
.left {
float: left;
}
.right {
float: right;
}
.center {
position: absolute;
width: 100%;
margin: 0 auto;
}
.center > h2, .center > h5 {
margin: 0 auto;
}
.clearfloats {
clear: both;
}
<div class="wrapper">
<div class="left">
<img class="styleLogo" src="https://dummyimage.com/170x170">
</div>
<div class="right">
<a href="home.html">
<img class="styleHome" src="https://dummyimage.com/50x45"></a>
</div>
<div class="center">
<h2 class="heading1">ss</h2>
<h2 class="heading2">yyyyyyy</h2>
<h5 class="subHeading1">jjjjjj</h5>
<h5 class="subHeading2">yyyyyyyyyyyy</h5>
</div>
<div class="clearfloats"></div>
</div>
To place the right image at the bottom right of the wrapper you could position it absolutely instead of floating it. Just change the .right class like this:
.right {
position: absolute;
right: 0;
bottom: 0;
}
Using the "CSS Grid" method:
You can eliminate floats and absolute positioning. There are all kinds of options for positioning within the grid. See this jsFiddle
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
border-bottom: 2px solid black;
text-align: center;
}
.left {
justify-self: start;
}
.center {
align-self: center;
}
.right {
align-self: end;
justify-self: end;
}
.center > h2,
.center > h5 {
margin: 0 auto;
}
<div class="wrapper">
<div class="left">
<img class="styleLogo" src="https://dummyimage.com/170x170">
</div>
<div class="center">
<h2 class="heading1">ss</h2>
<h2 class="heading2">yyyyyyy</h2>
<h5 class="subHeading1">jjjjjj</h5>
<h5 class="subHeading2">yyyyyyyyyyyy</h5>
</div>
<div class="right">
<a href="home.html">
<img class="styleHome" src="https://dummyimage.com/50x45"></a>
</div>
</div>
<div class="wrapper" style="border-bottom: 2px solid black;text-align:center;">
<div class="flex" style="display:flex;flex-direction:row;justify-content:center;justify-content:space-between;">
<img class="styleLogo" src="ss.png">
<h2 class="heading1">ss</h2>
<h2 class="heading2">yyyy</h2>
<h5 class="subHeading1">jjjjjj</h5>
<h5 class="subHeading2">yyyyyy</h5>
<img class="styleLogo" src="ss.png">
</div>
</div>
</div>
</div>
</div>
You can make this kind of structure simply using CSS flexbox, just make the div element with class wrapper flexbox and then use the appropriate rules to align your content in it, for example first place the elements in the order you wish them to appear on webpage
<div class="wrapper">
<div class="left">
<img class="styleLogo" src="https://dummyimage.com/300.png/09f/fff">
</div>
<div class="center">
<h2 class="heading1">ss</h2>
<h2 class="heading2">yyyy</h2>
<h5 class="subHeading1">jjjjjj</h5>
<h5 class="subHeading2">yyyyyy</h5>
</div>
<div class="right">
<a href="home.html">
<img class="styleHome" src="https://dummyimage.com/300.png/09f/fff"></a>
</div>
</div>
Then use this CSS to adjust the content according to your need
.wrapper {
display:-webkit-box;
display:-ms-flexbox;
display:flex;
-webkit-box-pack:justify;
-ms-flex-pack:justify;
justify-content:space-between;
border:1px solid #000;
align-items:center;
text-align:center;
}
.left img,
.right img {
width:100%;
}
.center {
min-width:33.33%;
}
You can alter the width of your left, right and center divs according to your wish or accommodate the content, and if you want your content to be centered vertically also then just add one new rule to wrapper div align-items:center;
If you are not familiar with the concept of flexbox then you can visit this resource for more information https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Edit: as per your requirement to make the center div to stay at exact center irrespective of the size and placement of the divs on sides you can use position:absolute; on center div like below:
.wrapper{
display:flex;
justify-content:space-between;
border:1px solid #000;
align-items:center;
text-align:center;
position:relative;
overflow:hidden;
}
.right{
margin-top:auto;
}
.right img{
width:50px;
height:45px;
display:block;
}
.left img{
width:170px;
height:170px;
display:block;
}
.center{
min-width:33.33%;
position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
border:1px solid red;
}
Hope it helps!
I am really struggling with getting a text in the middle of every picture.
My gallery has 50 pictures and each of them has a different size. This is my code but it doesn't work :/ could anyone help, please? All "sample" text should be in the middle of the.
html:
<div class="row">
<div class="column">
<img src="/artbook/1.jpg">
<p> sample </p>
<img src="/artbook/2.jpg">
<p> sample</p>
<img src="/artbook/3.jpg">
<p> sample</p>
<img src="/artbook/4.jpg">
<P> sample </p>
<img src="/artbook/5.jpg">
<P> sample </p>
</div>
</div>
css:
.column img {
margin-top: 10px;
vertical-align: middle;
display: block;
align-content: center;
max-width: 250px;
.column p{
position: absolute;
text-align: center;
z-index: 1;
Something like this should work using an outer div container. It also uses the translate function to properly center the text both vertically and horizontally according to the parent container. One thing to keep in mind is that when you want to position something according to the parent container then the parent container must also be relative or absolute.
Also, by default, a paragraph element has extra padding around it. You may prefer to use a div instead.
.column div.outer {
position: relative;
display: inline-block;
}
.column img {
margin-top: 10px;
vertical-align: middle;
align-content: center;
max-width: 250px;
}
.outer div{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
<div class="row">
<div class="column">
<div class="outer">
<img src="1.jpg">
<div> sample1 </div>
</div>
<div class="outer">
<img src="2.jpg">
<div> sample2</div>
</div>
<div class="outer">
<img src="3.jpg">
<div> sample3</div>
</div>
<div class="outer">
<img src="4.jpg">
<div> sample4 </div>
</div>
<div class="outer">
<img src="5.jpg">
<div> sample5 </div>
</div>
</div>
</div>
Check it out.
First create a holder for your image and text. Give it position:relative.
Now, absolutely position your p element containing text relative to its holder. But extend your p to all sides with top:0; bottom:0; left:0; right:0;. Now p is occupying the whole holder. Just apply display:flex; to it and center the content with justify-content:center; align-items:center.
.holder{
position:relative;
display:inline-block;
}
.holder:hover img{
filter: brightness(100%);
}
.column img {
filter: brightness(45%);
margin-top: 10px;
vertical-align: middle;
display: block;
align-content: center;
max-width: 250px;
}
.column p{
position: absolute;
display:flex;
justify-content:center;
align-items:center;
z-index: 1;
top:0;
bottom:0;
left:0;
right:0;
}
<div class="row">
<div class="column">
<div class='holder'>
<img src="http://via.placeholder.com/350x100">
<p> sample </p>
</div>
<div class='holder'>
<img src="http://via.placeholder.com/350x150">
<p> sample </p>
</div>
</div>
</div>
I have three different div tags (not inside each other) with code so it has one puts words to left, center, or right but the center is very off centered. Here is HTML code:
.desc {
float: right;
color: skyblue;
}
.desc1 {
float: left;
color: skyblue;
}
.desc2 {
text-align: center;
color: skyblue;
}
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
You can use flexbox to fix that,
HTML:
<div class="container">
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
</div>
CSS:
.container{
display: flex;
align-items: center;
justify-content: space-between;
}
Try this
.desc {
text-align: center;
color: skyblue;
width:33%
}
.desc1 {
text-align: center;
color: skyblue;
width:33%
}
.desc2 {
text-align: center;
color: skyblue;
width:33%
}
.desc4{
display: flex
}
<div class="desc4">
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
</div>
Your desc2 contents are technically centered, relative to the remaining space. Your desc (right column) is getting pushed below the rest of your content because it will start floating from the point where the content of desc2 ends.
The easiest solution is to move desc up above desc2 so that the left/right floated items come first, and will start at the same y-position.
After that, if you want to ensure your main content is truly centered, you may need to specify a width for your left/right columns.
What you could do is actually wrap those 3 divs inside another div, and apply a display : flex to this main div, like so :
.main {
display : flex;
justify-content : space-between;
}
.desc {
float: right;
color: skyblue;
}
.desc1 {
float: left;
color: skyblue;
}
.desc2 {
text-align: center;
color: skyblue;
}
<div class="main">
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
</div>
Since the float property have some strange behaviour in some conditions, display : flex is much more appropriate when you want to display several parts side by side. I really recommend you to learn a little bit more about those flex properties, they are really time-saving. I hope it might help you.
I would use a wrapper around the existing divs and define a flexbox for it.
.container {
width: 100%;
height: 100vh;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10%;
}
.desc {
color: skyblue;
}
<div class="container">
<div class="desc">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
</div>
Try this:
.desc2 {
height: 200px;
width: 400px;
color: skyblue;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -200px;
}
Hope this is helpful :)
Try this .
body{
width:900px;
align-items:center;
margin:0 auto;
}
I think it's helps to you.
You can use flexbox for this and define styles for your body or wraps this blocks in container. No need for float here. Demo:
body {
/* become a flex-container */
display: flex;
/* vertically center flex-items */
align-items: center;
/* centering for text, optional here */
text-align: center;
/* occupy all height */
margin: 0;
height: 100vh;
}
/* equal width for children */
body > * {
flex: 1;
}
.desc {
color: skyblue;
}
.desc1 {
color: skyblue;
}
.desc2 {
color: skyblue;
}
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
You could also use the <center> </center> tag. It works quite well for this.
If you dont have to use the float you can simply remove the floats and enclose all your divs in a main div which alligns all text to center:
.desc {
color: skyblue;
}
.desc1 {
color: skyblue;
}
.desc2 {
color: skyblue;
}
.div1{
text-align:center;
}
<div class="div1" >
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
</div>