I was working on a project and started working on texts when I realized that if a set the margin-top: 20vh property on CSS does not work, why? Please help me.
#text1 {
margin-top: 26vh;
}
#text2 {
float: right;
margin-right: 15mm;
margin-top: 22vh;
}
#text3 {
float: left;
margin-top: 37vh;
}
<section class="imagesUnderHeader" id="image2" style="background-image: url(Images/Loop.gif)">
<div class="progressionBar" id="progressionBar"></div>
<div class="dots" id="firstParagraph"></div>
<div class="dots" id="secondParagraph"></div>
<div class="dots" id="thirdParagraph"></div>
<div class="paragraphBar" id="bar1"></div>
<div class="paragraphBar" id="bar2"></div>
<div class="paragraphBar" id="bar3"></div>
<h1 class="title adjustPadding goUpText" id="title">Some Text</h1><br>
<p class="subtitle adjustPadding popUpText" id="text1">Subtitle 1</p><br>
<p class="subtitle adjustPadding popUpText" id="text2">Subtitle 2</p><br>
<p class="subtitle adjustPadding popUpText" id="text3">Subtitle 3, <a> with a link, </a> <a>Another one</a><br> <a>and another one</a></p>
</section>
If you need any informations please ask and I will provide additional informations, thank you so much for the help.
Here I made a demo stripping away some details from your code that were just adding noise for the sake of better showing what's going on.
As the mdn docs says:
https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
1vh = 1% of the viewport's height
I included that quote just to avoid any ambiguity but it was pretty clear already.
In this demo I just used one single custom css property to decide the margin-top value and used that value to set the margin-top of all the 3 #text elements and to size the ::before element used as a placeholder to highlight the margin like it was a ruler.
The value of that variable is going to be 10vh so 10% of viewport's height.
As you can see running the demo at full screen, if you resize the window, those distances will indeed change as expected.
:root {
--margin-top: 10vh;
}
* {
margin: 0;
padding; 0;
}
#text1, #text2, #text3 {
margin-top: var(--margin-top);
}
.title {
border: solid 1px;
}
.subtitle {
position: relative;
border: solid 1px blue;
}
.subtitle::before {
content: '';
position: absolute;
height: var(--margin-top);
border: solid 1px red;
width: 0px;
top: calc(-1 * var(--margin-top) - 1px); /*here it's doing -1px to account for border*/
left: 5px;
}
<section class="imagesUnderHeader" id="image2">
<h1 class="title adjustPadding goUpText" id="title">Some Text</h1>
<p class="subtitle adjustPadding popUpText" id="text1">Subtitle 1</p>
<p class="subtitle adjustPadding popUpText" id="text2">Subtitle 2</p>
<p class="subtitle adjustPadding popUpText" id="text3">
Subtitle 3,
<a> with a link, </a>
<a>Another one</a>
<br>
<a>and another one</a>
</p>
</section>
Anyway the whole truth is also that I removed the <br>s that were going to add vertical spaces hard to discern from margins and more importantly I also removed the float left and right because they affect the positioning in relation to the document flow.
So for the sake of completeness this is the same exact demo with those styles added to show the difference:
:root {
--margin-top: 10vh;
}
* {
margin: 0;
padding; 0;
}
#text1, #text2, #text3 {
margin-top: var(--margin-top);
}
#text2{
float: left;
}
#text3{
float: right;
}
.title {
border: solid 1px;
}
.subtitle {
position: relative;
border: solid 1px blue;
}
.subtitle::before {
content: '';
position: absolute;
height: var(--margin-top);
border: solid 1px red;
width: 0px;
top: calc(-1 * var(--margin-top) - 1px); /*here it's doing -1px to account for border*/
left: 5px;
}
<section class="imagesUnderHeader" id="image2">
<h1 class="title adjustPadding goUpText" id="title">Some Text</h1>
<p class="subtitle adjustPadding popUpText" id="text1">Subtitle 1</p>
<p class="subtitle adjustPadding popUpText" id="text2">Subtitle 2</p>
<p class="subtitle adjustPadding popUpText" id="text3">
Subtitle 3,
<a> with a link, </a>
<a>Another one</a>
<br>
<a>and another one</a>
</p>
</section>
So to make it short, to me the margin is correctly applied. So I'm not sure I'm answering to the exact issue you are encountering. As an added consideration maybe you are fighting against the margin collapsing and in case that's an option, here is the related info from mdn:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing
Related
I'm attempting to rework the sections of my website, and I got halfway there on what I wanted, except whenever I attempt to add another element, the size breaks for some reason, so what's supposed to be two large boxes, become two small boxes with overlapping text
How it looks with a single element
How it looks with two elements
Image I edited image to show what I'm trying to accomplish
Someone told me previously that it had something to do with line-height, but messing with line-height didn't really change much besides the fact the text wasn't clipping anymore, but the size change was still a problem
I want them all to be a specific size, independently if there's another element near them or not, if I leave the .headercontainer width at 100%, the single element background stretches through the whole page, which is something I don't want, here's what I'm talking about
Here's my CSS code for the page:
.headercontainer {
display: flex;
height: 5%;
width: 46%;
margin: auto;
}
div.wrapper {
flex: 1;
border: 1px solid white;
margin: 0.50%;
}
.headerpfp {
float: left;
margin-left: 1%;
margin-top: 1%;
margin-right: 1%
}
.posttext {
text-align: left;
margin-left: 1%;
margin-top: -0.35%;
}
.headtext {
margin-top: 3.00%;
color: lime;
text-align: left;
}
And the HTML code:
<div class="headercontainer">
<div class="wrapper" style="background-image:url(../../images/quakebackgrounds/sitebackground03.png);background-size:cover;float:left;">
<a href="../../blog/essays/pages/Early2000sInternet.html">
<img src="../../blog/images/PFPs/JuneSSaiPFP.png" style="border:1px solid white;" class="headerpfp">
<h2 class="headtext">The Early and Mid 2000's Internet</h2></a>
<p style="text-align:left;">Posted August 7, 2022</p>
<p style="text-align:left;">Written By June S. Sai</p>
<br>
<br>
<p class="posttext">There was no bigger joy than sending your</p>
<p class="posttext">friends DooM wads on Skype and playing deathmatch</p>
<p class="posttext">while voicecalling all day long, good times.</p>
</div>
<div class="wrapper" style="background-image:url(../../images/quakebackgrounds/sitebackground03.png);background-size:cover;float:right;">
<a href="../../blog/essays/pages/Early2000sInternet.html">
<img src="../../blog/images/PFPs/JuneSSaiPFP.png" style="border:1px solid white;" class="headerpfp">
<h2 class="headtext">The Early and Mid 2000's Internet</h2></a>
<p style="text-align:left;">Posted August 7, 2022</p>
<p style="text-align:left;">Written By June S. Sai</p>
<br>
<br>
<p class="posttext">There was no bigger joy than sending your</p>
<p class="posttext">friends DooM wads on Skype and playing deathmatch</p>
<p class="posttext">while voicecalling all day long, good times.</p>
</div>
</div>
Here's my style.css file aswell: https://junessai.net/style.css
Change the width of .headercontainer from 46% to 100% in CSS
.headercontainer {
display: flex;
height: 5%;
width: 100%;
margin: auto;
}
div.wrapper {
flex: 1;
border: 1px solid white;
margin: 0.50%;
}
.headerpfp {
float: left;
margin-left: 1%;
margin-top: 1%;
margin-right: 1%
}
.posttext {
text-align: left;
margin-left: 1%;
margin-top: -0.35%;
}
.headtext {
margin-top: 3.00%;
color: lime;
text-align: left;
}
<div class="headercontainer">
<div class="wrapper" style="background-image:url(../../images/quakebackgrounds/sitebackground03.png);background-size:cover;float:left;">
<a href="../../blog/essays/pages/Early2000sInternet.html">
<img src="../../blog/images/PFPs/JuneSSaiPFP.png" style="border:1px solid white;" class="headerpfp">
<h2 class="headtext">The Early and Mid 2000's Internet</h2></a>
<p style="text-align:left;">Posted August 7, 2022</p>
<p style="text-align:left;">Written By June S. Sai</p>
<br>
<br>
<p class="posttext">There was no bigger joy than sending your</p>
<p class="posttext">friends DooM wads on Skype and playing deathmatch</p>
<p class="posttext">while voicecalling all day long, good times.</p>
</div>
<div class="wrapper" style="background-image:url(../../images/quakebackgrounds/sitebackground03.png);background-size:cover;float:right;">
<a href="../../blog/essays/pages/Early2000sInternet.html">
<img src="../../blog/images/PFPs/JuneSSaiPFP.png" style="border:1px solid white;" class="headerpfp">
<h2 class="headtext">The Early and Mid 2000's Internet</h2></a>
<p style="text-align:left;">Posted August 7, 2022</p>
<p style="text-align:left;">Written By June S. Sai</p>
<br>
<br>
<p class="posttext">There was no bigger joy than sending your</p>
<p class="posttext">friends DooM wads on Skype and playing deathmatch</p>
<p class="posttext">while voicecalling all day long, good times.</p>
</div>
</div>
I'm currently working on freecodecamp's first test, so my question is probably dumb. I would like to change the line-height of #titles to a smaller one, while keeping it's background color. It's probably the display element, but I can't figure out what to do. Also, I'd like to get rid of the white line surrounding my image, right before the border...
<div id="main">
<div id="titles">
<h1 id="title">A tribute to Ocelote</h1>
<h2 id="title2">The man who has done it all.</h2>
</div>
<hr>
<div id="img-div">
<img id="image" src="https://theshotcaller.net/wp-content/uploads/2017/09/IMG_5488-1.jpg" alt="A photo of Ocelote">
<div id="img-caption"> A story of how far can one go, if only the desire is
there.
</div>
<div id="tribute-info">
<br>
<br>
fgj
</div>
<a id="tribute-link" href="https://lol.gamepedia.com/Ocelote" target="_blank"> </a>
</div>
</div>
https://jsfiddle.net/deffciu/hrna0Lfs/
any help is appreciated
Adding the below two rules to #titles makes it work:
#titles {
display: block;
background: #6C7E95;
line-height: 5px;
/* Add the below two rules */
overflow: hidden;
padding: 0 0 20px;
}
You get this:
Snippet
html, body {
font-family: 'Oswald', sans-serif;
text-align: center;
background: white;
}
#title2 {
color: #052449;
margin-bottom: 0px;
}
#titles {
display: block;
background: #6C7E95;
line-height: 5px;
/* Add the below two rules */
overflow: hidden;
padding: 0 0 20px;
}
#image {
border: 8px solid #052449;
border-radius: 50%;
width: 500px;
height: 375px;
margin-top: 15px;
}
hr {
border-color: #486282;
margin-top:0px;
}
#img-caption {
margin-top: 20px;
font-style: italic;
font-size: 25px;;
}
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<div id="main">
<div id="titles">
<h1 id="title">A tribute to Ocelote</h1>
<h2 id="title2">The man who has done it all.</h2>
</div>
<hr>
<div id="img-div">
<img id="image" src="https://theshotcaller.net/wp-content/uploads/2017/09/IMG_5488-1.jpg" alt="A photo of Ocelote">
<div id="img-caption"> A story of how far can one go, if only the desire is there.
</div>
<div id="tribute-info">
<br>
<br>
fgj
</div>
<a id="tribute-link" href="https://lol.gamepedia.com/Ocelote" target="_blank"> </a>
</div>
</div>
For the white border issue, it's your body's margins. The below code will fix it.
body {margin: 0;}
I am creating a messaging system where one user speaks to the other. I have created message boxes with the arrows. So far all the boxes has arrows except one (see pics below). Also the height is not auto adjusting to the content. Can someone take a look at my code to see what is going on?
HTML
<div class="col-xs-7 live-chat-feed">
<div class="chat-date"><p>Friday 12:34</p></div>
<div class="user-post">
<div class="chat-avatar">
<img src="img/bitmap(3).png"
srcset="img/bitmap(3)#2x.png 2x,
img/bitmap(3)#3x.png 3x"
class="Bitmap"><p class="time-posted">12:47</p>
</div>
<div class="single-post-box">
<p class="chat-content">
Hey there! <br>
I noticed that not only are you a football fan
but you also go to a lot of games! What do you think about the upcoming season and who is your favorite team? Looks to me like you are a Pats fan!</p>
</div>
</div>
<div class="new-live-chat">
<div class="chat-date"><p>Saturday 22:40</p></div>
<div id="current-user">
<div class="user-post">
<div class="chat-avatar">
<img src="img/bitmap-copy.png"
srcset="img/bitmap-copy#2x.png 2x,
img/bitmap-copy#3x.png 3x"
class="Bitmap"><p class="time-posted">12:47</p>
</div>
<div class="single-post-box">
<p class="chat-content">
Wow! That’s awesome. I love football and im a beat writer for the Pats & have the luxury of catching their games!</p>
</div>
<div class="single-post-box">
<p class="chat-content">
What about you? Are you a Pats fan yourself?</p>
</div>
</div>
</div>
<div class="user-post">
<div class="chat-avatar">
<img src="img/bitmap(3).png"
srcset="img/bitmap(3)#2x.png 2x,
img/bitmap(3)#3x.png 3x"
class="Bitmap"><p class="time-posted">12:47</p>
</div>
<div class="single-post-box">
<p class="chat-content">
Oh yeah! Brady with the SB win again this year! </p>
</div>
</div>
<div id="current-user">
<div class="user-post">
<div class="chat-avatar">
<img src="img/bitmap-copy.png"
srcset="img/bitmap-copy#2x.png 2x,
img/bitmap-copy#3x.png 3x"
class="Bitmap"><p class="time-posted">12:47</p>
</div>
<div class="single-post-box">
<p class="chat-content">
Thats pretty cool! No idea how much of a Pats fan you were to already have season tix! I dont even have them yet!</p>
</div>
</div>
</div>
</div>
CSS
.live-chat-feed {
margin-left: 50%;
margin-top: -310%;
background-color: #000;
}
.new-live-chat {
margin-top: 20%;
}
.chat-avatar {
position: relative;
left: -30%;
top: 85px;
}
.chat-date,
.chat-content,
.time-posted {
color: #8785ab;
}
.chat-date {
position: relative;
left: 30%;
}
.single-post-box {
width: 729.9px;
height: auto;
border-radius: 2px;
background-color: #ffffff;
box-shadow: 0 2px 4px 0 rgba(167, 169, 197, 0.55);
margin-bottom: 10%;
padding: 20px;
}
#current-user .single-post-box {
position: relative;
left: -15%;
border-radius: 2px;
background-color: #1ac384;
box-shadow: 0 2px 4px 0 rgba(167, 169, 197, 0.55);
}
.single-post-box::after {
content: '';
height: 0;
position: absolute;
width: 0;
border: 10px solid transparent;
border-right-color: #fff;
right: 97.5%;
top: 115px;
}
#current-user .single-post-box::after {
content: '';
height: 0;
position: absolute;
width: 0;
border: 10px solid transparent;
border-left-color: #1ac384;
left: 100%;
top: 0px;
}
I always use height: inherit; for height property. It will create a box containing the the text without any free space at the bottom. So if you have like text of 3 rows it will create a height like 20% or something, if you have 6 rows, it will create height of 40%, etc. Hope that helps.
So I have an image and some text inside a border. I'm trying to have a word on the border itself and I can't seem to find a way of doing it.
my HTML
<div class="img">
<img src="https://imagizer.imageshack.us/v2/321x396q90/661/oUF8n3.jpg" align="left" height=400px width=400px alt="sliced">
<div class="text">
Calibre: From 1 up to 5 mm <br>
Packing: jute or polypropylene bags , Vacuum & Carton <br>
Usage areas: It is used as the raw material for processed and fully processed hazelnuts, etc. <br>
</div>
<h2> Sliced </h2>
</div>
CSS
.img {
float: left;
border-style: solid;
border-width: 2px;
border-color: 24AB36;
padding: 20px;
}
I want the header 2 to be on the border.
How do I do this ?
if you want a text on the border ,you can use fieldset
SEE DEMO
<fieldset>
<legend>Title Text</legend>
CONTENT HERE
</fieldset>
Html:
<fieldset class="field_set">
<legend style="text-align: center;"><h2>Sliced</h2></legend>
<div class="img">
<img src="https://imagizer.imageshack.us/v2/321x396q90/661/oUF8n3.jpg" align="left" height=400px width=400px alt="sliced">
<div class="text">
Calibre: From 1 up to 5 mm <br>
Packing: jute or polypropylene bags , Vacuum & Carton <br>
Usage areas: It is used as the raw material for processed and fully processed hazelnuts, etc. <br>
</div>
</div>
</fieldset>
CSS:
.img {
float: left;
padding: 20px;
}
.field_set{
border-width:6px;
border-color:#F00;
border-style: solid;
}
I can't see how the text could fit into your div's 2px border, so I assume you mean the padding.
In that case, set .img's position to relative, set h2's position to absolute, and use some guesswork to manoeuvre it into the padding using top and left properties.
http://jsfiddle.net/prashanthcr/p2zmc4o5/1/
.img {
<other properties omitted for brevity>
position: relative;
}
h2 {
position: absolute;
top: 395px;
left: 180px;
}
Fieldset may work, but the fieldset tag is usually used within a form to group controls/input elements, like a group of checkboxes.
It may be a little more semantically correct to just style and position your h2 like so:
body {
padding: 20px;
}
.img {
float: left;
border-style: solid;
border-width: 2px;
border-color: 24AB36;
padding: 20px;
position: relative;
}
.img h2 {
position: absolute;
background: white;
top: -1.65em;
}
<div class="img">
<h2> Sliced </h2>
<img src="https://imagizer.imageshack.us/v2/321x396q90/661/oUF8n3.jpg" align="left" height=400px width=400px alt="sliced">
<div class="text">
Calibre: From 1 up to 5 mm
<br>Packing: jute or polypropylene bags , Vacuum & Carton
<br>Usage areas: It is used as the raw material for processed and fully processed hazelnuts, etc.
<br>
</div>
</div>
Or if you're not as concerned about, semantics you could use a pseudo element like so:
.img::before {
content: "Sliced";
font-size: 2em;
position: absolute;
background: white;
top: -0.75em;
left: 0.75em;
}
body {
padding: 20px;
}
.img {
float: left;
border-style: solid;
border-width: 2px;
border-color: 24AB36;
padding: 20px;
position: relative;
}
.img::before {
content: "Sliced";
font-size: 2em;
position: absolute;
background: white;
top: -0.75em;
left: 0.75em;
}
<div class="img">
<img src="https://imagizer.imageshack.us/v2/321x396q90/661/oUF8n3.jpg" align="left" height=400px width=400px alt="sliced">
<div class="text">
Calibre: From 1 up to 5 mm
<br>Packing: jute or polypropylene bags , Vacuum & Carton
<br>Usage areas: It is used as the raw material for processed and fully processed hazelnuts, etc.
<br>
</div>
</div>
I am new to css . I am trying to display my images in a perfect manner
here is my html code:
<div id="photos">
<h3>Photo title</h3>
<P class="like">Like </P>
<p class="date">date </p>
<div id="image">
<img src="something.jpg" />
</div>
<p class="about">about image goes here</p>
</div>
Now i want to style the same like this:
http://www.desolve.org/
If you want to make your image like that wall post i did it in below given fiddle link.
http://jsfiddle.net/zWS7c/1/
Css
#photos{
margin:10px;
border:solid 1px red;
font-family:arial;
font-size:12px;
}
#photos h3{
font-size:18px;
}
.date, .like{
text-align:right;
}
.about{
margin:10px;
}
#image img{
width:100%;
}
HTML
<div id="photos">
<h3>Photo title</h3>
<P class="like">Like </P>
<p class="date">date </p>
<div id="image">
<img src="http://www.desolve.org/_images/chicago_banner.jpg" />
</div>
<p class="about">about image goes here</p>
</div>
Live demo http://jsfiddle.net/46ESp/
and now set to according to your layout as like margin *padding* with or height
I think you need like this
http://jsfiddle.net/VwPna/
From http://www.w3schools.com/css/default.asp you learn easily... and also you can check other website css from firebug in your browser.
below code is that you given site css for banner class.
.banner {
background: url("../_images/gallery_banner.jpg") no-repeat scroll 0 0 transparent;
height: 350px;
margin-bottom: 4em;
overflow: hidden;
padding-left: 3.9%;
position: relative;
}
same way you can give more style their.
Here is the way it is made on the link you gave.
HTML:
<div class="banner">
<h1>We love urban photography</h1>
<p>
We’re betting you do to. Welcome to our site, a growing collection of galleries taken by a small group of passionate urban photographers. Visit our galleries, buy some of our prints, or drop us a line. While you’re at it, feel free to submit a gallery of your own.
<strong>Welcome</strong>
.
</p>
</div>
CSS:
.banner {
background: url("../_images/gallery_banner.jpg") no-repeat scroll 0 0 transparent;
height: 350px;
margin-bottom: 4em;
overflow: hidden;
padding-left: 3.9%;
position: relative;
}
.banner h1 {
color: #FFFFFF;
font-size: 2.2em;
letter-spacing: 0.1em;
padding-top: 290px;
}
.banner p {
background: none repeat scroll 0 0 rgba(123, 121, 143, 0.8);
color: #FFFFFF;
font-size: 1em;
height: 350px;
padding: 1% 1% 0;
position: absolute;
right: 0;
top: 0;
width: 21%;
}
You only need to translate that to your id's, classes and form, then you have it
There's nothing special that they've done on the reference web site. They've used the image as a background property of a div class="preview".
Here is the (x)HTML:
<section class="chicago">
<h2>Chicago</h2>
<p class="pubdate">
<time datetime="2011-04-24" pubdate="">April 2011</time>
</p>
<div class="preview"></div>
<p class="caption">Big wind, big shoulders. See a different side of Chicago.</p>
</section>
And the corresponding CSS
.chicago .preview {
background: url(../_images/sm_chicago_banner.jpg) no-repeat;
}
You can always sneak-peek by right mouse click on the website and choosing "View Page Source" or something similar, depending on your browser :)