I really have a hard time placing a div tag. I need to get my form-box with the yellow border out to the right, and my text Inbound Marketing and subtext in the middle. Can anybody help me through this one?
The text is laying in the div with a green border.
The background picture is laying in the div with a red border
Here is my code what I tried until now.
My code looks like this:
HTML:
<div class="top-area" style="border: 4px solid red;">
<div class="container" style="border: 4px solid green;">
<div class="form-container" style="border: 4px solid yellow;">
<div>
#Umbraco.RenderMacro("Ebook")
</div>
</div>
<h1 class="header-xl center">
#Html.Raw(headerText)
</h1>
<p class="sub-header center">
#Html.Raw(CurrentPage.imageTeaserText)
</p>
</div>
</div>
CSS
.top-area {
position: relative;
text-align: center;
}
.top-area, .top-area > .container {
min-height: 500px;
display: -ms-flexbox;
display: flex;
}
.top-area > .container {
-ms-flex-align: center;
align-items:center;
-ms-flex-pack: center;
justify-content: center;
-ms-flex-direction: column;
flex-direction: column;
}
.top-area p {
margin: 0;
color: #fff;
width: 100%;
}
.top-area .header-xl {
margin-top: 20px;
padding: 0;
}
.top-area .sub-header {
font-weight: 300;
margin-top: 5px;
font-size: 2.8em !important;
}
.form-container {
display: block;
float: right;
float: right;
padding: 20px 0;
width: 320px;
}
I'm not entirely sure that I'm clear on what you're trying to do here, but you can use a display: block; on your .top-area > .container item to move it to the right within the green container. If you wanted it OUTSIDE of the green container and to the right in the red container, then you'd need to move it in the HTML. Right now it's contained in the div with the green border, rather than the red border.
Related
This seems like an easy question but I've been trying to fix it for a couple of hours now and I still cannot find a solution. I have a box with two columns like in here:
p {
margin: 0;
padding: 0;
margin-right: 2px;
}
.container {
padding: 5px;
width: 90%;
height: 200px;
margin: auto;
border: 1px black solid;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
.half {
width: 50%;
}
.left-col {
display: flex;
}
.right-col {
text-align: right;
}
.tooltip {
position: relative;
border: 1px black solid;
border-radius: 100%;
width: 14px;
height: 14px;
font-size: 12px;
display: flex;
justify-content: center;
align-items: center;
}
<div class="container">
<div class="row">
<div class="half">
<div class="left-col">
<p>Username picked on regitration:</p>
<div class="tooltip">?</div>
</div>
</div>
<div class="half">
<p class="right-col">
John WithLongSurname
</p>
</div>
</div>
</div>
The problem is, that when I open the page on mobiles, the text on the left column is too long and it wraps (which is good), but its width still takes a whole column, so the tooltip is not next to the text but in the center of the box (it sticks to the right side of the column). Example:
I tried to add width: min-content to the "label" class, but then the whole paragraph just collapses to the smallest possible width. How can I adjust the width of the paragraph, so it will take only as much width as it needs to, so the tooltip will always be next to it?
It is because you are using display: flex; for the .left-col class. By default it will distribute the width automatically and evenly.
Try the styling below to see if it works:
p {
margin: 0;
padding: 0;
margin-right: 2px;
}
.container {
padding: 5px;
width: 90%;
height: 200px;
margin: auto;
border: 1px black solid;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
.half {
width: 50%;
}
.left-col {
display: inline;
}
.right-col {
text-align: right;
}
.tooltip {
position: relative;
border: 1px black solid;
border-radius: 100%;
width: 14px;
height: 14px;
font-size: 12px;
display: inline;
}
p.label {
width: auto;
}
<div class="container">
<div class="row">
<div class="half">
<div class="left-col">
<p class="label">Username picked on regitration:
<span class="tooltip">?</span>
</p>
</div>
</div>
<div class="half">
<p class="right-col">
John WithLongSurname
</p>
</div>
</div>
</div>
I have problem with my CSS of navigation bar. I want to align items to the center of purple div, but there are spaces between texts. How I can achieve alignment without these spaces?
Screen:
Code:
<div class="navbar">
<h1 class="logo">ab</h1>
<p class="items">O nás</p>
<p class="items">Reference</p>
<p class="items">Blog</p>
</div>
<style>
.navbar{
margin: 30px;
padding: 10px;
height: 100px;
background: red;
display: flex;
}
.navbar .logo{
font-size: 50px;
}
.navbar .items{
float: left;
display: flex;
flex-grow: 1;
justify-content:center;
background: blueviolet;
align-items: center;
}
</style>
The flex-box always takes as much space as it needs to fill the box.
All your p.items are flex and the covered div is also flex.
The p has flex-grow: 1 so they will have the same width inside the covered div.
The solution to this problem is create another div to cover all your items and remove display: flex and flex-grow: 1 from your items class, so the spaces between your text will be removed.
<div class="navbar">
<h1 class="logo">ab</h1>
<div class="d-flex">
<p class="items">O nás</p>
<p class="items">Reference</p>
<p class="items">Blog</p>
</div>
</div>
<style>
.navbar{
margin: 30px;
padding: 10px;
height: 100px;
background: red;
display: flex;
}
.navbar .logo{
font-size: 50px;
}
.navbar .d-flex {
display: flex;
flex-grow: 1;
background: blueviolet;
justify-content: center;
align-items: center;
}
.navbar .items{
margin: 0 10px;
}
</style>
I'm currently designing a header bar for a site I'm working on. I would like the header to show a logo at the left, the title in the center, and the user account on the right.
This mockup is what I'm envisioning. Note that the dotted boxes denote a div.
I've made some progress on creating it in HTML/CSS, but I can't seem to get the title to center to the viewport.
As you can see, the title is centering itself between the logo and the account info divs, instead of centering itself on the viewport. This ends up making the page just look a little bit off, and so I would really like to center the title to the viewport.
Here's my code:
.headerBarArea {
background-color: #7785A2;
border: 0;
padding: 0;
width: 100%;
display: inline-block;
text-align: center;
}
.logoArea {
display: inline;
text-align: center;
float: left;
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.minesLogo {
width: 96px;
}
.titleArea {
display: inline-block;
text-align: center;
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.siteTitle {
color: white;
}
.pageTitle {
color: white;
}
.userAccountArea {
display: inline;
text-align: center;
float: right;
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.userAccountIcon {
float: left;
width: 35px;
}
.userAccountText {
float: right;
}
<div className="headerBarArea">
<div className="logoArea">
<img src="assets/mines_logo_stacked.png" className="minesLogo" />
</div>
<div className="titleArea">
<h2 className="siteTitle">This is my site Title</h2>
<h3 className="pageTitle">Page Title</h3>
</div>
<div className="userAccountArea">
<img src="assets/user_account.png" className="userAccountIcon" />
<span className="UserAccountText">John Smith (Student)</span>
</div>
</div>
Any ideas on what I could do to make the title div centered to the viewport, instead of centering between the two divs?
html code
<div class="flex-container">
<div class="flex-item">1</div>
<div class="align-self-center">
<span class="siteTitle">This is my site Title</span>
<br>
<div class="text-center ">Page Title</div>
</div>
<div class="flex-item align-self-end third-item">3</div>
</div>
CSS code
.flex-container {
/* We first create a flex layout context */
display: flex;
/* Then we define the flow direction
and if we allow the items to wrap
* Remember this is the same as:
* flex-direction: row;
* flex-wrap: wrap;
*/
flex-flow: row wrap;
/* Then we define how is distributed the remaining space */
justify-content: space-between;
}
.flex-item {
background: tomato;
padding: 5px;
width: 200px;
height: 150px;
margin-top: 10px;
line-height: 150px;
color: white;
font-weight: bold;
text-align: center;
}
.third-item {
height: 100px;
}
.text-center{
text-align: center;
}
.align-self-end{
align-self:end;
}
.align-self-center{
align-self:center;
}
code output
code solution
used flex to place the items used .flex-container as parent div where flex items are placed in .justify-content: space-between; is used to place space in between the items. align-self:center; is used to place Page Title at center
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
codepen
.headerBarArea{
display:flex;
justify-content: space-between;
align-items: center
}
It is an easy way to the layout.
you can try it.
Try adding margin-left:auto; and margin-right:auto; to the .titleArea class .
I would suggest using a flex-box though.
Replace your css code with this to make title div centered in all the viewport.
.headerBarArea {
background-color: #7785A2;
border: 0;
padding: 0;
width: 100%;
display:flex;
justify-content: space-between;
}
.logoArea , .titleArea , .userAccountArea {
border: lawngreen;
border-style: dashed;
border-width: 1px;
}
.minesLogo {
width: 96px;
}
.titleArea {
text-align: center;
}
.siteTitle , .pageTitle{
color: white;
}
.userAccountIcon {
float: left;
width: 35px;
}
.userAccountText {
float: right;
}
This question already has answers here:
How to make borders collapse (on a div)?
(8 answers)
Closed 2 years ago.
I am trying to create a table with 3 divs using flex box, but when I add a border to the div's the border isn't lining up on top of the next div. Anyone with an eagle eye spot what I'm missing?
Thanks!
.content div {
width: 350px;
border: solid;
padding: 6px;
}
p {
font-size: medium;
font-weight: 700;
color: #000;
margin-left: 10px;
}
.content {
height: 50px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.red {
display: flex;
align-items: center;
justify-content: center;
}
.green {
display: flex;
align-items: center;
justify-content: center;
}
.blue {
display: flex;
align-items: center;
justify-content: center;
}
<div class="content">
<div class="red"><img src="https://i.ibb.co/7YJB7QC/flag.png" alt="flag" border="0" width="40" height="40">
<p>100% Made in the USA</p>
</div>
<div class="green"><img src="https://i.ibb.co/dmDyGKH/100.png" alt="100" border="0" width="40" height="40">
<p>100% Happiness Guaranteed</p>
</div>
<div class="blue"><img src="https://i.ibb.co/zmK0Jk0/check.png" alt="check" border="0" width="40" height="40">
<p>100% Secure Checkout</p>
</div>
<table>
</table>
</div>
If you are referring to the thick borders its because of the box-model, the borders from each element are right underneath each other making it look like the border is 2px. A good trick is to have no top or bottom borders on each element and then adjust either the first or last one.
This was my solution, I applied a border-bottom of none to all the items and the added the border back to the bottom of the last element.
.content div {
width: 350px;
border: solid;
padding: 6px;
border-bottom: none;
}
.content div:last-child {
border-bottom: solid;
}
.content div {
width: 350px;
border: solid;
padding: 6px;
border-bottom: none;
}
.content div:last-child {
border-bottom: solid;
}
p {
font-size: medium;
font-weight: 700;
color: #000;
margin-left: 10px;
}
.content {
height: 50px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.red {
display: flex;
align-items: center;
justify-content: center;
}
.green {
display: flex;
align-items: center;
justify-content: center;
}
.blue {
display: flex;
align-items: center;
justify-content: center;
}
<div class="content">
<div class="red"><img src="https://i.ibb.co/7YJB7QC/flag.png" alt="flag" border="0" width="40" height="40">
<p>100% Made in the USA</p>
</div>
<div class="green"><img src="https://i.ibb.co/dmDyGKH/100.png" alt="100" border="0" width="40" height="40">
<p>100% Happiness Guaranteed</p>
</div>
<div class="blue"><img src="https://i.ibb.co/zmK0Jk0/check.png" alt="check" border="0" width="40" height="40">
<p>100% Secure Checkout</p>
</div>
</div>
Flexbox items don't collapse borders.
If you want the borders to operate like table borders, display them like table, table-row, and table-cell:
div.content {
width: 350px;
display: table;
text-align: center;
border-spacing: 0;
border-collapse: collapse;
}
div.content div.row {
border: solid 2px black;
display: table-row;
}
div.row p {
display: table-cell;
}
div.content div.row img {
height: 40px;
margin-right: 10px;
vertical-align: middle;
}
<div class="content">
<div class="red row">
<p>
<img src="https://i.ibb.co/7YJB7QC/flag.png" alt="flag"></img>
100% Made in the USA
</p>
</div>
<div class="green row">
<p>
<img src="https://i.ibb.co/dmDyGKH/100.png" alt="100"></img>
100% Happiness Guaranteed
</p>
</div>
<div class="blue row">
<p>
<img src="https://i.ibb.co/zmK0Jk0/check.png" alt="check"></img>
100% Secure Checkout
</p>
</div>
</div>
Try setting a thickness for the border, such as 1px:
.content div {
width: 350px;
border: 1px solid;
padding: 6px;
}
I'm writing something for the new job and I'm having a problem with the progress bar.
I created the bar along with the number represented, ie if the number is 50 then half of the bar will be filled (as usual).
But when I put the bar and the number on the same line (with display: inline-block), the filling of the bar disappears. Without this property, the bar looks right but the number is not aligned to the same height
html:
<div style="width:100%;">
<div class="progress">
<div class="progress-bar" style="width:{{value}}%"></div>
</div>
<span class="value">{{value | number:0}}</span>
</div>
css:
.progress {
height: 0.3rem;
width: 90%;
display: inline-block;
}
.value {
float: right;
display: inline-block;
vertical-align:top;
}
i dont understand the issue.. need your help.
TNX!!!
Why don't you just use the wonders of FlexBox?
If you are unfamiliar with this, here is a link: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Basically you can do the following:
https://jsfiddle.net/nL3pr8vw/2/
* {
padding: 0;
margin: 0;
}
.load {
display: flex;
justify-content: left;
align-items: center;
background: grey;
padding: 5px;
margin: 10px;
width: 300px;
border-radius: 5px;
}
.bar {
width: 45%;
background: red;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
height:25px;
}
p {
color: white;
font-family: Arial;
font-size: 0.5em;
}
<div class="load">
<div class="bar">
<span class="count"><p>45%</p></span>
</div>
</div>
Now with this code, you can just re-arrange the divs and mess around with the FlexBox in the CSS to get your desired result!