This question already has an answer here:
Why is a flex item limited to parent size?
(1 answer)
Closed 4 months ago.
.location-text {
font-family: 'Inter';
display: inline-block;
word-break: break-word;
font-style: normal;
font-weight: 700;
font-size: 16px;
line-height: 26px;
align-items: center;
color: #13233A;
}
.list-contact {
display: flex;
}
.icon-address {
width: 22px;
height: 22px;
background: #EAA9A9;
border-radius: 8px;
align-items: center;
display: flex;
justify-content: center;
}
<div class="col-md-3 col-sm-6 col-xs-12 bootCols">
<div class="title location">
<i class="bx bx-location-plus localst"></i>
<span class="location-text">Trụ sở (TP. Vinh)</span>
</div>
<div class="list-contact">
<div class="icon-address">
<img src="./image/home/address.png" alt="">
</div>
<div class="content-address">
<span>Do Something Do Something Do Something Do Something Do Something Do Something Do Something</span>
</div>
</div>
</div>
I have a frame like the following and I want to display flex so that they are on one row:
And I wanted the icon and content to be on the same line so I used display flex and it affected the width of the right icon. Here is my HTML and CSS code:
And this is the result I got:
So is there a way to make the element containing my icon unaffected? Hope to get a solution from you
By default, every flex child has flex-shrink: 1 assigned, which cause them to shrink to its minimum content width when there are no enough space.
To counter that, you just need to manually assign it to 0 so it will keep its assigned size which is 22px.
See more about flex-shrink.
.icon-address {
flex-shrink: 0;
}
.location-text {
font-family: 'Inter';
display: inline-block;
word-break: break-word;
font-style: normal;
font-weight: 700;
font-size: 16px;
line-height: 26px;
align-items: center;
color: #13233A;
}
.list-contact {
display: flex;
}
.icon-address {
width: 22px;
height: 22px;
flex-shrink: 0;
background: #EAA9A9;
border-radius: 8px;
align-items: center;
display: flex;
justify-content: center;
}
<div class="col-md-3 col-sm-6 col-xs-12 bootCols">
<div class="title location">
<i class="bx bx-location-plus localst"></i>
<span class="location-text">Trụ sở (TP. Vinh)</span>
</div>
<div class="list-contact">
<div class="icon-address">
<img src="./image/home/address.png" alt="">
</div>
<div class="content-address">
<span>Do Something Do Something Do Something Do Something Do Something Do Something Do Something</span>
</div>
</div>
</div>
you just need to put the elements correctly, so that the layout is as expected
.location-text{
font-family: 'Inter';
display: inline-block;
word-break: break-word;
font-style: normal;
font-weight: 700;
font-size: 16px;
line-height: 26px;
align-items: center;
color: #13233A;
}
.list-contact{
display: flex;
}
.icon-address{
width: 22px;
height: 22px;
background: #EAA9A9;
border-radius: 8px;
align-items: center;
display: flex;
justify-content: center;
}
.content-address{
width: 200px
}
<div class="col-md-3 col-sm-6 col-xs-12 bootCols">
<div class="title location">
<i class="bx bx-location-plus localst"></i>
<span class="location-text">Trụ sở (TP. Vinh)</span>
</div>
<div class="icon-address">
<img src="./image/home/address.png" alt="">
</div>
<div class="list-contact">
<div class="content-address">
<span>Do Something Do Something Do Something Do Something Do Something Do Something Do Something</span>
</div>
</div>
</div>
Related
I don't know how to center icon with the text. I have SVG + text. I can do it with plain CSS(flex-box) but I have to use bootstrap. Also, I want to center text, so it will be centered as other parts of the webpage, I want it to be aligned vertically
I have this:
I want to get this:
I have tried different solutions but did not come up with a good idea.
So the questions are:
How to make text to be centered to the left so it looks centered?
How to aligned svg icon with the text?
thanks
<section class="perks">
<img src="./media/blueCircle.svg" alt="" />
<div class="container">
<div class="row">
<div class="col perksFirst">Perks of Meetlete</div>
<div class="w-100"></div>
<div class="row perksList">
<div class="col">Access to our secure video platform!</div>
<div class="col">
<img src="./media/2.svg" alt="" />Calls are executed through our
App!
</div>
<div class="w-100"></div>
<div class="col">Metelete calls take place on your time!</div>
<div class="col">None of your information is shared!</div>
<div class="w-100"></div>
<div class="col">Build loyalty with your fans!</div>
<div class="col">Make lifetime memories!</div>
<div class="w-100"></div>
<div class="col">Earn up to 10x more than other platforms!</div>
<div class="col">Meetlete calls are timed!</div>
</div>
<div class="w-100"></div>
<div class="col">
<button class="earlyAccess btn">Early access</button>
<div class="launchDate">Launching 2/14/21!</div>
</div>
</div>
</section>
.perks {
display: flex;
text-align: center;
margin-top: 310px;
position: relative;
}
.perks .earlyAccess {
margin-top: 117px;
}
.perks img {
position: absolute;
left: 0;
top: -50%;
}
.perks .row {
justify-content: center;
}
.perksList {
max-width: 860px;
display: flex;
justify-content: center;
align-items: center;
}
.perksList .col {
font-weight: 600;
font-size: 18px;
display: flex;
align-items: center;
display: flex !important;
text-align: start;
margin-top: 26px;
}
.perksFirst {
margin-bottom: 77px;
font-size: 24px;
font-weight: 700;
}
.launchDate {
font-weight: 700;
font-size: 18px;
margin-top: 26px;
}
In order to align icons with the text you can put them together in a
Or you use bootstrap grid https://getbootstrap.com/docs/4.6/layout/grid/. You could use this easily to render it all dynamically, by putting your text in a list.
You can use text-align: center on the outer div (container) to center all. then text-align left in the inner one (perklist) in case this turns your text all left aligned.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
justify-content: center;
margin: auto;
text-align: left;
margin-top: 10px;
}
.heading {
text-align: center;
padding: .5rem;
}
.heading h3 {
font-size: 24px;
font-weight: 700;
text-transform: capitalize;
}
.card {
background: whitesmoke;
padding: 2rem;
border: darkgrey
}
span {
display: flex;
vertical-align: middle;
padding-top: 1rem;
}
span img {
display: inline-flex;
height: 2rem;
}
span a {
font-size: 18px;
font-weight: 600;
line-height: 2rem;
padding-left: .5rem;
}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solution By Tarak</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="new.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xl-1"></div>
<div class="card col-xl-10 col-sm-12">
<div class="row">
<div class="heading col-12">
<h3>Perks of Meetlete</h3>
</div>
</div>
<div class="row">
<div class="col-xl-6 col-md-12">
<span><img src="./test-tubes.svg" /><a>Access to our secure video platform!</a></span>
<span><img src="./test-tubes.svg" /><a>Metelete calls take place on your time!</a></span>
<span><img src="./test-tubes.svg" /><a>Build loyalty with your fans!</a></span>
<span><img src="./test-tubes.svg" /><a>Earn up to 10x more than other platforms!</a></span>
</div>
<div class="col-xl-6 col-md-12">
<span><img src="./test-tubes.svg" /><a>Calls are executed through our App!</a></span>
<span><img src="./test-tubes.svg" /><a>None of your information is shared!</a></span>
<span><img src="./test-tubes.svg" /><a>Make lifetime memories!</a></span>
<span><img src="./test-tubes.svg" /><a>Meetlete calls are timed!</a></span>
</div>
</div>
</div>
</div>
</div>
</body>
height of span img == line-height of span a (for it to be inline center)
change svg of your choice.
play with styles.
My site looks like this:
DESKTOP:
MOBILE:
However, I need the text to be inline with the middle of the corresponding image (both items centered, so that the subtext isn't off-centered).
My HTML:
<div class="col-lg-3>
<div class="container--wrap">
<div class="inward-text">
<br>
<img src="green-up.png" class="center" style="vertical-align: middle;">
<br>
<span style="color: #9BDDB4; font-family: robotobold; font-size: 30px; vertical-align: middle;" "="">4.51%</span>
<br>
<span style="color: #ffffff; font-family: robotolight; font-weight: lighter; font-size: 15px">from yesterday</span>
<img src="red-up.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<br>
<br>
<br>
<br>
<div id="txtdown">
<span style="color: #EE939C; font-family: robotobold; font-size: 30px; vertical-align: middle;">1.80%</span>
<br>
<span style="color: #ffffff; font-family: robotolight; font-weight: lighter; font-size: 15px">from yesterday</span>
</div>
<img src="flag-ic.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<br>
<br>
<br>
<div id="txtdown">
<span style="color: #AEAEAE; font-family: robotobold; font-size: 30px; vertical-align: middle;">text</span>
<br>
<span style="color: #ffffff; font-family: robotolight; font-weight: lighter; font-size: 15px">subtext</span>
</div>
</div>
</div>
</div>
Relevant CSS:
.container--wrap {
background-color: #000000;
border-radius: 15px;
margin: 5px;
overflow: hidden;
}
.col-lg-3 {
flex: 0 0 25%;
max-width: 25%;
}
.col {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 135px;
}
.inward-text span{
display: inline;
margin-left: 10px;
}
.inward-text img{
margin-left: 80px;
float: left;
}
#txtdown{
margin-top: 10px;
}
How do I do what I want to be doing?
EDIT:
I apologise in advance for the extremely messy <br>s that there are!
br tags it is not the best approach, I try to simplify your solution, block with your image and text should be like there:
<div class="items">
<div class="item red">
<img/>
<div class="item__text">
<span class="percent"></span>
<span class="description"></span>
</div>
</div>
<div class="item green">
<img/>
<div class="item__text">
<span class="percent"></span>
<span class="description"></span>
</div>
</div>
<div class="item grey">
<img/>
<div class="item__text">
<span class="percent"></span>
<span class="description"></span>
</div>
</div>
</div>
CSS
.items {
display: flex;
flex-direction: column;
}
.item {
display: flex;
align-items: center;
}
.item__text {
display: flex;
flex-direction: column;
}
And don't use be, use margin or padding, it is a more flexible and reliable approach.
Html:
<div class="container--wrap">
<div class="inward-text">
<div class="flex">
<img src="green-up.png" class="center" style="vertical-align: middle;">
<div id="txtdown">
<span style="color: #9BDDB4; font-size: 30px; vertical-align: middle;">4.51%</span>
<span style="color: #ffffff; font-weight: lighter; font-size: 15px">from yesterday</span>
</div>
</div>
<div class="flex">
<img src="green-up.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<div id="txtdown">
<span style="color: #EE939C; font-size: 30px; vertical-align: middle;">1.80%</span>
<span style="color: #ffffff; font-weight: lighter; font-size: 15px">from yesterday</span>
</div>
</div>
<div class="flex">
<img src="green-up.png" class="center" style="padding-top: 30px; vertical-align: middle;">
<div id="txtdown">
<span style="color: #AEAEAE; font-size: 30px; vertical-align: middle;">text</span>
<span style="color: #ffffff; font-weight: lighter; font-size: 15px">subtext</span>
</div>
</div>
</div>
</div>
Css:
.container--wrap {
background-color: #000000;
border-radius: 15px;
margin: 5px;
overflow: hidden;
}
.flex {
display: flex;
}
.col-lg-3 {
flex: 0 0 25%;
max-width: 25%;
}
.col {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.inward-text span {
display: inline;
margin-left: 10px;
}
#txtdown {
margin-top: 10px;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
Step 1
Remove all inline styles from each element and place them in CSS, as classes, along these lines:
.percent {
color: #EE939C;
font-family: robotobold;
font-size: 30px;
vertical-align: middle;
}
.detail {
color: #ffffff;
font-family: robotolight;
font-weight: lighter;
font-size: 15px;
}
Step 2
Remove all <br/>s
Step 3
Wrap each of the items as the following markup
<div class="fancy-item"> <!-- your group -->
<img ...>
<div> <!-- flexbox sub-group -->
<span class="percent">1.80%</span>
<span class="detail">from yesterday</span>
</div>
</div>
Add the rest of your CSS:
.fancy-item {
display: flex;
align-items: center;
}
Step 4
Add some bottom margin to .percent or top margin to .detail if you want to set them slightly apart.
You're done!
Note: You don't have to use my class names, use whatever makes sense in your context.
Another note: Steps 1-3 are the most important. They allow you to change all the items at once, if you don't like a particular detail, without having to go through each of them and do the modification. DRY is one of the most important principles in programming.
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;
}
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>
I want to build a simple webpage with two pages of full height.
These two pages have one centered block and a small text (with icon) at the bottom.
Here is an example: https://jsfiddle.net/f93wm58r/
<div id="how-to" class="section how-to">
<div id="title" class="title">title</div>
<div id="code" class=" code">title</div>
<div id="view-more" class="view-more">
<span>View intructions</span>
<br/> <!-- other option ? -->
<i class="fa fa-arrow-down view-more--arrow"></i>
</div>
</div>
<div id="instructions" class="section instructions">
<div id="intructions" class="instructions">instructions</div>
<div id="view-more" class="view-more">
<span>Go back</span><br/>
<i class="fa fa-arrow-up view-more--arrow"></i>
</div>
</div>
body {
font-family: "Source Sans Pro","Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 1.3rem;
background-color: #FFF;
}
.section {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
flex-flow: column wrap;
align-content: space-between;
}
.title {
margin-top: auto;
font-weight: bold;
font-size: 4rem;
}
.view-more {
color: #D1D1D1;
text-align: center;
cursor: pointer;
margin-top: auto;
margin-bottom: 10px;
}
.view-instructions {
margin-top: auto;
}
.view-more--arrow {
font-size: 2rem;
}
As you can see on the second page the text is not centered.
What am I missing?
Extra issue
it's not responsive: try reducing the page and the content will be displayed in two columns
You haven't gave the second page title a margin-top of auto, like you did with .title.
.instructions {
margin-top: auto;
}