Div boxes not aligning properly using inline-block - html

I have some very simple code which works perfect for what look I'm trying to achieve. I have two divs which are displayed as "boxes" which are contained within an outer div which is the boxContainer. I have the boxes sitting next to each other rather than one on top of the other, and they are aligned perfectly in the middle of the screen. The boxes widths shrink/grow as the browser width gets smaller/larger, and the boxes relocate to be one on top of the other if the browser window gets too small, while remaining centered on the page. Perfect.
The only problem is that the boxes are aligned on the bottom instead of the top. Because the second box has less text within it, it is pushed further down the page to align with the bottom of the first box. I want them to align on the top instead.
I believe this is caused by display:inline-block, but I'm not sure why, and I don't know how to fix it and keep the same features I listed above.
If you could help me out, I'd surely appreciate it!!
#boxContainer {
width:80%;
margin:0 auto;
text-align:center;
}
.box {
display:inline-block;
width:35%;
margin:20px;
border:solid 5px;
border-radius:40px;
}
<div id="boxContainer">
<div class="box">
<h3>BOX 1</h3>
<p>TEXT GOES HERE, blaha dlfjas fakfasldfjas fkdf lasfjwio we dklajdakfliwo wklw jdkas fdsaj fjdsfwoif ajkdl kdalfej woja dklf woef adkiweoj daljidw odal fjwe ewew kalwoie ea falk blaha dlfjas fakfasldfjas fkdf lasfjwio we dklajdakfliwo wklw jdkas fdsaj fjdsfwoif ajkdl kdalfej woja dklf woef adkiweoj daljidw odal fjwe ewew kalwoie ea falk</p>
</div>
<div class="box">
<h3>BOX 2</h3>
<p>TEXT GOES HERE, blaha dlfjas fakfasldfjas fkdf lasfjwio we dklajdakfliwo wklw jdkas fdsaj fjdsfwoif ajkdl kdalfej woja dklf woef adkiweoj daljidw odal fjwe ewew kalwoie ea falk</p>
</div>
</div>
Picture
Thank you!

Since the boxes are already inline-block you can add vertical-align: top to the .box style.

.box {
display: inline-block;
border: solid 1px;
vertical-align: top;
width: 40%;
}
<div id="boxContainer">
<div class="box">
<h3>BOX 1</h3>
<p>Lorem ipsum dolor sit amet, altera interesset pri an. Et aeque interpretaris vel, at quo summo deleniti disputationi. Eu inimicus splendide duo, soleat intellegam ut per. Sint impedit recusabo ex vix, aliquid adipisci consequat no ius. Eu possim consequat eum, sea cu quaeque impedit, est fuisset accusamus definiebas ad.</p>
</div>
<div class="box">
<h3>BOX 2</h3>
<p>Viris eruditi consectetuer ei mea, eu nulla ridens officiis duo. In atomorum forensibus abhorreant quo, id nec aperiam dissentiet.</p>
</div>
</div>
You can use the vertical-align CSS property.
It has effect only on inline, and inline-block elements.
This is a great reference on vertical-align.

Related

What is the best (responsive) way to implement irregular shaped divs/folds?

I've been working on designs with very irregularly-shaped divs, such as rhombuses, trapezoids, etc. I want to know what the most responsive way to deal with these types of designs.
My current workaround:
The typical way I implement these designs is by using a combination of clip-path, bloated vertical padding to deal with the clip-path clipping content, and then a negative margin-top on the next fold to cover the white-space created by the clip-path. I declare negative margin-top values with viewport width (ex. -10vw), so the folds adjust based on the width of the browser.
Problems with current workaround:
Negative margins usually cause folds to overlap each other, covering the content of other folds. Multiple #media queries needed for it to look acceptable and yet I still encounter certain sizes where the folds overlap each other.
Here's an image to further describe what I mean by irregularly-shaped divs/folds:
https://imgur.com/a/jCbJZS4
Any help would be appreciated. These sort of designs seem to be trending, so your help will serve me and others for future projects as well. Thank you!
SVGs are a nice way to create section dividers as per your image,(and other complex shapes!) you can target the various shapes inside an svg with css (change fill colour, animations etc), they are widely supported (except for old IE browsers, naturally) and as they are simply vector paths, you can easily stretch, scale and distort, and they're quite small in size.
You might set an svg divider e.g. a wave pattern inside an absolutely positioned div at the bottom of a content section, like below.
section {
position: relative;
width: 100%;
margin: 0;
padding: 0;
}
#sect1 {
background-color: #2baf70;
}
#sect2 {
background-color: #f9f9f9;
}
.row {
max-width: 900px;
margin-left: auto;
margin-right: auto;
padding: 45px 45px 115px 45px;
}
.divider {
background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDBweCIgdmlld0JveD0iMCAwIDEyODAgMTQwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxnIGZpbGw9IiNmOWY5ZjkiPjxwYXRoIGQ9Ik0xMjgwIDMuNEMxMDUwLjU5IDE4IDEwMTkuNCA4NC44OSA3MzQuNDIgODQuODljLTMyMCAwLTMyMC04NC4zLTY0MC04NC4zQzU5LjQuNTkgMjguMiAxLjYgMCAzLjRWMTQwaDEyODB6IiBmaWxsLW9wYWNpdHk9Ii4zIi8+PHBhdGggZD0iTTAgMjQuMzFjNDMuNDYtNS42OSA5NC41Ni05LjI1IDE1OC40Mi05LjI1IDMyMCAwIDMyMCA4OS4yNCA2NDAgODkuMjQgMjU2LjEzIDAgMzA3LjI4LTU3LjE2IDQ4MS41OC04MFYxNDBIMHoiIGZpbGwtb3BhY2l0eT0iLjUiLz48cGF0aCBkPSJNMTI4MCA1MS43NmMtMjAxIDEyLjQ5LTI0Mi40MyA1My40LTUxMy41OCA1My40LTMyMCAwLTMyMC01Ny02NDAtNTctNDguODUuMDEtOTAuMjEgMS4zNS0xMjYuNDIgMy42VjE0MGgxMjgweiIvPjwvZz48L3N2Zz4=);
/* this is an inlined svg taken from a project I'm working on, as an example. as I can't really import a .svg file here */
width: 100%;
background-size: 100% 70px;
bottom: 0;
height: 70px;
z-index: 1;
display: block;
background-repeat-y: no-repeat;
position: absolute;
}
<section id="sect1">
<div class="row">
<h2>Mock Content</h2>
<p>Lorem ipsum dolor sit amet, affert omittam urbanitas est te. Eam ne oportere erroribus, quis veri eam cu, usu ex tota verear iudicabit. Vim modus conclusionemque an, verterem explicari sententiae ei duo. Mel cu docendi fierent, sonet dolorum ocurreret
at vis. Voluptua fabellas electram ut has, tation maluisset voluptatibus sea ex.</p>
</div>
<div class="divider"></div>
</section>
<section id="sect2">
<div class="row">
<h2>Mock Content</h2>
<p>Lorem ipsum dolor sit amet, affert omittam urbanitas est te. Eam ne oportere erroribus, quis veri eam cu, usu ex tota verear iudicabit. Vim modus conclusionemque an, verterem explicari sententiae ei duo. Mel cu docendi fierent, sonet dolorum ocurreret
at vis. Voluptua fabellas electram ut has, tation maluisset voluptatibus sea ex.</p>
</div>
</section>

css - Postion:fixed works on desktop but not mobile

I am creating a page for comments, which containers users' comments and a comment input, the comment input is fixed at the bottom.
The problem is it works fine on Desktop, but when I try on my iPad iOS 11 the comment input box scrolls with the page, not fixed at the bottom.
Here is my code: JSFiddle
CSS
.xi-ipad-scroll {
height:500px;
overflow:hidden;
background:green;
}
.xi-comment {
width: 40%;
bottom: 0;
position: fixed;
}
.xi-comment-box {
width: 100%;
font-size: 15pt;
font-weight: 700;
}
.xi-comment-send {
bottom: 15px;
position: fixed;
}
HTML
<div class="xi-ipad-scroll">
<div class="xi-main-title">Bình luận</div>
<div class="xi-comment-list">
<ul>
<li>
<div>Quang Anh Nguyễn</div>
<div>Lorem ipsum dolor sit amet, illum prompta sadipscing cu sit. Ea mei lorem erroribus honestatis, laoreet torquatos eu mel, nam dicant labitur tractatos et. Cu est alia altera consulatu, vim falli detracto reformidans in, novum forensibus eu sit. At etiam erroribus prodesset qui, eam veniam laoreet at. Ea mei natum erant.</div>
</li>
<li>....</li>
</ul>
</div>
<div class="xi-box xi-comment">
<textarea type="text" placeholder="Comment..." class="resizable xi-comment-box" rows="1"></textarea>
</div>
</div><!--iPad-->
I searched on internet and I got solutions like putting -webkit-backface-visibility: hidden; or z-index:100 but none of them works
If I'm understanding what you are trying to do correctly, your "position:fixed" is actually what is causing this. Fixed position will always show on the screen. More info on fixed position. If you want it to be at the bottom of all content you will need to remove the fixed from both -send and -comment.
.xi-comment {
width: 40%;
bottom: 0;
***position: fixed;***
}
.xi-comment-send {
bottom: 15px;
***position: fixed;***
}
This now leads to a new problem, you have set an absolute height and have hidden anything outside of that height. You either need to extend the height, remove the hidden, or move the comment section outside of that div.
I put together a codepen to show this. I think you actually are having the same issue on desktop, I just don't believe you had enough content for you to realize it.

Div is not floating left

I'm still relatively new to html and css, and I'm not able to figure this out. I have three divs with some text and I want them to be next to each other. I set them to float: left but they are not doing so.
.threethings {
width: 20%;
}
.threethings div {
text-align: center;
position: relative;
float: left;
}
<div class="threethings">
<div><span>Style</span>
<br>
<p>Lorem ipsum dolor sit amet, ius te ullum indoctum, sanctus consequat eum te. Nemore recteque necessitatibus et eos.</p>
</div>
<div><span>Style</span>
<br>
<p>Lorem ipsum dolor sit amet, ius te ullum indoctum, sanctus consequat eum te. Nemore recteque necessitatibus et eos.</p>
</div>
<div><span>Style</span>
<br>
<p>Lorem ipsum dolor sit amet, ius te ullum indoctum, sanctus consequat eum te. Nemore recteque necessitatibus et eos.</p>
</div>
</div>
try this
.threethings {
width : 100%;
}
.threethings div {
width: 20%;
text-align: center;
position: relative;
float : left;
}
so what happens is divs are floated in your case but not side by side as you are giving 20% width to parent , due which children cant fload side by side.
what i did was give parent some large width and children some small width, so that parent can accomodate children floating side by side.
well as div is block. width:100% might not be necessary
You're floating the parent class - not the divs containing paragraphs. Add the .threethings class to the 3 nested divs to instruct them to float their proceeding divs up alongside them.
Note that you may also need to give the divs a fixed width, as the paragraphs you have on there may exceed the length of your html body, which in turn would force them onto a new line.
Try this solution
.threethings {
width:100%;
}
.threethings div {
width:33%;
position: relative;
float : left;
}

W3C validation generating error [duplicate]

This question already has answers here:
w3c html validation error - Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections
(3 answers)
Closed 6 years ago.
Warning: Article lacks heading. Consider using h2-h6 elements to add
identifying headings to all articles. From line 32, column 5; to line
32, column 46 ↩ ↩
The above warning is generated by https://validator.w3.org/.
Now let me show you the code of those line numbers.
<article class="form-control relativePos">
<ul class="formsectionTab">
<li class="active">1. Services</li>
<li>2. Time</li>
<li>3. Details</li>
<li>4. Payment</li>
<li>5. Done</li>
</ul>
Precisely the Line#32 that code is talking about is this →
<article class="form-control relativePos">
My HTML developer is saying there are only 2 ways to get rid of these warnings →
Either use <div></div> in place of section or article or use h2-h6 elements.
But my problem is I want to build my template on HTML5 tags and the code has no scope of putting up the headings because thats not required. what should I do?
Any alternative HTML5 attributes that can do this w/o enforcing the h2-h6 elements?
The answer is in your question. I will quote you: "I want to build my template on HTML5 tags and the code has no scope of putting up the headings because thats not required."
This is one of the biggest problems in the software industry. It's called Scope Creep.
Basically, if something is not within the scope of requirements, you should avoid dealing with it unless absolutely necessary. Sometimes it's hard to bite the bullet though I know.
Add h1 - h6 elements as much as you want
Wrap those h1 - h6 elements in divs styled the same as your other text
Add classes to the h1 - h6 elements to inherit the div style (which
should be the same as the rest of your text)
Effect?
h1 - h6 that look exactly like the rest of your text instead of looking like heading elements
body {
background: #111;
color: #999;
text-align: justify;
text-justify: inter-word;
max-width: 80%;
margin: 10%
}
.uniform {
display: inherit;
text-align: inherit;
color: inherit;
font-size: inherit;
font-weight: inherit;
}
.mycoolstyle {
color: red;
font-size: 22px;
font-weight: bold;
display: inline;
}
<body>
<div>
<h1>This is a Header 1 with browser defaults</h1>
<div class="mycoolstyle">
<h1 class="uniform">This is a Header 1 with inhertied div style</h1>
</div>
<h2>This is a Header 2 with browser defaults</h2>
<div class="mycoolstyle">
<h2 class="uniform">This is a Header 2 with inhertied div style</h2>
</div>
<h3>This is a Header 3 with browser defaults</h3>
<div class="mycoolstyle">
<h3 class="uniform">This is a Header 3 with inhertied div style</h3>
</div>
<p>This is a paragraph with browser defaults
<br>Lorem ipsum dolor sit amet, in eam simul nostrud definiebas, mea iusto placerat prodesset ei. Eum summo audiam ea. Vitae aperiri at duo. Vis atomorum partiendo id, nam ea noluisse platonem. Nec minimum consequat cu, pri in harum moderatius. Ferri
aperiam forensibus an nam.</p>
<div class="mycoolstyle">
<p class="uniform">This is a paragraph with inhertied div style
<br>Lorem ipsum dolor sit amet, in eam simul nostrud definiebas, mea iusto placerat prodesset ei. Eum summo audiam ea. Vitae aperiri at duo. Vis atomorum partiendo id, nam ea noluisse platonem. Nec minimum consequat cu, pri in harum moderatius. Ferri
aperiam forensibus an nam.</p>
</div>
</div>
</body>

vertically center elements in div [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Closed 6 years ago.
Hey I'm new to coding and here is my predicament. I didn't know how to vertically center elements in a div, and apparently this is a common problem because there isn't a simple class that does that function. So I looked around at a few methods and came up with the following solution to center the text within the container div.
CodePen:
http://codepen.io/mmartinb/pen/ozzjVN
The HTML:
<div class="container" id="tryone">
<div id="trytwo">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ita relinquet duas, de quibus etiam atque etiam consideret. Atque his de rebus et splendida est eorum et illustris oratio. Claudii libidini, qui tum erat summo ne imperio, dederetur. Eam si varietatem diceres, intellegerem, ut etiam non dicente te intellego; Sint ista Graecorum; Duo Reges: constructio interrete. Piso igitur hoc modo, vir optimus tuique, ut scis, amantissimus. At iam decimum annum in spelunca iacet. Sapientem locupletat ipsa natura, cuius divitias Epicurus parabiles esse docuit. Qui-vere falsone, quaerere mittimus-dicitur oculis se privasse;</p>
</div>
<img src="http://res.cloudinary.com/dqoqzoncd/image/upload/v1474214059/YzW4rUu_f69vph.jpg" alt="Manuel Martin" id="smaller-image">
</div>
The CSS:
#tryone{
max-width:1000px;
}
#trytwo{
top: 50%;
max-width: 550px;
float: left;
margin-top: 45px;
}
Which was just adding a margin-top to the text div. The only issue is that the code does not seem very flexible. If I want to change the size of my text which I will end up wanting to, the the container will be unbalanced unless I change the margin-top:. Is there a solution such that a change in text doesn't unbalance the container.
try this: (if u don't care about IE9)
#tryone{
max-width:1000px;
display: flex;
align-items: center;
}
#trytwo{
max-width: 550px;
}
you can use flexbox in order to align items vertically. Flexbox has a property called align-items, you can check it out here: https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties
In order to achieve what you want, you'll need to add the following to the #tryone id styles:
#tryone{
max-width:1000px;
display:flex;
align-items: center;
}
And remove from #trytwo (I've removed this since is no longer needed):
#trytwo{
top: 50%;
max-width: 550px;
margin-top: 45px;
}
Here is a plunker with a working copy: https://plnkr.co/edit/5jOUuMPUv4a1gvDdNfgV?p=preview
Hope this helps!