How do I remove invisible space around text (Heading)? - html

So as the title say I put a color on top of an image and I then tried to put some text on top of it, but then all the div got moved to the bottom and the text got moved to the top of the div and when I inspect the heading, it shows a space colored in yellow. I'm trying to understand CSS position and I'm starting to understand it, but right now I don't understand haha. I think it's something with a margin, but I reinitialized it at the beginning of the CSS.
(Also sorry! If you feel the need to tell me that my CSS is bad don't hesitate to tell me off i want to learn from my mistake!)
The HTML
<div id="section3">
<div id="layer">
<h1>Parmi les premiers de classe !</h1>
</div>
</div>
And CSS
#section3 img {
width: 1903px;
margin-left: 0px;
margin-top: -645px;
z-index: 100;
}
#section3 h1 {
margin-top: 260px;
margin-left: 420px;
font-size: 80px;
}
#section3 p {
margin-top: 10px;
margin-left: 590px;
font-size: 30px;
}
.img4{
position: relative;
top: 641px;
}
#section3{
background: url('../Images/CF3.jpg');
position: relative;
bottom:4px;
width: 1903px;
height: 930px;
}
#layer{
background-color: #4c96eb75;
width: 100%;
height: 100%;
}
#layer h1{
display: block;
}
The reset at the start of CSS
* {
margin: 0;
padding: 0;
font-family: Segoe UI;
}

You used up higher values of height and width that's why it happened. I changed that:
#section3 h1 {
/* margin-top: 260px;
margin-left: 420px; */
font-size: 80px;
}
#section3 p {
margin-top: 10px;
margin-left: 590px;
font-size: 30px;
}
.img4{
position: relative;
top: 641px;
}
#section3{
background: url('../Images/CF3.jpg');
position: relative;
bottom:4px;
width: 390px;
height: 300px;
}
#layer{
background-color: #4c96eb75;
width: 100%;
height: 100%;
}
#layer h1{
display: block;
margin: 0;
}
<div id="section3">
<div id="layer">
<h1>Parmi les premiers de classe !</h1>
</div>
</div>

Change the css to this:
#section3 img {
width: 1903px;
margin-left: 0px;
margin-top: -645px;
z-index: 100;
}
#section3 h1 {
/* margin-top: 260px;
margin-left: 420px; */
font-size: 80px;
}
#section3 p {
margin-top: 10px;
margin-left: 590px;
font-size: 30px;
}
.img4{
position: relative;
top: 641px;
}
#section3{
background: url('../Images/CF3.jpg');
position: relative;
bottom:4px;
width: 1903px;
height: 930px;
}
#layer{
background-color: #4c96eb75;
width: 100%;
height: 100%;
}
#layer h1{
display: block;
margin: 0;
}
I have added a margin:0, to the header and removed other styles margin for #section3 h1, that was the reason div was placed at the bottom and

Related

How to make fixed elements scroll after the 100% of the body?

I'm currently working in a final assignment for a class. I need to create a basic webpage (actually, the main goal of the assignment is to learn to use the local storage) but i got stuck on a very early stage of the making (i'm pretty novice in this). I've been using fixed divs for the main structure of the webpage and now idk how to add more content. i tried inherent position but everything went wrong.
the code: https://codepen.io/ipanonima/pen/WNbNeJm
html of the body:
<body>
<div class="main">
<div class="main-bar">
<div class="main-bar-container">
<div class="main-bar--logo">
<img src="./public/logo.png">
</div>
<div class="main-bar--info-container">
<div class="main-bar--info-container--buttons">
<div class="main-bar--info-container--buttons--b"><p>Botón</p></div>
<div class="main-bar--info-container--buttons--b"><p>Botón</p></div>
<div class="main-bar--info-container--buttons--b"><p>Botón</p></div>
</div>
<div class="main-bar--info-container--login">
<div class="main-bar--info-container--login--b"><p>login</p></div>
</div>
</div>
</div>
</div>
<div class="example-section">
<div class="example-section--pictures" id="ex1">
<div class="example-section--pictures-pic"><img src="./public/canada-example.jpg"></div>
<div class="example-section--pictures--overlay"><div class="overlay--text">canadá</div></div>
</div>
<div class="example-section--pictures" id="ex2">
<div class="example-section--pictures-pic"><img src="./public/mexico-example.jpg"></div>
<div class="example-section--pictures--overlay"><div class="overlay--text">méxico</div></div>
</div>
<div class="example-section--pictures" id="ex3">
<div class="example-section--pictures-pic"><img src="./public/eu-example.jpg"></div>
<div class="example-section--pictures--overlay"><div class="overlay--text">EE.UU.</div></div>
</div>
</div>
<div class="banner-sesion"></div>
</div>
</body>
and my css (which is getting really long)
*{
margin: 0;
padding: 0;
font-family: 'Montserrat', sans-serif;
}
input{
border: none;
border-bottom: 2px solid #74b5fa;
background-color: rgba(250, 167, 116, 0);
}
.box-session{
box-sizing: content-box;
position: relative;
background-image: linear-gradient(to top left,rgba(152, 116, 250,.1 ), rgba(250, 167, 116, 1));
width: 232px;
padding-left: 15px;
padding-right: 17px;
padding-top: 15px;
padding-bottom: 15px;
margin-top: 11%;
border-radius: 20px;
margin-left: calc(50% - 116px);
}
.session{
box-sizing: border-box;
position: relative;
width: 232px;
}
body{
background-color: #E2EBF8;
height: 100%;
width: 100%;
}
.relative{
position: relative;
height: 100%;
width: 100%;
}
.alto20{
height: 20%;
width: 100%;
}
.navBar{
position: fixed;
height: 100%;
width: 11%;
background-color: blue;
border-radius: 20px;
background-image: linear-gradient(#71AEFF, #4080FF);
}
.navBar--perfil{
position: relative;
float: left;
/* background-color: yellow; */
}
.navBar--photo{
position: relative;
margin-top: 25%;
/* background-color: blue; */
width: 100%;
height: 50%;
}
.navBar--photo img{
height: 30px;
width: 30px;
background-color: #FFFFFF;
border-radius: 5px;
margin-left: 40px;
}
.navBar--photo p{
color: #FFFFFF;
font-weight: bold;
font-size: 16px;
padding-left: 26px;
margin-top: 4px;
}
.navBar--opciones{
float: left;
width: 100%;
height: 60%;
}
.navBar--botones{
position: relative;
float: left;
width: 100%;
height: calc(100%/5);
}
.navBar--blanco{
position: relative;
height: 65px;
width: 65px;
/* background-color: green; */
margin-top: 3.5%;
margin-left: calc(50% - 52px);
box-sizing: border-box;
padding-top: 8px;
}
.navBar--blanco img{
height: 30px;
width: 30px;
margin-left: 19px;
}
.navBar--blanco p{
width: 100%;
color: #FFFFFF;
font-weight: bold;
font-size: 12px;
text-align: center;
}
.selected{
background-color: #FFFFFF;
border-radius: 20px;
color: #71AEFF;
}
.selected p{
color: #71AEFF;
}
.navBar--ayuda{
float: left;
/* background-color: green; */
}
.navBar--ayuda p{
position: relative;
background-color: #FFFFFF;
width: 70px;
height: 20px;
border-radius: 7%;
text-align: center;
color: #71AEFF;
font-weight: bold;
top: 75%;
left: 15%;
}
.main{
position: fixed;
height: 100%;
width: 55%;
background-color: #FFFFFF;
border-radius: 20px;
margin-left: 8%;
/* background-color: lightblue; */
}
.main--scroll{
position: absolute;
width: 90%;
/* background-color: pink; */
float: left;
overflow-y: scroll;
height: 95%;
overflow-y: auto;
overflow-x: hidden;
margin-top: 2.5%;
margin-left: 2.5%;
}
.lista ul{
float: left;
/* list-style-type: upper-roman; */
list-style-position: inside;
list-style-image: url('../public/man.png');
}
.tabla table{
border: 2px solid red;
border-collapse: separate;
}
.derecha{
position: fixed;
height: 100%;
width: 40%;
margin-left: 60%;
border-radius: 20px;
background-image: linear-gradient(#F3FAFC, #CCDBEF);
}
.ej{
background-color: greenyellow;
width: 100%;
height: 200px;
border: 1px solid black;
}
.noteblock{
width: 150px;
height: 150px;
background-color: #ff7190;
border-radius: 20px;
margin-left: 20px;
margin-top: 20px;
padding-top: 10px;
padding-left: 10px;
position: relative;
float: left;
}
.noteblock p{
color: white;
}
.noteblock h3{
color: white;
}
.boton{
margin-left: 20px;
margin-top: 20px;
position: relative;
}
thanks for all the patience
I think you may have misunderstood the fixed position. As it is, you can add more content perfectly well in your site: try setting .new { height: 2000px; background: orange;} and you'll see the orange wall does appear and the site scrolls. One thing that might be misleading you is because your header is also fixed, so any content you do add (an <h1> for example) is going to go under it.
In any case, because the banners are fixed, their position is relative to the screen, so they "go down" as you scroll, and they'll be in front of any content you add.
I don't understand what led you to set them fixed in the first place, but it's probably not a good idea. Try taking that out, give the ejemplo pictures a fixed height and let it scroll (try setting you header to sticky rather than fixed). When you're done with your homework, try researching CSS positions a bit more.

Series of divs, where on each one is stacked a black div with transparency, with a centered text

I have to display on the mobile view for a webpage a list of divs, where each of them has a specific background-image and central h1 where I display the title. Stacked on each of these divs with the background-image, there is a black div with an opacity: 0.5 to make the image darker.
This is the my code:
.square-container {
min-height: auto;
background-color: white;
}
.square {
width: 100vmin;
height: 100vmin;
color: white;
}
.hover-square {
background: black;
width: 100vmin;
height: 100vmin;
margin-top: 0;
margin-bottom: 4px;
position: absolute;
opacity: 0.5;
}
.square-logo {
width: 12.5%;
height: auto;
margin-left: 50%;
transform: translateX(-50%);
}
h1 {
height: 87.5vmin;
width: 100%;
font-size: 36px;
text-align: center;
vertical-align: middle;
line-height: 100vmin;
margin: 4px auto;
z-index: 10 !important;
}
.square h1.first {
margin-top: 50px;
margin-bottom: 4px;
}
<div class="square-container">
<div class="square" style="background-color: #e74c3c">
<div class="hover-square"></div>
<h1 class="first">Case 1</h1>
<img class="square-logo" src="//pmcdeadline2.files.wordpress.com/2016/07/logo-tv-logo.png">
</div>
</div>
It is correctly working, but the title is kept below the black div. I have tried to modify the z-index of the h1 tag, but I had no luck so far. Do you have an idea on how to solve this issue?
This is a JSFiddle with the complete code. Thanks in advance for your replies!
When one mix elements (siblings) where some have a position other than static, they end up in a higher layer, hence, in your case, the h1 sits behind.
As mentioned, for z-index to work it need a position (other than static), though one rarely need to use z-index, instead make sure all, or none, has a position, so in your case, simply drop z-index and add position: relative
.square-container {
min-height: auto;
background-color: white;
}
.square {
width: 100vmin;
height: 100vmin;
color: white;
}
.hover-square {
background: black;
width: 100vmin;
height: 100vmin;
margin-top: 0;
margin-bottom: 4px;
position: absolute;
opacity: 0.5;
}
.square-logo {
width: 12.5%;
height: auto;
margin-left: 50%;
transform: translateX(-50%);
}
h1 {
position: relative;
height: 87.5vmin;
width: 100%;
font-size: 36px;
text-align: center;
vertical-align: middle;
line-height: 100vmin;
margin: 4px auto;
}
.square h1.first {
margin-top: 50px;
margin-bottom: 4px;
}
<div class="square-container">
<div class="square" style="background-color: #e74c3c">
<div class="hover-square"></div>
<h1 class="first">Case 1</h1>
<img class="square-logo" src="//pmcdeadline2.files.wordpress.com/2016/07/logo-tv-logo.png">
</div>
</div>
If the sole purpose of the hover-square is to darken the square, you could use a pseudo element instead, and save some markup and gain some flexibility
.square-container {
min-height: auto;
background-color: white;
}
.square {
position: relative;
width: 100vmin;
height: 100vmin;
color: white;
}
.square::before { /* added/changed to pseudo */
content: '';
background: black;
width: 100vmin;
height: 100vmin;
margin-top: 0;
margin-bottom: 4px;
position: absolute;
opacity: 0.5;
}
.square-logo {
width: 12.5%;
height: auto;
margin-left: 50%;
transform: translateX(-50%);
}
h1 {
position: relative;
height: 87.5vmin;
width: 100%;
font-size: 36px;
text-align: center;
vertical-align: middle;
line-height: 100vmin;
margin: 4px auto;
}
.square h1.first {
margin-top: 50px;
margin-bottom: 4px;
}
<div class="square-container">
<div class="square" style="background-color: #e74c3c">
<h1 class="first">Case 1</h1>
<img class="square-logo" src="//pmcdeadline2.files.wordpress.com/2016/07/logo-tv-logo.png">
</div>
</div>
For z-index to work you need to create stacking context and the easiest way to do this in this case is to just set position: relative on h1 element.
DEMO
But if you want h1 under navbar then you also need to set higher z-index on navbar so if h1 is 10 then navbar must be 11.
Just use position: relative
DEMO HERE
CSS
h1 {
position: relative;
height: 87.5vmin;
width: 100%;
font-size: 36px;
text-align: center;
vertical-align: middle;
line-height: 100vmin;
margin: 4px auto;
z-index: 10 !important;
}

bug in navigation Link, for my portfolio

Trying to make my portfolio, and new to webdesign. I am trying to add navigation links but the last link goes to next line. Don't know why is it so?
I want in single line, and if even there is some different method to represent this pl. help me/guide me for that too.
Thank You!
My Demo
CSS & HTML
html,
body {
margin: 0%;
top: 0%;
}
body {
background: #2f233d;
overflow: hidden;
}
header {
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 12%;
background: #333;
font-family: Agenda Medium, Sans-Serif, Arial;
font-size: 20px;
}
header img {
display: inline;
width: 227px;
height: 100px;
margin-left: 2%;
}
header .links {
display: inline-block;
position: absolute;
bottom: 10%;
}
header a {
border: 1px solid #ddd;
padding: 1%;
text-decoration: none;
color: #ccc;
}
footer {
position: fixed;
bottom: 0%;
left: 0%;
width: 100%;
height: 10%;
background: #ccc;
}
aside {
position: fixed;
top: 12%;
left: 0%;
width: 20%;
height: 78%;
background: #f2f1f1;
overflow-y: auto;
}
section {
position: fixed;
top: 12%;
left: 20%;
width: 82%;
height: 78%;
background: #fff;
overflow-y: scroll;
}
<header>
<img src="Logo.png" alt="logo" />
<span class="links">
Home
About
Gallery
Work
Contact
</span>
</header>
<footer></footer>
<aside></aside>
<section></section>
You need to define your widths. Currently width is dependent on the length of the word.
Here is one of many solutions, this one being very straightforward.
header img {
width: 15%;
}
.links {
width: 80%;
}
I shaved a bit off to account for margins and paddings. The important thing here is I'm defining the image's width in percent instead of pixels, and I'm defining the width of .links, and not just the children of it.
In honesty, your solution is going to need to be more complex. It needs to account for mobile devices, because a small screen will cause the words to overflow their border. This, however, should answer your immediate question.
fiddle
For header a and header .links to changes in CSS..
demo:
html,
body {
margin: 0%;
top: 0%;
}
body {
background: #2f233d;
overflow: hidden;
}
header {
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 12%;
background: #333;
font-family: Agenda Medium, Sans-Serif, Arial;
font-size: 20px;
}
header img {
display: inline;
width: 227px;
height: 100px;
margin-left: 2%;
}
header .links {
display: inline-block;
position: absolute;
bottom: 10%;
width:100%
}
header a {
border: 1px solid #ddd;
padding: 1%;
text-decoration: none;
color: #ccc;
display:inline-block
}
footer {
position: fixed;
bottom: 0%;
left: 0%;
width: 100%;
height: 10%;
background: #ccc;
}
aside {
position: fixed;
top: 12%;
left: 0%;
width: 20%;
height: 78%;
background: #f2f1f1;
overflow-y: auto;
}
section {
position: fixed;
top: 12%;
left: 20%;
width: 82%;
height: 78%;
background: #fff;
overflow-y: scroll;
}
<header>
<img src="Logo.png" alt="logo" />
<span class="links">
Home
About
Gallery
Work
Contact
</span>
</header>
<footer></footer>
<aside></aside>
<section></section>
Just replace your header .links class
header .links
{
display:inline-block;
position:absolute;
bottom:10%;
width:100%
}
It will work for you.

overflow hidden with border radius shows a weird grey border over images

I have a round div which wraps an image and two other divs. The problem is that it is shown a grey border around this div. The problem is on all browsers chrome and firefox. I have tried putting browser css-vendor-prefixes, masks but no result.
I can not use :
img {
width: 100%;
height: 100%;
border-radius: 120px;
}
because the image is not in the correct aspect-ratio. It is in 1:1. It should be on 16:9 because it is a YouTube video frame.
<div class="video_wrap">
<div class="views">1651</div>
<img src="http://img.youtube.com/vi/-NschES-8e0/hqdefault.jpg">
<div class="title">o'najr</div>
</div>
.video_wrap {
width: 240px;
height: 240px;
border-radius: 120px;
overflow: hidden;
}
.views, .title {
position: relative;
background: #fff;
height: 50px;
color: #f8008c;
text-align: center;
line-height: 50px;
}
.views {
top: 0px;
z-index: 2;
}
.title {
top: -100px;
}
.video_wrap img {
height: 100%;
position: relative;
top: -50px;
}
fiddle http://jsfiddle.net/h3198LfL/
You could remove the border-radius:120px from .video_wrap and add following to your img
img{
width:100%;
border-radius: 120px;
}
SNIPPET
.video_wrap {
width: 240px;
height: 240px;
overflow: hidden;
}
img {
width: 100%;
border-radius: 120px;
}
.views,
.title {
position: relative;
background: #fff;
height: 50px;
color: #f8008c;
text-align: center;
line-height: 50px;
}
.views {
top: 0px;
z-index: 2;
}
.title {
top: -100px;
}
.video_wrap img {
height: 100%;
position: relative;
top: -50px;
}
<div class="video_wrap">
<div class="views">1651</div>
<img src="http://img.youtube.com/vi/-NschES-8e0/hqdefault.jpg">
<div class="title">o'najr</div>
</div>
add the webkit code and others in video-wrap, as in:
.video_wrap {
width: 240px;
height: 240px;
-webkit-border-radius:120px;
-moz-border-radius:120px;
-ms-border-radius:120px;
-o-border-radius:120px;
border-radius: 120px;
overflow: hidden;
}
to avoid the border, you can set new line of it, as in:
.video_wrap img {
border:0px;
border:none;
}
DEMo

How can I create two full-width headers on the top of the page without position:absolute?

I need to create two full-width headers but I can't seem to find a way to do them without using position absolute because if i use position:absolute, I can't use margin-bottom, which I need. What can I do?
This is what I have tried:
<div class="header1">
</div>
<div class="header2">
</div>
.header1 {
background-color: red;
margin-top: 110px;
color: #FFFFFF;
height: 35px;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.header2 {
background-color: blue;
margin-top: 150px;
color: #FFFFFF;
height: 35px;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
Not sure if I'm understanding the problem correctly, but
body {
margin:0
}
.header1 {
background-color: red;
color: #FFFFFF;
height: 35px;
width: 100%;
}
.header2 {
background-color: blue;
color: #FFFFFF;
height: 35px;
width: 100%;
}
Will give you 2 full width headers
DEMO