Centering a div in Skeleton - html

For a project of mine, I'm using Skeleton Boilerplate for the first time. And I'm looking for the best practice of centring a div in Skeleton without bashing into the rules of Skeleton.
At the moment, I've the following structure for a login page.
HTML:
<div class="container">
<div class="sixteen columns vertical-offset-by-one">
<div id="loginBox">
<img src="images/yeditepeLogo.png" alt="Yeditepe Logo" class="yeditepeLogo" />
<form action="" id="loginForm">
<input type="text" name="username" required placeholder="username" class="loginTextField">
<input type="password" name="password" required placeholder="password" class="loginTextField">
<input type="submit" value="Log In" class="loginButton" />
</form>
</div><!-- loginBox -->
</div><!-- sixteen columns -->
<div class="sixteen columns">
<p align="center">Click here to register</p>
</div>
</div><!-- container -->
CSS:
#loginBox, #registrationBox {
width: 470px;
height: 450px;
background-color: white;
left: 245px; */
top: 20px; */
position: relative;
margin: 0px auto; }
#registrationBox {
height: 500px; }
.yeditepeLogo {
position: relative;
left: 40px;
top: 33px; }
#loginForm, #registrationForm {
position: relative;
top: 45px; }
.loginTextField, .registrationTextField {
position: relative;
height: 40px;
width: 388px;
left: 40px;
border-color: #dedede;
border-style: solid;
border-width: 1px;
margin-bottom: 10px;
text-align: left;
font-size: 18px;
text-indent: 10px;
-webkit-appearance: none; }
.loginTextField:focus, .registrationTextField:focus {
outline-color: #ff9800;
outline-style: solid;
outline-width: 1px;
border-color: white; }
.loginTextField:nth-child(2), .registrationTextField:nth-child(3) {
margin-bottom: 40px; }
.loginButton, .registrationButton {
background-color: #77a942;
position: relative;
border: none;
width: 390px;
height: 60px;
left: 40px;
color: white;
font-size: 24px;
text-align: center;
opacity: 0.8; }
.loginButton:hover, .registrationButton:hover {
opacity: 1; }
As you can see, that #loginBox has a fixed width/height and it should always be on the centre of the page. margin: 0px auto code gives it the horizontal centring. But is it the best practice in Skeleton? Does Skeleton provide a better way?
Also how can I provide it's vertical centring?

There's actually a built in way of centering divs in Skeleton.
<div class="sixteen columns">
<div class="four columns offset-by-six">
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>
The offset-by-six in this case can be altered from one to fifteen, and offsets the column at hand by as many columns as entered. As a neat feature, the offsetting is not affecting alignment when smaller screens are used.
To clarify: This doesn't center the actual content in the div, but centers the div itself.

I know it has been a while since this question was asked, but maybe somebody else can use the answer.
I was able to accomplish centering with Skeleton by filling one-third column class with a space, then the next one-third column class with content, then another one-third column class with a space again.
<div class="one-third column"> </div>
<div class="one-third column"><p>Center of the screen.</p></div>
<div class="one-third column"> </div>

You can set the container to
.container {
position: absolute;
top: 50%;
left: 50%;
margin-left: -43 //replace with half of the width of the container
margin-top: -52 //replace with half of the height of the container
}
set the parent container or element to position: relative;
Here's a good article about How to Center Anything With CSS

Asus3000's answer is good as that is what I do and it works well. I would only add that on mobile, it adds quite a bit of unwanted vertical space. To avoid mobile vertical space, I use a class .filler and hide it on mobile.
HTML
<div class="one-third column filler"> </div>
<div class="one-third column"><p>Center of the screen.</p></div>
<div class="one-third column filler"> </div>
CSS
/* or whatever mobile viewport */
#media only screen and (max-width: 960px) {
.filler { display: none}
}

A way I believe works pretty good is:
<div class="container">
<div class="row">
<div class="two-half column">
centered div content
</div>
</div>
</div>
This makes the div centered and responsive. You can change margin-top to make it all the way in the middle, however changing width will (of course) not make it centered anymore.
Correct me if I'm wrong but this works for me! :)

Related

Having trouble styling a timeline in CSS

I'm relatively new to coding so bare with me. I want to create a simple timeline like the image I've included
https://imgur.com/a/4upikgR
I'm having trouble understanding col-md, how does it work? how can I obtain result like that?
Here's some of code I wrote, can I block the circle in center of page?
I've spent two days on it and can't make it work.
.img {
width: 150px;
height: 150px;
border-radius: 50%;
border: rgb(235, 234, 234) solid 7px;
align-items: center;
display: block;
margin-left: auto;
margin-right: auto;
}
.tml-title {
border: 2px blue solid;
font-weight: bold;
max-width: fit-content;
text-align: right;
}
.tml-text {
text-align: left font-size: 15px;
max-width: 200px;
color: grey;
}
<div id="bruh">
<div class='row'>
<div class="col-xs-8">
<h3 class="tml-title">Marzo 2021 <br> Nasce un'idea</h3>
</div>
<div class="col-xs-4">
<img class="img" src="https://images.app.goo.gl/nSM1SCypuwV9g2zc6" alt="">
</div>
From your code snippet, I assumed you are using Bootstrap as your CSS framework, so I am going to write this answer based on that assumption.
col-md, col-xs etc are classes to control Bootstrap's grid behaviour on different widths. col-xs-5 means 5 units on sm-and-up, meaning it will take 5 (of 12) units wide (5/12) on a typical small device width (> 768 pixels). Likewise col-md-5 means 5 units on md-and-up, etc.
Your CSS doesnt work because you placed the img in the col-xs-4, while technically you would like to put it on the center of the page. Bootstrap has 12 grids, so right now you placed it like this:
--------------------------------------------
| text | image |
--------------------------------------------
while from what I see, you would like it to be like this:
--------------------------------------------
| text | image | text |
---------------------------------------------
The solution is to split the grid into 3 columns of the same size, or 3 columns of different sizes. Since the max grid in one row is 12, you can choose either 4-4-4 or 5-2-5. I personally would recommend 5-2-5 since the image doesnt look like it will take a lot of space, but that's your choice.
<div class ="row">
<div class="col-xs-5">
<!-- your text here, align the text to the right -->
</div>
<div class="col-xs-2">
<!-- your image here, center it -->
</div>
<div class="col-xs-5">
<!-- your text here, align the text to the left -->
</div>
</div>
And that's it.
References:
What is the difference among col-lg-*, col-md-* and col-sm-* in Bootstrap? -> for more info
https://medium.com/wdstack/how-the-bootstrap-grid-really-works-471d7a089cfc -> to understand how bootstrap grid works.
You can use from position absolute and then scaling for that to be place in the center of page(for any element):
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
.img {
width: 150px;
height: 150px;
border-radius: 50%;
border: rgb(235, 234, 234) solid 7px;
align-items: center;
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.tml-title {
border: 2px blue solid;
font-weight: bold;
max-width: fit-content;
text-align: right;
}
.tml-text {
text-align: left font-size: 15px;
max-width: 200px;
color: grey;
}
<div id="bruh">
<div class='row'>
<div class="col-xs-8">
<h3 class="tml-title">Marzo 2021 <br> Nasce un'idea</h3>
</div>
<div class="col-xs-4">
<img class="img" src="https://images.app.goo.gl/nSM1SCypuwV9g2zc6" alt="">
</div>

Inner content pushes div down

I have a question about divs. I have multiple-divs in an parrent div, when I add content to the inner divs divs. The inner divs are pushed down?
I want to know why? Because all my mine margins and padding are add default 0;
Thank you for your time.
https://jsfiddle.net/3w50gj28/
<div class="boxes">
<div class="box">
<h3>MyBMW Login</h3>
<form class="" action="index.html" method="post">
<input type="text" name="email" placeholder="Emailadres">
<input type="password" name="password" placeholder="Wachtwoord">
</form>
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.boxes {
margin-top: 25px;
width: 100%;
position: relative;
text-align: center;
}
.box {
display: inline-block;
width: 300px;
max-height: 400px;
min-height: 233px;
padding: 15px;
border: 1px solid #e6e6e6;
overflow-wrap: break-word;
background-color: #fff;
margin-right: 20px;;
}
div are Block-level Element and a block-level element always starts on a new line and takes up the full width available
Margin and padding in this case aren't what is causing it. If you have divs stacked on each other, as you add content to one it will grow and push the div below down.

Short line linking the content of two Bootstrap columns

I have a series of Bootstrap rows, and I wonder if there's any way to 'link' the content in the columns with a short line, to indicate that they are related? This is how it currently looks:
And this is how I'd like it to look:
This is a sample of the existing code. I'm sure (I hope) I can do this by making using of info-div:before { some CSS } but I'm not entirely sure what.
<div class="row">
<div class="col-sm-6">
<label>LAN IP</label>
<input type="text" class="form-control" v-model="location.lan_ip" />
</div>
<div class="col-sm-6 info-div">
<p class="field-info">If the first two octets of the device's LAN IP (as reported by Meraki) matches this value, the device will resolve to this location during Meraki import.</p>
</div>
</div>
Yes, use :before. It must have content: set or it will not work (css is pseudo-bootstrap).
Since bootstrap padding between columns is always the same, you can just place some element with fixed width and desired position:
* {
box-sizing: border-box;
}
.row {
margin-left: -15px;
margin-right: -15px;
}
p {
margin: 0;
}
.col-sm-6 {
float: left;
width: 50%;
padding-left: 15px;
padding-right: 15px;
}
.row .wrapper {
position: relative;
background: #eee;
min-height: 100px;
}
.row .info-div:before {
content: '';
width: 30px;
position: absolute;
left: -30px;
top: 50%;
height: 1px;
background: black;
}
<div class="row">
<div class="col-sm-6">
<div class="wrapper">
<label>LAN IP</label>
<input type="text" class="form-control" v-model="location.lan_ip" />
</div>
</div>
<div class="col-sm-6">
<div class="wrapper info-div">
<p class="field-info">If the first two octets of the device's LAN IP (as reported by Meraki) matches this value, the device will resolve to this location during Meraki import.</p>
</div>
</div>
</div>

Responsive text fixed positioning with Button

http://i.imgur.com/Veauoig.png
I am currently trying to work out how to make the 'From £' text to keep in the same position as the buttons above. The page is responsive so I have been unable to keep the text in one position.
The CSS I have used so far -
element.style {position: absolute; width: 97%;}
I put each of the 'From £' parts in their own class. Not sure if there is an easier way?
<div class="price2">From £300</div>
Any help would be great. Thanks!
Add a container for the element for the price and button so that they remain in context with each other.
http://jsfiddle.net/05orkj1a/
.prices{
width: 100%;
}
.price-column{
display: table-cell;
width: 33%;
text-align: center;
margin: 0 auto;
padding: 0 5px;
}
<div class="prices">
<div class="price-column">
<button>Bass</button>
<div class="price2">From £65</div>
</div>
<div class="price-column">
<button>Mid</button>
<div class="price2">From £300</div>
</div>
<div class="price-column">
<button>Treble</button>
<div class="price2">From £715</div>
</div>
</div>
You could also Float the columns left to cause them to collapse vertically as the screen shrinks with the same html. Just change the margin or padding depending on how far apart you want them spaced
http://jsfiddle.net/z6agt11e/
.prices{
width: 100%;
overflow: hidden;
}
.price-column{
display: block;
float: left;
text-align: center;
padding: 5px 5px;
}
You can also add an outer container and then create a inner container for each button-price set.
Here is the HTML code:
<div class="outter">
<div class="block">
<div class="button">button1</div>
<div class="price2">From £65</div>
</div>
<div class="block">
<div class="button">button2</div>
<div class="price2">From £300</div>
</div>
<div class="block">
<div class="button">button3</div>
<div class="price2">From £715</div>
</div>
</div>
Here the CSS:
.outter{
width:100%;
}
.block{
width:33%;
background-color: yellow;
float:left;
text-align: center;
}
And here a jsfiddle:
http://jsfiddle.net/SoniaGM/ej4mdwx9/1/
Hope it helps.
You can use the CSS3 ::after pseudo-selector.
Give at button class:
position: relative;
Then you have to write something lime this:
.button-class::after {
content: 'From £300';
background: transparent;
height: 1%;
width: 3%;
position: absolute;
top: 20px;
left: 0px;
}
Obviously, you have to change height: 1%; width: 3%; and top: 20px; left: 0px;with whatever you want!

Columns of nested divs with the same set ratio rendering at slightly different heights

I've split my page into two vertical divs, each containing a number of nested divs wrapped so that they resize preserving a set ratio. That works great - but for some reason the divs on the left end up shorter than the divs on the right! The CSS is consistant, but something's not...
You can see a gap appear at the foot of the left-hand column here:
http://jsfiddle.net/VsJLs/
Is it clear what's wrong? Thank you for looking!
<head>
<style type="text/css">
.break {
padding-top: 25px;
}
.leftcol {
width: 50%;
position: absolute;
top: 0px;
left: 25px;
}
.leftpad {
padding-right: 38px;
}
.rightcol {
width: 50%;
position: absolute;
top: 0px;
right: 25px;
}
.rightpad {
padding-left: 37px;
}
.wrapper {
width: 100%;
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 161.3%;
display: block;
background-color: red;
content: '';
}
</style>
</head>
<body>
<div class="leftcol">
<div class="leftpad">
<div class="break"></div>
<div class="wrapper"></div>
<div class="break"></div>
<div class="wrapper"></div>
<div class="break"></div>
<div class="wrapper"></div>
</div>
</div>
<div class="rightcol">
<div class="rightpad">
<div class="break"></div>
<div class="wrapper"></div>
<div class="break"></div>
<div class="wrapper"></div>
<div class="break"></div>
<div class="wrapper"></div>
</div>
</div>
</body>
</html>
I've tried zeroing margins as suggested below but that doesn't improve things. It seems like the problem could lie with the padding-top: 161.3%; property. Changing % to px fixes that creeping misalignment - but I need to keep it as a percentage! Can anybody figure this out? Thanks for your time.
The problem is caused due to the margin border; set it to 0 or same on all sides:
MARGIN
{BORDER=0;
}
I figured it out - I mean: I know the problem but I'm still not sure why... The gutter I created was split unevenly:
.leftpad {
padding-right: 38px;
}
and
.rightpad {
padding-right: 37px;
}
If both those are equal (http://jsfiddle.net/VsJLs/1/) then there's no slip. Now I'm worried about creating columns this way - that's another question though...