I have one div containing 3 divs.
original
HTML code
.state {
background-color: rgba(233, 234, 237, 0.9);
height: 7vh;
width: 80%;
border-radius: 14px;
margin: 10px 0 15px 80px;
display: flex;
align-items: stretch;
}
.state-main {
text-align: center;
padding-top: 10px;
font-weight: 900;
font-size: 14px;
}
.options {
text-align: right;
margin-bottom: 10px;
}
.owner-image {
border-top-left-radius: 14px;
border-bottom-left-radius: 14px;
}
<div class="state">
<div class="owner">
<img class="owner-image" src="img/uk.jpg">
</div>
<div class="state-main">
<p class="state-name">PENNSYLVANIA</p>
</div>
<div class="options">
<p id="time"></p>
<button>SEND TROOPS</button>
<button>ATTACK</button>
</div>
</div>
Use flexbox (browser support).
.state {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 80px;
background-color: lightgray;
}
.state,
.btns button {
text-transform: uppercase;
}
<div class="state">
<img src="http://placehold.it/150x80/fc0">
<p>
Pennsylvania
</p>
<div class="btns">
<button>Send Troops</button>
<button>Attack</button>
</div>
</div>
**For IE9 and older you'll need to provide a fallback. Whether or not you need to do this depends on target audience.
.State is the div that contains all 3. .state-main is yellow div and should go at the center. .options is green div should go far right. .owner-image is the red div, and should stay at the same place.
Using flex to put the layout into place.
.state {
display: flex;
justify-content: space-between;
}
.state-mail {
text-align: center;
}
<div class="state">
<div class="owner-image">
<img src="http://placehold.it/100x50" />
</div>
<div class="state-main">PENNSYLVANIA</div>
<div class="options"><button>SEND TROOPS</button><button>ATTACK</button></div>
</div>
Related
Looking to align this image on the right with the other text that I have. When I run the code, it pushes the margin down and places the image below the text to the right. Preferably I'd like the image evenly with the top text. Any recommendations to help as well as suggestions for cleaning up code are appreciated.
<div class="main">
<h1 class="awesome" <strong>Welcome!</strong></h1>
<div class="text"<small><p>This website has some subtext that goes here under the main title.</p>
<p>Its a smaller font and the color is lower.</p> </small> </div>
<div class="button1"
<button> Sign Up </button>
</div>
<div class="Image">
<img src="Images/download.jpg"
alt="Rocket"
</div>
</div>
</div>
.main{
display: flex;
flex-direction: column;
flex-wrap: wrap;
background-color: #1F2937;
font-family: 'Roboto';
margin-bottom: 25px;
padding-left: 25px;
}
.awesome{
font-size: 48px;
font-weight: bolder;
color: #f9faf8;
}
.text{
align-self: flex-start;
color: #f9faf8;
}
.button1{
font-family: 'Roboto';
border: black;
border-radius: 8px;
padding: 10px;
width: fit-content;
height: fit-content;
background: #3882f6;
}
.Image{
align-self: flex-end;
}
You can put the text block (heading, text, button) in a container and use flexbox to position it next to the image like the example below. This way you can ommit most of the flex alignment css you had previously.
If you wanted something else, please add a picture of what you are trying to achieve.
.main{
display: flex;
background-color: #1F2937;
font-family: 'Roboto';
margin-bottom: 25px;
padding-left: 25px;
gap: 10px;
}
.awesome{
font-size: 48px;
font-weight: bolder;
color: #f9faf8;
}
.text{
color: #f9faf8;
}
.button1{
font-family: 'Roboto';
border: black;
border-radius: 8px;
padding: 10px;
width: fit-content;
height: fit-content;
background: #3882f6;
}
<div class="main">
<div>
<h1 class="awesome"><strong>Welcome!</strong></h1>
<div class="text">
<small>
<p>This website has some subtext that goes here under the main title.</p>
<p>Its a smaller font and the color is lower.</p>
</small>
<button class="button1"> Sign Up </button>
</div>
</div>
<img src="https://picsum.photos/id/237/300/300" alt="Rocket"/>
</div>
how i want it to look like
how it looks right now
.row2 {
display: flex;
justify-content: space-evenly;
align-items: stretch;
}
.til-col {
flex-basis: 32%;
border: 7px solid #c9c9c9;
border-radius: 30px;
margin: 10px;
position: relative;
overflow: hidden;
padding: 40px;
box-shadow: 5px 5px 20px rgba(92, 91, 91, 0.2);
flex-direction: column;
align-items: center;
}
.til-col img {
width: 50%;
border-radius: 10px;
padding-bottom: 5%;
}
.button {
display: inline-block;
text-decoration: none;
color: #fff;
margin: 12px 34px;
border-radius: 10px;
font-size: 13px;
padding: 0 20px;
background: #012a5d;
position: relative;
cursor: pointer;
}
<div class="row2">
<div class="til-col">
<img src="images/Home/Layer 2-2.svg">
<p>Interact with a TIL timeline showing key moments and events over the years</p>
<a href="classroom.html" class="button">
<h3>TIL Story</h3>
</a>
</div>
<div class="til-col">
<img src="images/Home/Progress.svg">
<p>Discover projects and initiatives that have launched out of TIL to support innovation in learning spaces</p>
<a href="classroom.html" class="button">
<h3>Projects</h3>
</a>
</div>
<div class="til-col">
<img src="images/Home/Report_icons-02 1.svg">
<p>See the transformation of classroom spaces and follow progress over stages of the redesign process</p>
<a href="classroom.html" class="button">
<h3>Classroom Redesign</h3>
</a>
</div>
</div>
I want to make the image of each box aligned with each other, same with the text and the button, like it is presented in the image. Yet everything would follow right after the image, the text ends. I also want to uniform the size of the image, without messing up the proportion, but I don't know how to do so.
Simply adding the below styles to ".til-col" class will achieve the expected result
display: flex;
text-align: center;
Maybe something like this?
P.S. I don't think CSS have something to let you horzionally align several child elements from different blocks.
.row2 {
display: flex;
justify-content: space-evenly;
align-items: stretch;
}
.til-col {
display:flex;
flex-basis: 32%;
border: 7px solid #c9c9c9;
border-radius: 30px;
margin: 10px;
position: relative;
overflow: hidden;
padding: 40px;
box-shadow: 5px 5px 20px rgba(92, 91, 91, 0.2);
flex-direction: column;
align-items: center;
}
.til-col img {
width: 50%;
border-radius: 10px;
padding-bottom: 5%;
}
.til-col > p{
padding-bottom:40px;
}
.button {
display: inline-block;
text-decoration: none;
color: #fff;
margin: 12px 34px;
border-radius: 10px;
font-size: 13px;
padding: 0 20px;
background: #012a5d;
position: absolute;
bottom:20px;
cursor: pointer;
}
<div class="row2">
<div class="til-col">
<img src="images/Home/Layer 2-2.svg">
<p>Interact with a TIL timeline showing key moments and events over the years</p>
<a href="classroom.html" class="button">
<h3>TIL Story</h3>
</a>
</div>
<div class="til-col">
<img src="images/Home/Progress.svg">
<p>Discover projects and initiatives that have launched out of TIL to support innovation in learning spaces</p>
<a href="classroom.html" class="button">
<h3>Projects</h3>
</a>
</div>
<div class="til-col">
<img src="images/Home/Report_icons-02 1.svg">
<p>See the transformation of classroom spaces and follow progress over stages of the redesign process</p>
<a href="classroom.html" class="button">
<h3>Classroom Redesign</h3>
</a>
</div>
</div>
You can follow below code for solution
.row2 {
display: flex;
justify-content: space-evenly;
align-items: stretch;
}
.til-col {
flex-basis: 32%;
border: 7px solid #c9c9c9;
border-radius: 30px;
margin: 10px;
position: relative;
overflow: hidden;
padding: 40px;
box-shadow: 5px 5px 20px rgba(92, 91, 91, 0.2);
flex-direction: column;
align-items: center;
display: flex;
justify-content: space-between;
text-align: center;
}
.til-col img {
width: 50%;
border-radius: 10px;
}
.icon{
display: flex;
align-items: center;
justify-content: center;
height: 150px;
margin-bottom: 30px;
}
.button {
display: inline-block;
text-decoration: none;
color: #fff;
margin: 34px 0 0 0;
border-radius: 10px;
font-size: 13px;
padding: 0 20px;
background: #012a5d;
position: relative;
cursor: pointer;
}
<div class="row2">
<div class="til-col">
<div class="til-col-head">
<div class="icon"><img src="https://dynamic.brandcrowd.com/asset/logo/2a056b05-ac9b-404f-a619-eba59f92ef48/logo-search-grid-1x?v=637631474641000000"></div>
<p>Interact with a TIL timeline showing key moments and events over the years</p>
</div>
<a href="classroom.html" class="button">
<h3>TIL Story</h3>
</a>
</div>
<div class="til-col">
<div class="til-col-head">
<div class="icon"><img src="https://cdn-icons-png.flaticon.com/512/109/109733.png"></div>
<p>Discover projects and initiatives that have launched out of TIL to support innovation in learning spaces</p>
</div>
<a href="classroom.html" class="button">
<h3>Projects</h3>
</a>
</div>
<div class="til-col">
<div class="til-col-head">
<div class="icon"><img src="https://miro.medium.com/max/1268/0*2pi-PJAAVse41Ovk.png"></div>
<p>See the transformation of classroom spaces and follow progress over stages of the redesign process</p>
</div>
<a href="classroom.html" class="button">
<h3>Classroom Redesign</h3>
</a>
</div>
</div>
I want to make header like on the photo:
Now it looks like that:
header
Here is the html code:
<header class="header">
<div class="container">
<nav class="navBar">
<div class="navBar-wrapper">
<div class="img-logo">
<img src="./img/logo.jpg" alt="" srcset=""></div>
<div class="home">Home</div>
<div class="aboutUs">About us</div>
<div class="findSpace">Find space</div>
<div class="share-space">Share space</div>
<div class="promoteSpace">Promote space</div>
</div>
</nav>
</div>
</header>
And here is css:
Is there any way to add space between logo and move the navigation to the left?
body{
font-family:"Poppins",sans-serif;
font-weight: 400;
}
.container{
max-width: 1110px;
margin-left: auto;
margin-right: auto;
}
.header{
height: 112px;
width: 100%;
background: #fff;
filter: drop-shadow(0px 4px 4px rgba(0, 0, 0, 0.25));
}
.navBar-wrapper{
display: flex;
align-items: center;
justify-content: space-between;
}
.navBar-wrapper div{
font-size: 16px;
line-height: 24px;
color: #323232;
margin-top: 28px;
}
.home{
font-weight: 700 !important;
color:#F78434 !important;
}
How can I make a space between logo and nav?
Tried to access second child using nth-child(2), but that didn't work.
Code snippet: https://codesandbox.io/s/agitated-davinci-1dqujt?file=/index.html
You can do that by simply applying margin-right: auto; to the img-logo-container.
Note that this will affect the parent containers justify-content: space-between;, so I would suggest applying another CSS-property such as gap: 10px; to navBar-wrapper.
Alternatively, you could wrap all the links in the navbar inside another container for better control in your navbar.
body {
font-family: "Poppins", sans-serif;
font-weight: 400;
}
.img-logo img {
max-width: 100px;
}
.img-logo {
margin-right: auto;
}
.container {
max-width: 1110px;
margin-left: auto;
margin-right: auto;
}
.header {
height: 112px;
width: 100%;
background: #fff;
filter: drop-shadow(0px 4px 4px rgba(0, 0, 0, 0.25));
}
.navBar-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.navBar-wrapper div {
font-size: 16px;
line-height: 24px;
color: #323232;
margin-top: 28px;
}
.home {
font-weight: 700 !important;
color: #F78434 !important;
}
<header class="header">
<div class="container">
<nav class="navBar">
<div class="navBar-wrapper">
<div class="img-logo">
<img src="https://4m4you.com/wp-content/uploads/2020/06/logo-placeholder.png" alt="" srcset=""></div>
<div class="home">Home</div>
<div class="aboutUs">About us</div>
<div class="findSpace">Find space</div>
<div class="share-space">Share space</div>
<div class="promoteSpace">Promote space</div>
</div>
</nav>
</div>
</header>
I'm trying to layout a footer for my site using Flexbox. There are two columns, each with the same number of items, except for one column is being populated by text in <h4> tags and other links in <a> tags. They are spaced differently on the vertical axis and I can't work out why. I have added some background colours for clarity.
What am I missing?
.footer {
font-family: 'nexa_light', sans-serif;
font-style: normal;
background-color: #003152;
color: white;
}
.footer-container {
background-color: red;
width: 90%;
margin-left: auto;
margin-right: auto;
padding-top: 25px;
padding-left: 30px;
}
.foot-section {
background-color: blue;
margin-bottom: 15px;
}
.foot-content {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-items: flex-start;
justify-content: flex-end;
}
.foot-section a {
/*links*/
color: white;
}
.footer-container>h5 {
/*Copyright*/
margin-left: auto;
margin-right: auto;
margin-top: auto;
font-size: 15px;
}
#media (min-width: 992px) {
.foot-section h2 {
font-size: 20px;
}
.foot-section a,
.foot-section h4 {
font-size: 15px;
}
}
<div class="container-fluid footer">
<div class="footer-container row">
<div class="col-sm-3 foot-section">
<div class="foot-content">
<h2><strong>Company</strong></h2>
<h4>London, UK</h4>
<h4>Logo by X</h4>
<h4>Something else</h4>
</div>
</div>
<div class="col-sm-3 foot-section">
<div class="foot-content">
<h2><strong>Quick Links</strong></h2>
Home
Products
News & Reviews
</div>
</div>
<div class="col-sm-6 foot-section">
<div class="foot-content">
<h2><strong>Contact</strong></h2>
</div>
</div>
<h5>Copyright © X Ltd 2020, All Rights Reserved. |</h5> Privacy Policy
</div>
</div>
Heading elements (such as an h4) tend to have top and bottom margins set in browser default style sheets.
These margins aren't applied to anchor elements (a).
Here are the styles applied to h4 elements in Chrome:
You can see that the top and bottom margins are 1.33em.
"block-start" is the top in horizontal writing mode.
"inline-start" is the side where text begins. It's the left side in LTR.
"-end" refers to the opposite side.
source: § 6.2. Flow-relative Directions
You just need to override the defaults. Add this to your code: h4 { margin: 0; }.
/* NEW */
.foot-section h4 {
margin: 0;
}
.footer {
font-family: 'nexa_light', sans-serif;
font-style: normal;
background-color: #003152;
color: white;
}
.footer-container {
background-color: red;
width: 90%;
margin-left: auto;
margin-right: auto;
padding-top: 25px;
padding-left: 30px;
}
.foot-section {
background-color: blue;
margin-bottom: 15px;
}
.foot-content {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-items: flex-start;
justify-content: flex-end;
}
.foot-section a {
/*links*/
color: white;
}
.footer-container>h5 {
/*Copyright*/
margin-left: auto;
margin-right: auto;
margin-top: auto;
font-size: 15px;
}
#media (min-width: 992px) {
.foot-section h2 {
font-size: 20px;
}
.foot-section a,
.foot-section h4 {
font-size: 15px;
}
<div class="container-fluid footer">
<div class="footer-container row">
<div class="col-sm-3 foot-section">
<div class="foot-content">
<h2><strong>Company</strong></h2>
<h4>London, UK</h4>
<h4>Logo by X</h4>
<h4>Something else</h4>
</div>
</div>
<div class="col-sm-3 foot-section">
<div class="foot-content">
<h2><strong>Quick Links</strong></h2>
Home
Products
News & Reviews
</div>
</div>
<div class="col-sm-6 foot-section">
<div class="foot-content">
<h2><strong>Contact</strong></h2>
</div>
</div>
<h5>Copyright © X Ltd 2020, All Rights Reserved. |</h5> Privacy Policy
</div>
</div>
I have an aurela app that needs to be able to print out labels. On the page with the form there is a hidden div that contains the layout of the label. I want to print only the hidden div and i want it to be stretched(with content) to be ful size of the page in landscape. Currently it only fills a small corner of the page.
JSFiddle Label
This is the CSS i have tryed to get it working. Weird thing is changes to the #page does nothing. I tryed different page sizes but nothing affects the div, it still sits in the one corner.
#media print {
header, footer, .print-hidden {
visibility: hidden;
}
#page {
size: auto;
margin: 0mm;
}
html, body {
height: 100%;
width: 100%;
}
.print-show{
display: block;
position: absolute;
width: 100vw;
height: 100vh;
top:0;
bottom:0;
}
}
This is the aurelia template for the label
<template bindable="firstname, lastname, company, inviter, uniquecode">
<div class="label-container">
<div class="row justify-content-start mx-0 px-1 pt-1">
<div class="text-center">
<img class="label-logo" src="image.png">
<div class="visitor-logo">VISITOR</div>
</div>
</div>
<div class="flex-row text-center label-name">
<div>${firstname}</div>
<div>${lastname}</div>
</div>
<div class="text-center label-company">
${company}
</div>
<div class="row justify-content-between mx-0 px-1">
<div>
<div class="label-guestof">Guest of</div>
<div class="label-inviter">${inviter}</div>
</div>
<span>${uniquecode}</span>
</div>
</div>
And here are the custom css classes for the label:
.label-container{
width: 350px;
height: 188px;
}
.visitor-logo{
font-weight: normal;
font-size: 15px;
color: #505659;
}
.label-name{
font-weight: 600;
font-size: 28px;
color: #2B3033;
}
.label-company{
font-weight: normal;
font-size: 12px;
color: #737B80;
}
.label-guestof{
font-weight: normal;
font-size: 10px;
color: #737B80;
}
.label-inviter{
font-weight: 600;
font-size: 12px;
color: #505659;
}
.label-logo{
height: 28px;
width: 60px;
}
I restyled it a little bit and added a background color for a better check. I hope this is what you're seeking. If not is was kinda fun to do it :P.
<!--index.html-->
<div class="label-container">
<div class="label-container__header mx-0 px-1 pt-1">
<div class="text-center">
<img class="label-logo" src="image.png">
<div class="visitor-logo">VISITOR</div>
</div>
</div>
<div class="label-container__names label-name">
<div>${firstname}</div>
<div>${lastname}</div>
</div>
<div class="label-container__company label-company">
${company}
</div>
<div class="label-container__footer justify-content-between mx-0 px-1">
<div>
<div class="label-guestof">Guest of</div>
<div class="label-inviter">${inviter}</div>
</div>
<span>${uniquecode}</span>
</div>
</div>
// style.css
html, body {
height: 100%;
width: 100%;
}
.label-container {
width: auto;
height: 100%;
background-color: #aaa;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.label-container__header {
display: flex;
justify-content: flex-start;
align-items: flex-start;
}
.label-container__names {
display: flex;
flex-direction: column;
align-items: center;
}
.label-container__company {
display: flex;
justify-content: center;
}
.label-container__footer {
display: flex;
justify-content: flex-end;
}
.visitor-logo{
font-weight: normal;
font-size: 15px;
color: #505659;
}
.label-name{
font-weight: 600;
font-size: 28px;
color: #2B3033;
}
.label-company{
font-weight: normal;
font-size: 12px;
color: #737B80;
}
.label-guestof{
font-weight: normal;
font-size: 10px;
color: #737B80;
}
.label-inviter{
font-weight: 600;
font-size: 12px;
color: #505659;
}
.label-logo{
height: 28px;
width: 60px;
}