How can put the div #box at the same height and 20px at the right of the div #mytext
HTML
<div id="mytext">This is a centered text</div>
<div id="box">
CSS
#mytext {
display: flex;
margin: 0 auto;
width: 450px;
height:280px;
border: 8px solid blue;
border-radius: 10px;
box-sizing: border-box;
outline:none;
resize:none;
font-size:45px;
font-weight:500;
text-align:center;
align-items:center;
background-color:white;
padding:10px;
}
#box {
display:inline-block;
width:90px;
height:280px;
background-color:dimgrey;
border-radius: 8px;
}
https://jsfiddle.net/fredericmarcel/kuv1m851/5/
Thank you for your help.
Wrap the elements and center them.
.wrapper {
text-align: center;
}
#mytext {
display: inline-flex; /* switched from 'flex' */
width: 450px;
height: 280px;
border: 8px solid blue;
border-radius: 10px;
box-sizing: border-box;
outline: none;
resize: none;
font-size: 45px;
font-weight: 500;
text-align: center;
align-items: center;
background-color: white;
padding: 10px;
}
#box {
display: inline-block;
vertical-align: top;
width: 90px;
height: 280px;
background-color: dimgrey;
border-radius: 8px;
}
<div class="wrapper">
<div id="mytext">This is a centered text</div>
<div id="box">
</div>
You can achieve this by wrapping the content in a div with display: flex. Updated fiddle
.container {
display: flex;
}
#mytext {
margin: 0 auto;
width: 450px;
height: 280px;
border: 8px solid blue;
border-radius: 10px;
box-sizing: border-box;
outline: none;
resize: none;
font-size: 45px;
font-weight: 500;
text-align: center;
align-items: center;
background-color: white;
padding: 10px;
}
#box {
display: inline-block;
width: 90px;
height: 280px;
background-color: dimgrey;
border-radius: 8px;
}
<div class="container">
<div id="mytext">This is a centered text</div>
<div id="box"></div>
</div>
If you want the grey box to be aligned 20px to the right you can use this. Note that the container has a set width. It also includes 8px to account for the blue border width:
#container {
background: #cc0000;
margin: 0 auto;
width: 568px;
}
#mytext {
display: flex;
float: left;
width: 450px;
height: 280px;
border: 8px solid blue;
border-radius: 10px;
box-sizing: border-box;
outline: none;
resize: none;
font-size: 45px;
font-weight: 500;
text-align: center;
align-items: center;
background-color: white;
padding: 10px;
}
#box {
float: right;
width: 90px;
height: 280px;
background-color: dimgrey;
border-radius: 8px;
}
<div id="container">
<div id="mytext">This is a centered text</div>
<div id="box"></div>
</div>
Use float:left; instead of display: flex; and display: inline-block;
Related
I am making a sidebar for my site and I want the side bar to fill the rest of the screen but also scroll separate to the right of the screen when it overflows with other elements inside. When I use 100% for the height the element only goes to the height of the last element inside of it.
I am trying to get it to fill the rest of the screen as I stated previously but it only goes to not all the way.
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.main {
margin-left: 345px;
border: 0px solid #ffffff;
padding: 0px 0px;
flex-direction: column;
align-content: center;
text-align: center;
width: 450px;
}
.card {
display: inline-block;
width: 400px;
height: 160px;
background-color: #404040;
border: 1px solid #404040;
border-radius: 4px;
margin: 0px;
margin-top: 20px;
text-decoration: none;
}
.toptext {
display: inline-block;
width: 400px;
height: 45px;
color: #ffffff;
background-color: #ffffff;
border: 1px solid #ffffff;
border-radius: 4px;
margin: 0px;
margin-top: 5px;
text-decoration: none;
text-align: left;
}
.toptext h1 {
font-size: 20px;
margin-left: 0px;
margin-top: 1px;
color: #404040;
}
.toptext p {
font-size: 12px;
margin-left: 0px;
margin-top: -10px;
color: #404040;
}
.flexcolumn {
flex-direction: column;
}
.leftmain {
height: 100%;
width: 325px;
padding: 0px 10px;
flex-direction: column;
align-content: center;
background-color: #333333;
overflow: scroll;
}
.leftmain p {
float: left;
color: #ffffff;
text-align: left;
padding: 0px 10px;
text-decoration: none;
font-size: 12px;
line-height: 25px;
border-radius: 4px;
background-color: #333333;
width: 300px;
}
.leftmain p:hover {
background-color: #404040;
color: #ffffff;
}
.header {
overflow: hidden;
background-color: #404040;
padding: 10px 10px;
height: 36px;
text-align: center;
}
.header-right {
float: right;
padding: 0px 0px;
}
.header a {
float: left;
color: #ffffff;
text-align: center;
padding: 5px 10px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
align-content: center;
}
.header a:hover {
background-color: #333333;
color: #ffffff;
}
<div class="header">
📄 My Paper Company
<div class="header-right">
Settings
Contact
Donate
<div class="flexcolumn">
</div>
</div>
</div>
<div id="leftmain" class="leftmain">
<p id="button" div="leftmain" onclick='show("htpmain")'>📢 How To Play</p>
</div>
<center>
<div id=htpmain class="main">
<div class="toptext">
<h1>
📢 How To Play
</h1>
<p>This guide will get you start the game and will be helpful to grasp everything you need to do.
</p>
</div>
<div class="card" />
</div>
</center>
Your leftmain IS taking up 100% of the space available to it, leftmain stops when it reaches . You have leftmain set to flex-direction: column;
when only the .main should have it. Also don't use the tag, it is no longer supported in HTML5 and is display: block; when it should be inline-block.
I would change just to and set display to inline-block and set a width so the leftmain has room to go past it.
I hope this solves your problem.
.leftmain {
height: 100%;
width: 325px;
padding: 0px 10px;
align-content: center;
background-color: #333333;
overflow: scroll;
}
#nameOfCenterDiv {
position: absolute;
left: 300px;
display: inline-block;
}
Give to the sidebar a position fixed so it always stays there wherever you scroll and and a margin-left to your content on the right (the width of the margin-left must be the same of sidebar width)
.leftmain{
position: fixed
}
.main{
margin-left: 345px;
width: 450px //remove this so it's 100%
}
You have to wrap the left sidebar and right panel within the same container.
Using the display: flex on the container, you no longer need to specify a 100% height for the left sidebar since it will automatically fill in the remaining space.
You also need to remove the margin-left rule for the right content so that it lays nicely with the sidebar.
You can optionally set a max-height of 100vh to the sidebar so that it scrolls when its content exceeds the viewport height.
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.main {
border: 0px solid #ffffff;
padding: 0px 0px;
flex-direction: column;
align-content: center;
text-align: center;
width: 450px;
}
.card {
display: inline-block;
width: 400px;
height: 160px;
background-color: #404040;
border: 1px solid #404040;
border-radius: 4px;
margin: 0px;
margin-top: 20px;
text-decoration: none;
}
.toptext {
display: inline-block;
width: 400px;
height: 45px;
color: #ffffff;
background-color: #ffffff;
border: 1px solid #ffffff;
border-radius: 4px;
margin: 0px;
margin-top: 5px;
text-decoration: none;
text-align: left;
}
.toptext h1 {
font-size: 20px;
margin-left: 0px;
margin-top: 1px;
color: #404040;
}
.toptext p {
font-size: 12px;
margin-left: 0px;
margin-top: -10px;
color: #404040;
}
.flexcolumn {
flex-direction: column;
}
.container {
display: flex;
}
.leftmain {
width: 325px;
padding: 0px 10px;
flex-direction: column;
align-content: center;
background-color: #333333;
overflow: scroll;
}
.leftmain p {
float: left;
color: #ffffff;
text-align: left;
padding: 0px 10px;
text-decoration: none;
font-size: 12px;
line-height: 25px;
border-radius: 4px;
background-color: #333333;
width: 300px;
}
.leftmain p:hover {
background-color: #404040;
color: #ffffff;
}
.header {
overflow: hidden;
background-color: #404040;
padding: 10px 10px;
height: 36px;
text-align: center;
}
.header-right {
float: right;
padding: 0px 0px;
}
.header a {
float: left;
color: #ffffff;
text-align: center;
padding: 5px 10px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
align-content: center;
}
.header a:hover {
background-color: #333333;
color: #ffffff;
}
<div class="header">
📄 My Paper Company
<div class="header-right">
Settings
Contact
Donate
<div class="flexcolumn">
</div>
</div>
</div>
<div class="container">
<div id="leftmain" class="leftmain">
<p id="button" div="leftmain" onclick='show("htpmain")'>📢 How To Play</p>
</div>
<center>
<div id=htpmain class="main">
<div class="toptext">
<h1>
📢 How To Play
</h1>
<p>This guide will get you start the game and will be helpful to grasp everything you need to do.
</p>
</div>
<div class="card" />
</div>
</center>
</div>
In This Code,I want to set the margin-top of .Login class ,smaller,although I set The margin-top ,to zero,but it is not set near to the top of page.What Can I do?why by setting the margin-top of this division ,this div does not set ,near the top of page?is other thing ok?the other elements works properly.
body {
margin: 0px;
direction: rtl;
}
#font-face {
src: url('../fonts/IRANSansWeb.eot'), url('../fonts/IRANSansWeb.woff'), url('../fonts/IRANSansWeb.woff2'), url('../fonts/IRANSansWeb.ttf');
font-family: "IranSans";
}
header {
width: 100%;
min-height: 700px;
height: auto;
overflow: auto;
background-color: #007bff;
}
nav {
margin-top: 0px;
height: 50px;
}
nav ul {
width: 60%;
height: 60px;
margin: 0px auto;
border: 2px solid black;
display: inline-block;
}
.Logo {
width: 160px;
height: 50px;
margin-left: 0px;
margin-right: 30px;
margin-bottom: 0px;
display: inline-block;
}
.Logo img {
width: 100%;
height: 100%;
}
.LogIn {
width: 140px;
height: 50px;
display: inline-block;
margin-right: 130px;
margin-top: 0px;
font-family: "IranSans";
border-radius: 5px;
background-color: #00d363;
}
.LogInA {
width: 100%;
height: 100%;
border: 5px;
color: #fff;
display: inline-block;
text-decoration: none;
text-align: center;
line-height: 50px;
}
.LogInA:hover {
border-radius: 5px;
background-color: #007bff;
color: #00d363;
border: 1px solid #00d363;
}
<body>
<header>
<nav>
<div class="Logo"><img src="Content/img/logo.png" alt="جاب بورد"></div>
<ul>
</ul>
<div class="LogIn">
<a class="LogInA" href="#">ارسال شغل</a>
</div>
</nav>
</header>
</body>
Try adding display: flex; to your nav
You should use:
display:flex; justify-content: center; to your Nav and also you should remove height and use: flex-direction:column; in mobile version.
I have been trying to align some text inside a circle in my webpage.
So far i have been able to come up with the following:
From looking at it, it's not the best solution so I was wondering if you have any recommendation how to make sure that the text "LM" or "TM" is perfectly centered inside the circle (if that's possible).
Here is the fiddle:
Sample Demo
html:
.performance-box-container {
margin: 5px;
padding: 5px;
}
.performance-box {
width: 120px;
height: 60px;
margin: 0px 5px 5px 0px;
padding: 5px 5px 10px 5px;
border: 2px solid #868686;
background-color: rgba(202, 202, 202, 0.5);
display: inline-block;
}
.performance-box-name-in-circle {
height: 40px;
width: 40px;
border: 2px solid #000;
background-color: #fff;
border-radius: 50%;
font-weight: bold;
font-size: 12px;
display: inline-block;
}
.performance-box-name-in-circle span {
display: table-cell;
vertical-align: middle;
height: 40px;
width: 40px;
text-align: center;
padding: 0;
margin: 0;
}
.performance-box-stats {
margin-left: 5px;
font-size: 10px;
font-weight: bold;
display: inline-block;
}
.performance-box-stats p {
line-height: 1.5;
margin: 0;
}
.performance-box-stats span.positive {
color: #388C00;
}
.performance-box-stats span.unchanged {
color: #000;
}
.performance-box-stats span.negative {
color: #f00;
}
<div class="performance-box-container">
<div class="performance-box">
<div class="performance-box-name-in-circle">
<span>TM</span>
</div>
<div class="performance-box-stats">
<p>DTD: <span class="positive">+3.5%</span></p>
<p>MTD: <span class="unchanged">+0.0%</span></p>
<p>YTD: <span class="negative">-4.5%</span></p>
</div>
</div>
<div class="performance-box">
<div class="performance-box-name-in-circle">
<span>LM</span>
</div>
<div class="performance-box-stats">
<p>DTD: <span class="positive">+3.5%</span></p>
<p>MTD: <span class="unchanged">+0.0%</span></p>
<p>YTD: <span class="negative">-4.5%</span></p>
</div>
</div>
</div>
You can vertically and horizontally align them center using flexbox
display: flex;
justify-content: center;
align-items: center;
.performance-box-name-in-circle,
.performance-box-name-in-circle span {
display: flex;
justify-content: center;
align-items: center;
}
.performance-box-name-in-circle {
height: 40px;
width: 40px;
border: 2px solid #000;
background-color: #fff;
border-radius: 50%;
font-weight: bold;
font-size: 12px;
}
<div class="performance-box-name-in-circle">
<span>LM</span>
</div>
Here is the Updated JSFiddle
Used flexbox to display performance-box-name-in-circle and performance-box-stats side by side and used below css to place span in the center of the circle. Hope this helps. thanks
margin: 50%;
display: inline-block;
transform: translate(-50%, -50%);
.performance-box-container {
margin: 5px;
padding: 5px;
display: flex;
}
.performance-box {
width: 120px;
/* height: 60px; */
margin: 0px 5px 5px 0px;
padding: 5px 5px 10px 5px;
border: 2px solid #868686;
background-color: rgba(202, 202, 202, 0.5);
/* display: inline-block; */
display: flex;
justify-content: center;
align-items: center;
}
.performance-box-name-in-circle {
height: 40px;
width: 40px;
border: 2px solid #000;
background-color: #fff;
border-radius: 50%;
font-weight: bold;
font-size: 12px;
display: inline-block;
}
.performance-box-name-in-circle span {
display: table-cell;
*/
/* vertical-align: middle; */
/* height: 40px; */
/* width: 40px; */
/* text-align: center; */
padding: 0;
margin: 0;
margin: 50%;
/* margin-top: 80px; */
display: inline-block;
transform: translate(-50%, -50%);
}
.performance-box-stats {
margin-left: 5px;
font-size: 10px;
font-weight: bold;
display: inline-block;
}
.performance-box-stats p {
line-height: 1.5;
margin: 0;
}
.performance-box-stats span.positive {
color: #388C00;
}
.performance-box-stats span.unchanged {
color: #000;
}
.performance-box-stats span.negative {
color: #f00;
}
<body>
<div class="performance-box-container">
<div class="performance-box">
<div class="performance-box-name-in-circle">
<span>TM</span>
</div>
<div class="performance-box-stats">
<p>DTD: <span class="positive">+3.5%</span></p>
<p>MTD: <span class="unchanged">+0.0%</span></p>
<p>YTD: <span class="negative">-4.5%</span></p>
</div>
</div>
<div class="performance-box">
<div class="performance-box-name-in-circle">
<span>LM</span>
</div>
<div class="performance-box-stats">
<p>DTD: <span class="positive">+3.5%</span></p>
<p>MTD: <span class="unchanged">+0.0%</span></p>
<p>YTD: <span class="negative">-4.5%</span></p>
</div>
</div>
</div>
</body>
I have been working on re-doing my fathers website that was created in the nineties (ugh) and I have been having trouble getting the text to fit inside of a div and align horizontally. I need the text to sit next to each other so they fit in the div. Here's the code for the page in a jsfiddle
Example HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body>
<div>
<img id="header" src="http://www.salesprofessionalsinc.com/images/new%20logo.jpg">
</div>
<div id="links">
<div class="home">
<span></span>Home
</div>
<div class="home">
<span></span>Inside Staff
</div>
<div class="home">
<span></span>Our Mission
</div>
</div>
Example CSS
div img#header{
width: 50%;
height: 15%;
margin-left: 125px;
margin-right: auto;
}center input#search{
width: 300px;
height: 45px;
border: solid 1px black;
margin-top: 55px;
font-size: 25px;
}center button#searchbutt{
border: solid 1px black;
width: 65px;
height: 30px;
}#searchbutt:hover{
color: #FFF;
background-color: #000;
}#searchbutt{
background-color: #FFF;
color: #000;
}#links{
height: 40px;
width: 100%;
text-align: center;
line-height: 40px;
}.home{
width: 80px;
text-align: center;
height: 40px;
background-color: white;
color: black;
padding-left: auto;
padding-right: auto;
display: inline-block;
border: solid 1px black;
vertical-align: middle;
}.DL{
width: 95;
text-decoration: none;
text-align: center;
height: 40px;
background-color: white;
color: black;
padding-left: auto;
padding-right: auto;
display: inline-block;
border: solid 1px black;
}.home a{
text-decoration: none;
color: gray;
}.DL a{
text-decoration: none;
color: gray;
}div center a#DLbutt{
border: solid 1px black;
width: 100px;
height: 50px;
background-color: black;
}div center a#DLbutt{
text-decoration: none;
color: gray;
}#download{
padding-top: 30px;
}html{
background-image: url("watermark.gif");
}.home a span{
position:absolute;
width:100%;
height:100%;
top:0;
left: 0;
display: inline-block;
vertical-align: middle;
line-height: normal;
}
I need the "Our Mission part" to be in the same div.
You need to set the display to be display: table-cell for div.home and then remove the line-height you have set for these. This should automatically align the text for you.
div img#header {
width: 50%;
height: 15%;
margin-left: 125px;
margin-right: auto;
}
#links {
height: 40px;
margin-left: 125px;
text-align: center;
display: inline-block;
}
.home {
width: 80px;
text-align: center;
height: 40px;
background-color: white;
color: black;
padding-left: auto;
padding-right: auto;
display: table-cell;
border: solid 1px black;
vertical-align: middle;
}
.home a {
text-decoration: none;
color: gray;
}
http://jsfiddle.net/03syn1to/
I believe this is what you are asking for. You want the "Our Mission" to be in the button vertically. Just update with this code. And it should work. Let me know what you think.
.home{
width: 80px;
text-align: center;
height: relative;
background-color: white;
color: black;
padding-left: auto;
padding-right: auto;
display: inline-block;
border: solid 1px black;
vertical-align: middle;
}
I changed the height.. height: relative;
I’m looking for a way to make sure that all label have the same space to the bottom border. (It should look like the image, and not like the fiddle)
JsFiddle
Goal:
My CSS:
.outerDiv {
text-align: center;
/*display: inline-block;*/
float: left;
border-radius: 10px;
border: 2px solid #c3c3c3;
height: 100px;
width: 100px;
margin: 5px;
}
.innerDiv {
width: 80%;
height: 100%;
line-height: 50px;
margin: 0 auto;
}
.errorLabel {
background-color: #a90329;
padding: .2em .6em .3em;
font-size: 100%;
color: #fff;
border-radius: .25em;
line-height: 1;
vertical-align: baseline;
font-weight: 700;
text-align: center;
white-space: nowrap;
box-sizing: border-box;
overflow: hidden;
display: block;
}
Your vertical-align doesn't have any affect due to your display: block.
Try changing vertical-align to "bottom" and display to "inline-block". Then adjust your bottom margin/padding to your desire!
.errorLabel {
background-color: #a90329;
padding: .2em .6em .3em;
font-size: 100%;
color: #fff;
border-radius: .25em;
line-height: 1;
vertical-align: bottom;
font-weight: 700;
text-align: center;
white-space: nowrap;
box-sizing: border-box;
overflow: hidden;
display: inline-block;
margin-bottom: 0.5em;
width: 100%;
}
Edit:
Added width: 100%; to keep the labels the full width.
As #RokoC.Buljan pointed out in the example in the comments, this can be accomplished with cleaner CSS. My example above is just a few small modifications on the OP's original code (in case those classes are used elsewhere too). :)
Absloute positioning would seem the logical choice.
.errorLabel {
background-color: #a90329;
padding: .2em .6em .2em;
font-size: 100%;
color: #fff;
border-radius: .25em;
line-height: 1;
vertical-align: baseline;
font-weight: 700;
text-align: center;
white-space: nowrap;
box-sizing: border-box;
overflow: hidden;
display: block;
position: absolute;
bottom:0;
left:50%;
transform:translateX(-50%);
margin-bottom: 5px;
}
.outerDiv {
text-align: center;
/*display: inline-block;*/
float: left;
border-radius: 10px;
border: 2px solid #c3c3c3;
height: 100px;
width: 100px;
margin: 5px;
}
.innerDiv {
width: 80%;
height: 100%;
line-height: 50px;
margin: 0 auto;
position: relative
}
.errorLabel {
background-color: #a90329;
padding: .2em .6em .2em;
font-size: 100%;
color: #fff;
border-radius: .25em;
line-height: 1;
vertical-align: baseline;
font-weight: 700;
text-align: center;
white-space: nowrap;
box-sizing: border-box;
overflow: hidden;
display: block;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
margin-bottom: 5px;
}
<div class="outerDiv">
<div class="innerDiv"> <span>123123</span>
<span class="errorLabel">OK</span>
</div>
</div>
<div class="outerDiv">
<div class="innerDiv"> <span>123123</span>
<span class="errorLabel">Error2</span>
</div>
</div>
<div class="outerDiv">
<div class="innerDiv"> <span>123123</span>
<span class="errorLabel">
Line1<br/>
Line2
</span>
</div>
</div>
<div class="outerDiv">
<div class="innerDiv"> <span>123123</span>
<span class="errorLabel">
Line1<br />
Line2
</span>
</div>
</div>
You can fiddle with the bottom amount:
http://jsfiddle.net/z7hL3any/5/
add:
.errorLabel {
position: relative;
}
.innerDiv {
position: absolute;
bottom: 5px;
width: 100%; }
try this
.errorLabel {
background-color: #a90329;
border-radius: 0.25em;
bottom: 0;
box-sizing: border-box;
color: #fff;
display: block;
font-size: 100%;
font-weight: 700;
line-height: 1;
margin-bottom: 10px;
overflow: hidden;
padding: 0.2em 0.6em 0.3em;
position: absolute;
text-align: center;
vertical-align: baseline;
width: 100%;
}
.it should also work