Mystery gap between container and article element - html

Can anyone help me with why the left side of this article is sitting down from the top of the section? I have shown this in the below image.
I have used Chrome developer tools to try and find the problem but I can't see anything in the gap or margins that would indicate such behaviour?
main {
border: 1px solid white;
}
main>section {
border: 1px solid black;
}
main>section>h3 {
border: 1px solid black;
width: 98%;
text-align: center;
padding: 2px;
margin: 2px 2px;
height: 10%;
}
main>section>article {
display: inline-flex;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
min-height: 300px;
max-height: 400px;
}
main>section>article.aleft {
border: 1px solid black;
width: 28%;
padding: 1px;
height: 90%;
margin: 1px 1px;
}
main>section>article.aright {
border: 1px solid black;
width: 68%;
padding: 1%;
height: 90%;
margin: auto;
}
<main id="content">
<section class="part">
<h3>Latest News</h3>
<article class="aleft">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro at vero esse error eius laborum illum magni qui natus quisquam culpa, quaerat, ullam impedit. Nobis, repellendus itaque commodi! Iure, distinctio.
</article>
<article class="aright">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil aut quis mollitia, voluptates alias odit amet ullam praesentium molestias sapiente ex est. Repudiandae expedita cupiditate illo quis veritatis nemo, voluptates architecto incidunt ratione
in, voluptate neque amet quaerat eligendi ipsum earum aliquid dolorum inventore non natus. Autem dignissimos similique at possimus voluptatum, hic vel sunt velit. Rerum blanditiis voluptate animi molestias, hic ab natus vitae, cum labore facere
harum, placeat ea illum officia magni quis. Earum atque illum sit voluptate, veritatis asperiores, facere velit ipsam laborum hic iusto blanditiis possimus, molestias maxime sed! Excepturi nemo, rem quisquam quae, dolore magni.
</article>
</section>
</main>

It's being caused by uneven padding on your article elements.
main > section > article.aleft {
border: 1px solid black;
width: 28%;
padding: 1px; /* pixel unit */
height: 90%;
margin: 1px 1px;
}
main > section > article.aright{
border: 1px solid white;
width: 68%;
padding: 1%; /* percentage unit */
height: 90%;
margin:auto;
}
Matching the units for both – percentages or pixels – solves the problem.

you may use this code
main>section {
border: 1px solid white;
display: flex;
flex-wrap: wrap;
}
and replace the CSS you have for main>section
Hope this helps
Take care and happy coding

Related

Sidenav links inactive

This is a very strange problem I've encountered. Everytime I add more content to the main content the sidenav links aren't able to be clicked on. Here is an example of the sidenav without main content:
<style>
div.sidenav {
width: 240px;
position: absolute;
z-index: -1;
top: 110px;
left: 10px;
background: transparent;
overflow-y: scroll;
overflow-x: hidden;
padding: 8px 0;
border-style: dashed; color: #28eb4c;
text-align: center;
}
div.sidenav a {
padding: 1px 2px 1px 10px;
text-decoration: none;
font-size: 25px;
color: #ed7eeb;
display: block;
}
div.sidenav a:hover {
color: #e3a8e2;
}
div.main {
margin-left: 240px;
padding: 10px 10px;
}
</style>
</head>
<body>
<h1>A Test</h1>
<div class="sidenav">
<h2>Links</h2>
YouTube
Twitter
</div>
<div class="main">
<h2>Some text</h2>
</div>
</body>
Here is an example with main text:
<style>
div.sidenav {
width: 240px;
position: absolute;
z-index: -1;
top: 110px;
left: 10px;
background: transparent;
overflow-y: scroll;
overflow-x: hidden;
padding: 8px 0;
border-style: dashed; color: #28eb4c;
text-align: center;
}
div.sidenav a {
padding: 1px 2px 1px 10px;
text-decoration: none;
font-size: 25px;
color: #ed7eeb;
display: block;
}
div.sidenav a:hover {
color: #e3a8e2;
}
div.main {
margin-left: 240px;
padding: 10px 10px;
}
</style>
</head>
<body>
<h1>A Test</h1>
<div class="sidenav">
<h2>Links</h2>
YouTube
Twitter
</div>
<div class="main">
<h2>Some text</h2>
<p>
Lorem ipsum dolor sit amet. In aperiam magnam in quod aliquam ut dolor reprehenderit nam modi fugit ab sunt harum et alias amet. Aut alias magni et perferendis molestias ut veritatis explicabo qui rerum reprehenderit?
</p>
<p>
Ut pariatur soluta ea exercitationem nisi in optio ratione 33 totam modi et ipsam natus? Vel eius suscipit eos voluptatem nihil ut adipisci alias aut quos dolor quo soluta velit.
</p>
<p>
Voluptatibus necessitatibus labore eius ea internos quos est ullam alias. Eum ratione optio At facere nulla id accusamus pariatur vel sint omnis sit omnis eveniet in laudantium debitis. Ut architecto corrupti eum consequuntur odio qui illo numquam aut inventore fuga aut laboriosam atque. Et odio molestiae et incidunt enim qui doloribus nihil?
</p>
</div>
</body>
Maybe I messed something up with the <style> section? I mostly don't really know what is happening around there, especially with margins and padding and maybe I've overridden the margins with the main body. I have also seen examples of sidebars made as an entirely different html page within another, and maybe that could help. If you could also help me figure out how to fix the sidebar as well as make it scrollable instead of it filling the whole page, that would be appreciated, thanks.
The z-index property specifies the stack order of an element:
div.sidenav {
width: 240px;
position: absolute;
z-index: 10;
top: 110px;
left: 10px;
background: transparent;
overflow-y: scroll;
overflow-x: hidden;
padding: 8px 0;
border-style: dashed; color: #28eb4c;
text-align: center;
}
div.sidenav a {
padding: 1px 2px 1px 10px;
text-decoration: none;
font-size: 25px;
color: #ed7eeb;
display: block;
}
div.sidenav a:hover {
color: #e3a8e2;
}
div.main {
margin-left: 240px;
padding: 10px 10px;
}
<h1>A Test</h1>
<div class="sidenav">
<h2>Links</h2>
YouTube
Twitter
</div>
<div class="main">
<h2>Some text</h2>
<p>
Lorem ipsum dolor sit amet. In aperiam magnam in quod aliquam ut dolor reprehenderit nam modi fugit ab sunt harum et alias amet. Aut alias magni et perferendis molestias ut veritatis explicabo qui rerum reprehenderit?
</p>
<p>
Ut pariatur soluta ea exercitationem nisi in optio ratione 33 totam modi et ipsam natus? Vel eius suscipit eos voluptatem nihil ut adipisci alias aut quos dolor quo soluta velit.
</p>
<p>
Voluptatibus necessitatibus labore eius ea internos quos est ullam alias. Eum ratione optio At facere nulla id accusamus pariatur vel sint omnis sit omnis eveniet in laudantium debitis. Ut architecto corrupti eum consequuntur odio qui illo numquam aut inventore fuga aut laboriosam atque. Et odio molestiae et incidunt enim qui doloribus nihil?
</p>
</div>
also it is better to use flex or grid

how can I remove small gap vertically

If I remove the space between the block code it only removes a small gap horizontally,
but vertically it's still has a small gap i know i can use flexbox instead but, I'm trying to understand why it behaves like this, any idea why it still has a small gap? vertically it can be removed with font size set to 0 but there is no text or letter below the image
/* Video Wrapper */
.video-wrapper {
background-color: royalblue;
width: 60%;
margin: 15px auto 15px auto;
box-sizing: border-box;
}
.video-wrapper > h2 {
text-indent: 150px;
background-color: lightblue;
margin: 0px;
height: 50px;
line-height: 50px;
}
.video-content {
display: inline-block;
background-color: red;
width: 40%;
position: relative;
height: 400px;
box-sizing: border-box;
}
iframe {
width: 100%;
outline: 0;
position: absolute;
height: 100%;
box-sizing: border-box;
}
.video-wrapper > p {
display: inline-block;
width: 50%;
box-sizing: border-box;
vertical-align: top;
}
No Space Removed:
<section class="video-wrapper" id="video-section">
<h2>Video</h2>
<div class="video-content"></div>
<p>Carefully Haa Lorem ipsum dolor sit amet consectetur, adipisicing elit. Non perspiciatis veritatis veniam hic dignissimos! Et quas magnam doloremque, sapiente quae error ut repellendus esse aspernatur doloribus mollitia sunt iste cupiditate quisquam, aliquam dolorem labore dolore nobis repellat consectetur vel, nulla harum alias incidunt. Odit, dolorem. Maiores maxime quidem quis odit?</p>
</section>
Space Removed :
<section class="video-wrapper" id="video-section"><h2>Video</h2><div class="video-content"></div><p>Carefully Haa Lorem ipsum dolor sit amet consectetur, adipisicing elit. Non perspiciatis veritatis veniam hic dignissimos! Et quas magnam doloremque, sapiente quae error ut repellendus esse aspernatur doloribus mollitia sunt iste cupiditate quisquam, aliquam dolorem labore dolore nobis repellat consectetur vel, nulla harum alias incidunt. Odit, dolorem. Maiores maxime quidem quis odit?</p></section>
By reducing the margin-Bottom you can hide or remove the gap
to do that CSS will be
.video-content {
display: inline-block;
background-color: red;
width: 40%;
position: relative;
margin-bottom: -4px;
height: 400px;
box-sizing: border-box;
}
Yes, as answered #Jvs there is a way like to reduce margin-botttom and
there is more one way is reducing height of parent tag/class
in your case CSS :
.video-wrapper {
background-color: royalblue;
width: 60%;
margin: 15px auto 15px auto;
box-sizing: border-box;
height: 450px;
}
Try this one also :p

Different result to what expected when using overflow: scroll

This page states "browsers always display scrollbars whether or not any content is actually clipped."
This isn't the case for #2.
#1 does display a scroll-bar but only when I scroll. For some reason I was led to believe it'd always be there.
I am using Chrome. Is this behavior normal? Have I misinterpreted MDN?
div {
height: 150px;
width: 150px;
padding: 5px;
border: 5px solid red;
overflow: scroll;
}
section {
height: 150px;
width: 150px;
padding: 5px;
border: 5px solid red;
overflow: scroll;
}
<body>
<h1>1</h1>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium modi beatae explicabo officiis voluptatibus doloribus quae ipsam, voluptate reiciendis iure maiores repudiandae, hic quaerat eaque amet alias ducimus voluptas consequatur!</div>
<h1>2</h1>
<section>Voluptate reiciendis iure maiores repudiandae, hic quaerat eaque amet alias ducimus voluptas consequatur!</section>
</body>
see it here youtube
When an overflow is on scroll browsers will always display scrollbars whether or not any content is actually clipped that's it when overflow is set to scroll so if you want the contents not to show scrollbars when contents is not overflowing you can simply use auto on overflow like
overflow: auto;
div {
height: 150px;
width: 150px;
padding: 5px;
border: 5px solid red;
overflow: auto;
}
section {
height: 150px;
width: 150px;
padding: 5px;
border: 5px solid red;
overflow: auto;
}
<body>
<h1>1</h1>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium modi beatae explicabo officiis voluptatibus doloribus quae ipsam, voluptate reiciendis iure maiores repudiandae, hic quaerat eaque amet alias ducimus voluptas consequatur!</div>
<h1>2</h1>
<section>Voluptate reiciendis iure maiores repudiandae, hic quaerat eaque amet alias ducimus voluptas consequatur!</section>
</body>
so if you want to have the scrollbar on one dimension you could just use overflow-y to have scrollbars on the y-axis or use overflow-x to have the scrollbar on the x-axis
the following is an example of overflow on one dimension
Example
div {
height: 150px;
width: 150px;
padding: 5px;
border: 5px solid red;
overflow-y: scroll;
}
section {
height: 150px;
width: 150px;
padding: 5px;
border: 5px solid red;
overflow-x: scroll;
}
<body>
<h1>1</h1>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium modi beatae explicabo officiis voluptatibus doloribus quae ipsam, voluptate reiciendis iure maiores repudiandae, hic quaerat eaque amet alias ducimus voluptas consequatur!</div>
<h1>2</h1>
<section>Voluptate reiciendis iure maiores repudiandae, hic quaerat eaque amet alias ducimus voluptas consequatur!</section>
</body>

Set the same width of a “Position: fixed” div as parent div(flexbox item)

How can I make the same width of the NavWrapper as parent?
I want these links at a fixed position even the main section overflows.
I know how to do this without Flex. Is there any pure CSS way to do that?
body {
padding:0;
margin:0
}
.wrapper {
display: flex;
}
nav {
flex: 1 1 150px;
background: gray;
}
.nav-wrapper {
width: 100%;
position: fixed;
top: 0; left: 0;
display:flex;
flex-direction: column;
}
.nav-wrapper a {
flex: 1 1;
border: 1px solid red;
}
section {
flex: 5 1 500px;
padding: 20px;
}
<div class="wrapper">
<nav role="navigation">
<div class="nav-wrapper">
Home
About
</div>
</nav>
<section>
<p>Lorem</p>
</section>
</div>
You don't need fixed position- you can see why I say this after looking at the example below:
Remove the fixed positioning and add height: 100vh to nav:
nav {
flex: 1 1 150px;
background: gray;
height: 100vh;
}
Now wrap the contents on a section into an inner div that is positioned absolute like this:
section {
flex: 5 1 500px;
padding: 20px;
position: relative;
overflow-y: auto;
}
.inner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
This will allow the section to remain at 100vh of the nav-wrapper and the extra height will overflow.
body {
padding: 0;
margin: 0
}
.wrapper {
display: flex;
}
nav {
flex: 1 1 150px;
background: gray;
height: 100vh;
}
.nav-wrapper {
width: 100%;
display: flex;
flex-direction: column;
}
.nav-wrapper a {
flex: 1 1;
border: 1px solid red;
}
section {
flex: 5 1 500px;
padding: 20px;
position: relative;
overflow-y: auto;
}
.inner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div class="wrapper">
<nav role="navigation">
<div class="nav-wrapper">
Home
About
</div>
</nav>
<section>
<div class="inner">
<p>Lorem</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae molestiae, libero inventore nobis et veritatis, laborum vitae, vel eaque omnis ad adipisci quia velit blanditiis qui. Cum voluptas quisquam itaque possimus accusamus repellendus quia iure
asperiores. Unde, rerum nihil maiores nisi, iusto voluptate id cumque incidunt, perspiciatis facilis perferendis explicabo.
<p>Lorem</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae molestiae, libero inventore nobis et veritatis, laborum vitae, vel eaque omnis ad adipisci quia velit blanditiis qui. Cum voluptas quisquam itaque possimus accusamus repellendus quia iure
asperiores. Unde, rerum nihil maiores nisi, iusto voluptate id cumque incidunt, perspiciatis facilis perferendis explicabo.
<p>Lorem</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae molestiae, libero inventore nobis et veritatis, laborum vitae, vel eaque omnis ad adipisci quia velit blanditiis qui. Cum voluptas quisquam itaque possimus accusamus repellendus quia iure
asperiores. Unde, rerum nihil maiores nisi, iusto voluptate id cumque incidunt, perspiciatis facilis perferendis explicabo.
</div>
</section>
</div>
Check this out and let me know your feedback. Thanks!

Arrows from point to point

I have a PSD which I have to convert to html. I have a problem with some elements, to be more precise I have no idea how to create it, furthermore I don't know how to name it to find examples in google. Looking for your advices. Those arrows should be responsive(become longer or shorter)
I would give the background the dashed lines. Then I would position the icons along with their arrow heads at the top, bottom, and middle using css. Then as the element grows and shrinks the icons move with the sizing and cover the dashed lines in the background.
Here, I got you started...
.container {
box-sizing: border-box;
width: 80%;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.top-dash {
position: relative;
width: 100%;
height: 30px;
margin-bottom: 1em;
background-color: black;
display: flex;
align-items: center;
justify-content: space-between;
}
.top-dash:before {
content: "";
position: absolute;
left: 0;
top: 13px;
width: 100%;
border-top: 5px dashed orange;
}
[class*="word"] {
display: block;
padding-right: 1em;
background-color: black;
color: orange;
font-size: 18px;
font-weight: bold;
z-index: 5;
}
[class*="word"]:first-child {
padding-left: 1em;
}
[class*="word"]:nth-child(n+2):before {
content: ">";
padding-right: 1em;
}
.content {
position: relative;
box-sizing: border-box;
width: 100%;
padding: 0 2em;
border-left: 60px solid blue;
}
.side-dash {
position: absolute;
left: -60px;
top: 0;
width: 60px;
height: 100%;
overflow: hidden;
display: flex;
}
.side-dash:before {
content: "";
position: absolute;
left: 28px;
top: 0;
height: 100%;
border-left: 5px dashed white;
}
<div class="container">
<div class="top-dash">
<span class="word-left">ONE</span>
<span class="word-mid">TWO</span>
<span class="word-right">THREE</span>
</div>
<div class="content">
<div class="side-dash">
<span class="icon-top"></span>
<span class="icon-mid"></span>
<span class="icon-bot"></span>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, cupiditate, explicabo! Voluptatibus placeat quod magnam soluta, fuga molestiae consectetur doloribus distinctio ipsum voluptas labore delectus reprehenderit rem voluptate, beatae nesciunt.</p>
<p>Nisi excepturi nobis ipsam perferendis nemo ipsa! Aspernatur quaerat ad, harum sapiente? Adipisci, ea. Aperiam exercitationem unde reiciendis obcaecati dolorem sit vitae animi, ut at quisquam corporis ratione voluptatum modi!</p>
<p>Assumenda explicabo voluptatum ea porro unde quo at praesentium temporibus quae optio, laudantium ab minus vero quas, repellat nihil. Laudantium, facere. Tempora adipisci earum voluptatem deserunt atque eos fugiat debitis.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, cupiditate, explicabo! Voluptatibus placeat quod magnam soluta, fuga molestiae consectetur doloribus distinctio ipsum voluptas labore delectus reprehenderit rem voluptate, beatae nesciunt.</p>
<p>Nisi excepturi nobis ipsam perferendis nemo ipsa! Aspernatur quaerat ad, harum sapiente? Adipisci, ea. Aperiam exercitationem unde reiciendis obcaecati dolorem sit vitae animi, ut at quisquam corporis ratione voluptatum modi!</p>
<p>Assumenda explicabo voluptatum ea porro unde quo at praesentium temporibus quae optio, laudantium ab minus vero quas, repellat nihil. Laudantium, facere. Tempora adipisci earum voluptatem deserunt atque eos fugiat debitis.</p>
</div>
</div>