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
Related
I need to create an empty topbar and an empty sidebar as below. I want to stack them neatly so that the top of the sidebar touches the bottom of the topbar. For that, I am using percentage. However, I just can't get them to do that.
I saw some other threads suggesting to set html and body with height: 100%; and width : 100%. But in my app, the layout below is not in the main html document.
#nav-bar {
position: absolute;
top: 0;
left: 0;
background-color: blue;
height: 10%;
width: 100%;
}
#side-bar {
position: absolute;
top: 0;
left: 0;
background-color: #011a21;
height: 90%;
width: 7.5%;
/*margin-top: 10%;*/
}
<div id="nav-bar"> </div>
<div id="side-bar"></div>
Your #nav-bar has a height: 10%, and you can set the same value for the top rule, selector #side-bar.
#nav-bar {
position: absolute;
top: 0;
left: 0;
background-color: blue;
height: 10%;
width: 100%;
}
#side-bar {
position: absolute;
top: 10%;
left: 0;
background-color: #011a21;
height: 90%;
width: 7.5%;
/*margin-top: 10%;*/
}
<div id="nav-bar"> </div>
<div id="side-bar"></div>
I tend to use flex box for this, Maybe grid would be smarter though. I took also care of some scrolling things. Using min with and height 0 on flex parents is key for that.
body,
section {
min-height: 0;
min-width: 0;
}
body {
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
}
nav {
height: 2rem;
background: green;
}
section {
flex: 1 1 0%;
display: flex;
}
aside {
width: 4rem;
background: blue;
height: 100%;
}
main {
background: pink;
flex: 1 1 0%;
overflow: auto;
padding: 1rem;
}
div {
border: 1px black dashed;
height: 300%;
}
<nav></nav>
<section>
<aside></aside>
<main>
<div>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum, tempora. Voluptates, iure quis enim hic eius ullam sequi suscipit maiores, eum consectetur nesciunt quae dolorum! Voluptate adipisci praesentium illum dolorem.
<br> Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum, tempora. Voluptates, iure quis enim hic eius ullam sequi suscipit maiores, eum consectetur nesciunt quae dolorum! Voluptate adipisci praesentium illum dolorem.
<br> Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum, tempora. Voluptates, iure quis enim hic eius ullam sequi suscipit maiores, eum consectetur nesciunt quae dolorum! Voluptate adipisci praesentium illum dolorem.
<br> Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum, tempora. Voluptates, iure quis enim hic eius ullam sequi suscipit maiores, eum consectetur nesciunt quae dolorum! Voluptate adipisci praesentium illum dolorem.
<br>
</div>
</main>
</section>
I am trying to create some space between the profile picture and the text, but when I applied bottom margin to the image, it doesn't work. I tried setting display: block, but it makes no difference. Why is this not working?
When I change the height and width of the #profile-pic to 100%, or when I add margin to the #profile-pic directly, it works, but I don't understand why its not working in the following case?
#about {
height: 100%;
width: 100%;
}
#profile-pic {
height: 250px;
width: 250px;
margin: auto;
}
#profile-pic img {
display: block;
height: 100%;
width: 100%;
margin-bottom: 100px;
box-shadow: 0 0 5px 1px rgb(255, 255, 255);
border-radius: 50%;
object-fit: cover;
object-position: 50% 38%;
}
<section id="about">
<div id="profile-pic">
<img src="https://data.whicdn.com/images/322027365/original.jpg?t=1541703413" alt="profile pic">
</div>
<p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum autem sequi, est enim, eligendi voluptas et ut aspernatur nostrum laboriosam maxime itaque assumenda sapiente reiciendis, tenetur exercitationem culpa quia ea laudantium! Exercitationem
quo quibusdam, sit quas perspiciatis aspernatur aliquam enim nihil assumenda omnis sunt sequi rerum quisquam. Nesciunt,
</section>
because you have a fixed height parent #profile-pic and your img element has 100% height so it will take as much as his parent space 250px and margin will not affect it there just overflowing the other element with no real effect on the displayed image.
Give it to your div instead of your image
#about {
height: 100%;
width: 100%;
}
#profile-pic {
height: 250px;
width: 250px;
margin: auto;
margin-bottom: 100px;
}
#profile-pic img {
display: block;
height: 100%;
width: 100%;
box-shadow: 0 0 5px 1px rgb(255, 255, 255);
border-radius: 50%;
object-fit: cover;
object-position: 50% 38%;
}
<section id="about">
<div id="profile-pic">
<img src="https://data.whicdn.com/images/322027365/original.jpg?t=1541703413" alt="profile pic">
</div>
<p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum autem sequi, est enim, eligendi voluptas et ut aspernatur nostrum laboriosam maxime itaque assumenda sapiente reiciendis, tenetur exercitationem culpa quia ea laudantium! Exercitationem
quo quibusdam, sit quas perspiciatis aspernatur aliquam enim nihil assumenda omnis sunt sequi rerum quisquam. Nesciunt,
</section>
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!
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
I'm trying to align two div on the same line. No problem for that, but now I'm looking for a solution to have the same height on each div, the problem is that the first one contain only an icon and the second contain text that will probably take more space than the icon. I'm looking for a css property than can help me to do this...
.zone-info {
background-color: #e0f1f5;
line-height: 1.363em;
margin-bottom: 3px;
padding: 5px 0;
}
.zi-icon {
display: inline-block;
float: left;
text-align: center;
vertical-align: center;
height: 100%;
width: 10%;
}
.zi-text {
width: 90%;
display: inline-block;
float: left;
}
<div class="zi-icon zone-info">icone</div>
<div class="zi-text zone-info">Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur.<br>
# Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit.<br>
# Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.</br>
# Sed ut perspiciatis unde omnis iste natus error sit.
</div>
Here is a Jsfiddle of what I do for the moment.
http://jsfiddle.net/nc6L227z/
Wrap the two divs in a .wrapper element and give display: table. Then give display: table-cell to the inner divs and remove float:left and display: inline-block from the other elements:
EDIT: (vertical align added)
Check the Updated DEMO
.wrapper { display: table }
.zone-info {
background-color: #e0f1f5;
display: table-cell;
line-height: 1.363em;
vertical-align: middle;
}
.zi-icon {
text-align: center;
width: 10%;
}
.zi-text {
}
You can use table-cell or a new css property flex
div{display:flex} //you don't need float , inline-block, table cell anythng
DEMO
You could have the right one be contained in the left one.
.col1 {
float: left;
border: 1px solid green;
margin-right: 200px;
background: red;
}
.col1-content {
float: left;
width: 50px;
}
.col2 {
float: left;
background: green;
}
.col2-content {
width: 200px;
}
.clearfix:after {
content: ".";
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
<div class="outer">
<div class="inner clearfix">
<div class="col1">
<div class="col1-content">
Lorem ipsum dolor sit amet.
</div>
<div class="col2">
<div class="col2-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni excepturi animi vitae saepe ratione cumque nostrum eius impedit delectus quibusdam eaque earum et iusto quam soluta. Expedita eius perspiciatis necessitatibus facilis dignissimos quis velit maiores incidunt sequi odio non reprehenderit ut cum perferendis enim. Eligendi fugit nesciunt dolore aliquam numquam.
</div>
</div>
</div>
</div>
</div>
Check Fiddle
I have added a parent div and applied height on it.