Change the div position on desktop - html

I have these 2 divs (footer-txt and footer-img), on the mobile it works perfectly because I want the text on top and the 2 images on the bottom, like side by side.
But when the screen gets wider, I want the 2 images side by side and also the text div. Like a row with the 2 images and the text.
Is there a way that I can do this?
#footer {
background-color: #98AFFF;
}
.footer-txt {
font-size: 14px;
color: #464646;
text-align: left;
}
.footer-img {
display: flex;
gap: 25px;
}
<footer class="text-center text-lg-start" id="footer">
<div class="p-4" id="footer-content">
<div class="pb-2 footer-txt">
PROTESTE
</div>
<div class="pt-4 pb-2 justify-content-center footer-img">
<a href="#">
<img src="images/pag1/Mask group (1).png" alt="Google">
</a>
<a href="#">
<img src="images/pag1/Mask group.png" alt="Google">
</a>
</div>
</div>
</footer>

Well, if i understand correctly you can put this css in id #footer-content:
#footer-content {
display: flex;
flex-direction: row;
}
That way you change the direction of your div to as if it were a row.
If you only need this for when you're not mobile, you can add the following line:
#media screen and (min-width: 960px) {
#footer-content {
display: flex;
flex-direction: row;
}
}

The desired solution can be achieved using either Flex-Box or Grid & Responsive CSS using Media Queries
Flex Box
Grid Layout
Media Query
#footer {
background-color: #98AFFF;
}
#footer-content {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 25px;
}
.footer-txt {
font-size: 14px;
color: #464646;
text-align: left;
}
.footer-img {
display: flex;
gap: 25px;
}
/* Styling for Smaller Screens */
#media screen and (max-width: 500px) {
#footer-content {
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
}
<footer class="text-center text-lg-start" id="footer">
<div class="p-4" id="footer-content">
<div class="pb-2 footer-txt">
PROTESTE
</div>
<div class="pt-4 pb-2 justify-content-center footer-img">
<a href="#">
<img src="images/pag1/Mask group (1).png" alt="Google">
</a>
<a href="#">
<img src="images/pag1/Mask group.png" alt="Google">
</a>
</div>
</div>
</footer>

You have to make the text and both of the images a flex item. You achive this by defining the flex property on the footer-content. All of its direct children are then flex-items.
Very good explanation of flex can be found here:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
If my solution is not what are you looking for you are maybe also looking for breakpoints and media queries for a responsive design.
#footer {
background-color: #98AFFF;
}
.footer-txt {
font-size: 14px;
color: #464646;
text-align: left;
}
#footer-content {
display: flex;
flex-wrap: wrap;
}
<footer id="footer">
<div id="footer-content">
<div class="footer-txt">
PROTESTE
</div>
<div class="footer-img">
<a href="#">
<img src="images/pag1/Mask group (1).png" alt="Google">
</a>
</div>
<div class="footer-img">
<a href="#">
<img src="images/pag1/Mask group.png" alt="Google">
</a>
</div>
</div>
</footer>

Related

How can I align my icons left-horizontally and center-vertically without moving my text?

How can I align my icons left-horizontally and center-vertically without moving my text? For example:
Here is my code:
.leftpanel a {
display: block;
height: 65px;
text-align: center;
/* This also move my icons which I don't want to */
vertical-align: middle;
line-height: 65px;
}
<div class="leftpanel">
<img src="media/logo.png" class="logo">
<img src="media/icons/home.png" class="icons">acceuil
<img src="media/icons/sofa.png" class="icons">le grand salon
<img src="media/icons/shop.png" class="icons">boutique
</div>
You should wrap the text with an element that takes all available space, and also has text-align: center.
.menu a {
display: flex;
align-items: center;
}
.menu a span {
flex: 1;
text-align: center;
}
<div class="leftpanel">
<img src="media/logo.png" class="logo">
<div class="menu">
<a href="acceuil" class="acceuil">
<img src="media/icons/home.png" class="icons">
<span>acceuil</span>
</a>
<a href="le-grand-salon" class="le-grand-salon">
<img src="media/icons/sofa.png" class="icons">
<span>le grand salon</span>
</a>
<a href="boutique" class="boutique">
<img src="media/icons/shop.png" class="icons">
<span>boutique</span>
</a>
</div>
</div>
You can use flexbox to do it. Flexbox solves a lot of problems in general and I suggest you use it for layouts like this.
.leftpanel a {
display: flex;
height: 65px;
align-items: center;
line-height: 65px;
}
.leftpanel a img {
display: block;
flex-grow: 0;
}
.leftpanel a span {
display: block;
flex-grow: 1;
text-align: center;
}
<!-- I put the text in spans so we can style it separately -->
<div class="leftpanel">
<img src="media/logo.png" class="logo">
<img src="media/icons/home.png" class="icons"><span>acceuil</span>
<img src="media/icons/sofa.png" class="icons"><span>le grand salon</span>
<img src="media/icons/shop.png" class="icons"><span>boutique</span>
</div>

Locating picture to the left, but the text centered

I want to have my the picture.png to be exactly on the very left of the title "ribbon", and the text to be centred about the ribbon (regardless of the presence of the picture). I've been struggling with CSS and flex boxes for a lot of time trying to achieve just this effect. Here I'm using some bootstrap classes, but .heading is my class.
That being said, is it actually possible to do all this alignment without using flexbox, but something more natural and simple? Such as maybe something from CSS1, without all those flex boxes?
.heading {
background-color: rgba(15, 156, 199, 0.829);
height: 5%;
display: flex;
text-align: center;
justify-content: space-between;
/* not helpful of course */
}
/* Here's what I'm trying to achieve. I made this by artificially adding the following CSS code: */
.name {
margin-right: 31%;
}
<div class="container-sm">
<div class="card-body">
<div class="heading">
<img class="rounded img-fluid" src="picture.png" alt="...">
<div class="name">
<h4>Web server monitoring and maintenance.</h4>
<div>Monitoring and upgrades.</div>
</div>
</div>
</div>
</div>
Of course I want this to be naturally centred, not artificially.
TL;DR. Make your .name also a flex container.
Please see the code snippet below. I didn't edit the HTML except the placeholder image. The main CSS change is in .name class to make it flex container and have its content vertically centered. Also, its parent .heading styles are a little adjusted to make it work properly.
.heading {
background-color: rgba(15, 156, 199, 0.829);
height: 5%;
display: flex;
text-align: center;
}
img {
width: 50px;
height: 50px;
flex: 0;
}
.name {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h4, div {
margin: 0;
padding: 0;
line-height: 1;
}
<div class="container-sm">
<div class="card-body">
<div class="heading">
<img class="rounded img-fluid" src="https://picsum.photos/50" alt="...">
<div class="name">
<h4>Web server monitoring and maintenance.</h4>
<div>Monitoring and upgrades.</div>
</div>
</div>
</div>
</div>
Bootstrap relies on Flexbox for the alignment and layouts. So it will be odd to avoid using it.
Here is a code snippet that will help you achieve what you want to do.
Helpful links:
Bootstrap Flexbox: Flexbox utility classes
CSS Flexbox: MDN flexbox docs
.heading {
background-color: rgba(15, 156, 199, 0.829);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="container-sm">
<div class="card-body">
<div class="heading d-flex text-center">
<img class="rounded img-fluid" src="picture.png" alt="...">
<div class="name flex-grow-1">
<h4>Web server monitoring and maintenance.</h4>
<p>Monitoring and upgrades.</p>
</div>
</div>
</div>
</div>
Note: Bootstrap is all about pre-made components and utility classes so try to avoid writing custom CSS as much as possible. Another downside of this is that you're repeating yourself and making Bootstrap useless in the manner you're using it.
using flexbox
img,.image {
height:50px;
}
.box {
display: flex;
align-items: center;
width: 100%;
text-align: center;
height:50px;
}
.text-wrapper{
background-color: rgba(15, 156, 199, 0.829);
width:100%;
height:50px;
display: flex;
flex-direction: column;
justify-content: center;
}
.container{
padding:5px;
}
*{
margin:0px;
padding:0px;
}
<div class="container">
<div class="box">
<div class="image">
<img src="https://placekitten.com/640/360" alt="...">
</div>
<div class="text-wrapper">
<div class="text">
<h4>Web server monitoring and maintenance.</h4>
<p>Monitoring and upgrades.</p>
</div>
</div>
</div>
</div>

How can I change size of pictures in a flexbox?

I try to develop website for my portfolio. I want to do something like that :
But I've some problem with the 3 icons for Twitter/Instagram and Deviantart. To put the icons like that, I use the flexbox in html. Currently, I've that :
#conteneur {
display: flex;
justify-content: space-between;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
Test with CodePen here : https://codepen.io/lucbenedet/pen/yLbPMgK
But as you can see, the pictures are too large and when I try to put the pictures to a size of 35px like that :
#conteneur
{
display: flex;
justify-content: space-between;
width: 35px;
}
or
.element1
{
width: 35px;
}
The resize doesn't works...
Someone to show how to do that ?
You can update your CSS with following code.
#conteneur {
display: flex;
justify-content: space-between;
width: 150px;
padding: 10px;
}
#conteneur div img {
width: 35px;
height: 35px;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
You can have some space between icons when you maximize the width of the container
you can reset width on the flex-container to max-content (3 icones shouldnot overflow) and use gap to set a distance in between them.
You could use em for the gap and icon's width to have a coherent render.
Possible example:
#conteneur {
display: flex;
width: max-content;
align-items: center;
margin: auto;
gap: 1.6em;
}
#conteneur div img {
width: 3em;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
possible example from your codepen https://codepen.io/gc-nomade/pen/qBmVjBV

Basic 3 grid layout html/css

So basically I need to create a 3 grid layout which looks like:
-------------------------------------
| Image | The name of logo | > |
-------------------------------------
I have somewhat do this with :
<div class="panel panel-default">
<div class="card-header">
<a class="card-link row" href="/webview/topup">
<p style="font-size: 14sp; margin-bottom: 0">
<img src="../images.png" th:src="#{../images/image.png}" width="10%"
height="10%" style="vertical-align: middle; font-family: 'Barlow', sans-serif;">
The name of logo
<img src="../arrow.png" th:src="#{../arrow.png}" width="2%" height="2%"
style="vertical-align: middle;" align="right";>
</p>
</a>
</div>
</div>
But somehow my arrow is not centered because it only uses align right. How can I make my arrow to be align right and centered at the same time?
Im sorry to ask such basic questions, because Im kinda new to html/css. Thanks.
There are multiple methods to achieve this.
You can use flexbox on the parent:
{
display: flex;
align-items: center;
justify-content: flex-start;
}
and add:
{
margin-left: auto;
}
to the last child. In your example, the arrow.
A good visual introduction/overview of flexbox is available here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
A concrete example of this with your code:
.card-link {
display: flex;
align-items: center;
justify-content: flex-start;
}
.arrow {
margin-left: auto;
width: 1em;
height: 1em;
}
.logo {
width: 2em;
height: 2em;
}
img {
width: 100%;
height: auto
}
<div class="panel panel-default">
<div class="card-header">
<a class="card-link row" href="/webview/topup">
<img class="logo" src="https://via.placeholder.com/150">
<p class="text">The name of logo </p>
<img class="arrow" src="https://via.placeholder.com/150">
</a>
</div>
</div>
This can be done using css "grid" or "flex". You can refer to many
articles related to 'css flex' and 'css grid'. You can easily align
items in both vertical and horizontal. And there are many ways to align items inside a grid. This will be suitable for your case.
.grid {
display: grid;
height: 100px;
background-color: #f9f9f9;
grid-template-columns: auto 1fr auto;
align-items: center;
grid-gap: 20px;
}
<div class="grid">
<div>Image</div>
<div>The name of logo</div>
<div>></div>
</div>

Two part navigation. One centered and the other right aligned

I am using the CSS framework Bulma (first time), though my question might not be Bulma specific, I thought I'd include that just be clear.
I have a navigation bar that has a centered set of links, but also right-align elements. Here is a screenshot:
You can ignore the fixed leaves on the left. I want to know how I can get the cart and the login button to be right aligned whilst having the other bits centre aligned.
Here is a codepen of what I have tried. I just do not know of the proper way to have the car and the login right aligned. I mean I can position absolute them, but that sounds silly.
HTML CODE
<nav class="navbar is-fixed-top">
Products
Our Story
<div id="logo">Logo placeholder</div>
Blog
Contact Us
</nav>
CSS CODE
nav {
display: flex;
width: 100%;
height: 100px;
align-items: center;
justify-content: center;
}
nav a {
text-decoration: none;
color: #194522;
font-weight: bold;
margin: 0 40px;
display: flex;
align-items: center;
}
nav a:hover {
color: #abcf39;
}
How can I get my navigation like that?
Bulma has two regions in its navbar called navbar-startand navbar-end for control of alignment. Just add an additonal class (in my example: navbar-start--centered) to adapt the "start region" to your needs:
.navbar-start--centered {
flex-grow: 1;
justify-content: center;
}
Here a codepen to play with.
Look at it with a wide viewport - it is desktop only. If you want the start region in the viewports center, you could additionally position the "end region" absolutely.
.navbar-start--centered {
flex-grow: 1;
justify-content: center;
}
<nav class="navbar" role="navigation" aria-label="main navigation">
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start navbar-start--centered">
<a class="navbar-item" href="">Products</a>
<a class="navbar-item" href="">Our Story</a>
<a class="navbar-item" href="https://bulma.io">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a>
<a class="navbar-item" href="">Blog</a>
<a class="navbar-item" href="">Contact Us</a>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary">
<span class="icon">
<i class="fas fa-shopping-cart"></i>
</span>
<span>Cart</span>
</a>
<a class="button is-light">
Log in
</a>
</div>
</div>
</div>
</div>
</nav>
You can add an empty element to the left (as a placeholder) and one to the right (to hold the links) and set them to be flex:1.
Then use normal flex positioning to set the contents of the second (right) container to be right aligned.
nav {
display: flex;
width: 100%;
height: 100px;
align-items: center;
justify-content: center;
}
nav a {
text-decoration: none;
color: #194522;
font-weight: bold;
margin: 0 40px;
display: flex;
align-items: center;
}
nav a:hover {
color: #abcf39;
}
.nav-container{
display:flex;
flex:1;
justify-content: flex-end;
}
.nav-container a {
margin:0 10px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" />
<nav class="navbar is-fixed-top">
<div class="nav-container"></div>
Products
Our Story
<div id="logo">Logo placeholder</div>
Blog
Contact Us
<div class="nav-container">
🛒
Login
</div>
</nav>