I'm new to coding and have spent days trying to figure out how to get rid of this blank space at the bottom of my web page.
I've put my CSS code through a CSS corrector online, put red borders around all elements to try and identify elements that might be creating large borders or paddings, changed the height and width of the HTML & body elements - to no avail. Alternatively, I've tried changing the 'px' value for my map (as it is a large number and it might be pushing everything further down), but can't seem to achieve the position I want, when I do so.
Attached is all my CSS:
html, body {
background-color: #222909;
font-family: "Comic Sans MS", cursive, sans-serif;
color: yellow;
}
/* Here I have created a class to apply a solid, round and yellow border around all my frog images. As I
wanted the images to be consistent with the rest of the web page design. */
.Frog_Blog_Border {
border-style: solid;
border-color: yellow;
border-radius: 50%;
}
/* Here the style and position of the Frog Blog header is determined. I decided I wanted the header to be
centered so used the'diplay', 'margin-left' and 'margin-right' option to do so. Again, I chose the map font. I wanted the border
to stand out, so created a solid and rounded yellow border around it using the 'border' options in CSS. */
.Frog_Blog_Header {
display: block;
margin-left: auto;
margin-right: auto;
width: 904px;
height: 150px;
border-style: solid;
border-color: yellow;
border-radius: 5px;
position: relative;
}
/* Here the style and position of the map div is determined using an ID selector. I decided I wanted to fit images around
my map, so resized the map and used 'diplay', 'margin-left' and 'margin-right' to centre it. Again, I chose the map font
to be 'Comic Sans MS' for consistency, the font to be bold to stand out and font size to be 16pt. I wanted the map to stand
out, so created a solid and rounded yellow border around it using the 'border' options in CSS. */
#map {
width: 600px;
height: 500px;
font-family: "Comic Sans MS", cursive, sans-serif;
font-weight: bold;
font-size: 16px;
display: block;
margin-left: auto;
margin-right: auto;
border-style: solid;
border-color: yellow;
border-radius: 5px;
position: relative; /* Here I wanted to position my map so that it was below the header and text of the page, so used the
'position' option set to 'relative' to move the image around the page. */
bottom: 1105px; /* 'bottom' here refers to how far from the bottom in pixels the image was moved. */
left: 5px;
}
/* Here, I am styling the text for the map legend, which is taking the same properties of being yellow, bold and 'Comic
Sans MS from the body and html styling above, but adding some padding and alignment to it, so that the accompanying legend colour
scale does not overlap with the text. */
.legend {
font-size: small;
padding-top: 10px;
text-align: left;
line-height: 18px;
position: relative; /* Here I am using the 'position' option set to 'relative' to move the image left and from the bottom, up
the page. */
bottom: 1100px;
left: 325px;
}
/* Here I am styling the legend colour scale, adding alignment and margins to ensure it doesn't overlap with the text. */
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
}
.Yellow_Eyed_Frog_Caption {
position: relative;
left: 35px;
}
.Agalychnis_Annae{
position: relative;
}
.Black_Eyed_Frog_Caption {
position: relative;
left: 45px;
}
/* This is positioning the second frog image. */
.Agalychnis_Moreletii {
position: relative;
top: 2px;
}
.Lemur_Leaf_Frog_Caption {
position: relative;
bottom: 560px;
left: 950px;
}
/* This is positioning the third frog image. */
.Lemur_Leaf_Frog {
position: relative;
bottom: 560px;
left: 950px;
}
.Lemur_Leaf_Frog_2_Caption {
position: relative;
bottom: 560px;
left: 950px;
}
/* This is positioning the fourth frog image. */
.Lemur_Leaf_Frog_2 {
position: relative;
bottom: 565px;
left: 950px;
width: 300px;
height: 200px;
}
/* This is positioning the source link for the Frog Blog header below the main Frog Blog header image. */
.Image_Source {
position: relative;
left: 860px;
}
/* This is positioning the from image source link found below the third frog image. */
.Image_Source_2 {
position: relative;
left: 40px;
top: 610px;
}
/* This is positioning the tile source link found below the third frog image. */
.Tile_Source {
position: relative;
left: 40px;
top: 607px;
}
Related
I'm having trouble with a SCSS/CSS styling idea, I want to fill the space before or after the last line of a heading with a solid line. The last line of text does not have a set width (it varies depending on screen size) I'm open to any suggestions.
Here's what I want to achieve when the text is aligned right or left.
|Here is some text on screen| |Here is some text on screen|
|very cool -----------------| or |----------------- very cool|
| | | |
| | | |
EDIT Code added for clarity:
HTML
<h1>You're the painter, we just want to see you paint.</h1>
CSS (that is how far I've got)
h1{
font-family: "doesntMatter";
font-style: bold;
font-size: 2rem;
text-align: left;
}
h1::after{
display: inline-block;
line-height: 0;
position: relative;
bottom: 2.5rem;
border-bottom: 10px solid red;
width: 100%;
content: "";
}
I found a solution to my problem, if you take this code here and run it, the last line will be struck through.
.container {
width: 100%;
padding-inline: 2rem;
}
.text {
font-style: bold;
font-size: 2.5rem;
line-height: 2.5rem;
position: relative;
overflow-x:hidden;
}
.text::after {
position: absolute;
left:0;
bottom: 0.9rem;
width: 100%;
border-bottom: 0.4rem solid #000;
content: "";
}
<section class="container">
<h1 class="text">You're the painter, we are just the paint, brushes and canvas</h1>
</section>
But if you remove left:0; from the text::after styling, it magically jumps over to fill the blank space at the end.
I added a margin-left: 1rem to give the things some breathing room but yea I really don't know what's going on.
I don't know how it works but it just kind of does, if the .text{} element has overflow-x: hidden applied to it then the effect will cutoff at the width of the header.
.container {
width: 100%;
padding-inline: 2rem;
}
.text {
font-style: bold;
font-size: 2.5rem;
line-height: 2.5rem;
position: relative;
overflow-x: hidden;
}
.text::after {
position: absolute;
bottom: 0.9rem;
width: 100%;
margin-left: 1rem;
border-bottom: 0.4rem solid #000;
content: "";
}
<section class="container">
<h1 class="text">You're the painter, we are just the paint, brushes and canvas</h1>
</section>
That is one way to do the effect, if you want the line to spill off the page, you apply overflow-x: hidden to the .container{} element and remove if from the .text{}... since my container is 100% width the line goes off the page and works as intended.
.container {
width: 100%;
padding-inline: 2rem;
overflow-x: hidden;
}
.text {
font-style: bold;
font-size: 2.5rem;
line-height: 2.5rem;
position: relative;
}
.text::after {
position: absolute;
bottom: 0.9rem;
width: 100%;
margin-left: 1rem;
border-bottom: 0.4rem solid #000;
content: "";
}
<section class="container">
<h1 class="text">You're the painter, we are just the paint, brushes and canvas</h1>
</section>
The line responds to any changes in the width of the last line. There's a few edge cases that I'm going to have to look into like if the last line of text practically fills the entire width of the header, then there's just a little nub at the end.
But it's been fixed! I hope this helps anyone in the future that couldn't figure out the right combination of words to google to find a solution.
Building on what you have already, this snippet puts the text within a span element. This enables a white padding which can overwrite that part of the red line which is under the actual text.
h1 {
font-family: "doesntMatter";
font-style: bold;
font-size: 2rem;
text-align: left;
position: relative;
}
h1>span::after {
display: inline-block;
position: absolute;
border-bottom: 10px solid red;
width: 100%;
left: 0;
margin-top: -11px;
content: "X";
color: transparent;
z-index: -1;
}
h1>span {
background: white;
padding-bottom: 11px;
}
<h1><span>You're the painter, we just want to see you paint.</span></h1>
Note - it's a little bit hacky, including positioning 1px different from the height of the line. This is because on modern screens which use more than one screen pixel for a CSS pixel the system can 'leave behind' traces of color when it is positioning (e.g. a screen pixel - not a whole CSS pixel).
I'm trying to emulate this effect via CSS:
The reason this is an issue is because it needs to be re-usable. The red underline's size should be dictated by the text length, but also overflow its container in a predictable manner, e.g.:
<div>
<h1>This</h1>
<h1>Cool</h1>
<h1>Effect</h1>
</div>
The red underline should extend outside the div by 10px on the left, and then also overflow the text itself by roughly 50px on the right. So, all told, the red line is +60 pixels wider than the text itself.
How can I achieve this effect without doing it manually each time? I've had no success with pseudo elements, and box-shadow won't extend on the left and right as I need it to.
Pseudo elements was the answer for me. Setting z-index on the :after element to get it positioned behind the parent element is a neat trick. The elements can't be block elements, but other than that it seemed straightforward.
html {
min-height: 100%;
}
body {
min-height: 100%;
background: linear-gradient(to bottom, #0b122f 0%, #17457d 100%);
padding: 20px;
}
h1 {
position: relative;
display: inline-block;
color: #fff;
font-family: sans-serif;
font-size: 100px;
font-weight: 300;
margin: 0;
}
h1:before {
content: "";
background: red;
height: .25em;
width: calc( 100% + 60px);
position: absolute;
bottom: .15em;
left: -10px;
z-index: -1;
}
<div>
<h1>This</h1>
<br />
<h1>Cool</h1>
<br />
<h1>Effect</h1>
</div>
use <h1><span>This</span></h1> make effect in span and adjust red box to use padding to were's you want :
h1 span {
position: relative;
font-size: 100px;
font-weight: 300;
margin: 0;
padding:0 0 0 20px;
}
h1 span::before {
content: "";
background: red;
height: .25em;
position: absolute;
bottom: .15em;
z-index: -1;
width: 100%;
left: 0;
}
like: https://jsfiddle.net/bdmpqkme/1/
All this examples mentioned above by lalit bhakuni and JasonB work really well, but only when you don't have any section with a background behind this underlined text.
The z-index: -1 will put the line you want behind the text like you want and also behind any other parent sections. In case any of these parent sections have a background, the line will be hidden (behind).
Other solution, not so clean, but solves all our problems is by adding an extra element inside of your heading:
HTML
<div class="div-with-background">
<h1><span>This</span></h1>
<br />
<h1><span>Cool</span></h1>
<br />
<h1><span>Effect</span></h1>
</div>
CSS
.div-with-background {
background-color: #333;
}
h1 {
position: relative;
display: inline-block;
color: #fff;
font-family: sans-serif;
font-size: 100px;
font-weight: 300;
margin: 0;
}
h1::before {
content: "";
background: red;
height: .25em;
width: calc( 100% + 60px);
position: absolute;
bottom: .15em;
left: -10px;
}
h1 > span {
position: relative;
}
In this case, we don't even need to use the z-index property.
I'd like the have a visual border, pipe or some other separator between the <span> elements in the following snippet. The trouble is that when they flow into a new line I end up with a border at the beginning of the line. How can i apply some kind of border between elements only when they are on the same line? I am completely open to changing the markup or taking another approach, however I've tried a number of things from flexbox to floats so far without success.
Stipulations:
I do not want to use javascript for this.
span content is dynamic so media queries won't work since I can't know the width of the elements or where they might break.
Is this even possible? I've already looked at this similar question but the answers there either use js or media queries.
The snippet below is a basic example and I've put the spans in a resizeable div only to demonstrate the flow problem at smaller widths.
.resizable {
resize: horizontal;
overflow: scroll;
border: 1px solid black;
height: 95vh;
box-sizing: border-box;
min-width: 120px;
max-width: 100%;
padding: 10px;
}
span {
font-size: 18px;
font-family: sans-serif;
}
span+span {
margin-left: 10px;
border-left: 2px solid #aaa;
padding-left: 10px;
display: inline-block;
}
<div class="resizable">
<span>dog</span><span>cat</span><span>elephant</span><span>potato</span><span>boston clam chowder</span>
</div>
You can fix this by using a container with the overflow hidden, and a negative margin to “drag” the elements at the beginning of the line outside of that overflow area.
(In this particular example the overflow:hidden is not really necessary, the outer scrolling element already takes care of that, but in different scenarios it might be needed.)
The 1.5em value used here is a bit of a magic number; you might want to replace it with a pixel value, since you’re using pixels for the border and its spacing from the text already - but in general, you should be able to find “working” values with a little bit of experimentation.
.resizable {
resize: horizontal;
overflow: scroll;
border: 1px solid black;
height: 95vh;
box-sizing: border-box;
min-width: 120px;
max-width: 100%;
padding: 10px;
}
.container {
margin-left: -1.5em;
width: calc(100% + 1.5em);
}
span {
font-size: 18px;
font-family: sans-serif;
margin-left: 10px;
border-left: 2px solid #aaa;
padding-left: 10px;
display: inline-block;
}
<div class="resizable">
<div class="container">
<span>dog</span><span>cat</span><span>elephant</span><span>potato</span><span>boston clam chowder</span><span>dog</span><span>cat</span><span>elephant</span><span>potato</span><span>boston clam chowder</span><span>dog</span><span>cat</span><span>elephant</span><span>potato</span><span>boston clam chowder</span>
</div>
</div>
Here's a pure CSS method that also works for elements that are centered.
The ::before and ::after of adjacent tiles are used to create a dark strip between the elements, then, the ::before of the container clips the lighter stuff out of existence.
Downsides - Getting the perfect color can be tricky as there's lots of maths involved.
section {
text-align: center;
position: relative;
}
section::before {
/* Clip light areas to pure white, leaving only boarders*/
mix-blend-mode: color-dodge;
background: #bbb;
z-index: -1000;
/* Fill Parent */
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
content: "";
}
span {
position: relative;
display: inline-block;
box-sizing: border-box;
padding: 10px;
}
/* Spans slightly overlap creating darker lines between elements*/
span::before {
left: -1px;
}
span::after {
right: -1px;
}
span::before, span::after {
position: absolute;
content: "";
display: block;
width: 10px;
height: 100%;
background: #555;
top: 0;
z-index: -1001;
mix-blend-mode: multiply;
}
<section>
<span>Hello</span><span>Cats</span><span>Fish</span><span>Dogs</span><span>Hello</span><span>Cats</span><span>Fish</span><span>Dogs</span><span>Hello</span><span>Cats</span><span>Fish</span><span>Dogs</span>
</section>
For some reason, this code does not work in Stackoverflow's JSFiddle. Here's a link to JSFiddle where it does work:
https://jsfiddle.net/mdsimmo/vwu7xbjp/2/
I am using font awesome icons and I want them position on top of each other. I also want to the user to be able to interact with them by clicking on them.
The problem is that the element of each icon is taking up more space than it needs and is overlapping. So when the user thinks they are clicking on the top one, they end up activating a listener for the bottom one.
Here is the html:
<div class="arrow-container">
<i class="fa fa-sort-asc comment-vote up-vote-comment" aria-hidden="true"></i>
<i class="fa fa-sort-desc comment-vote down-vote-comment" aria-hidden="true"></i>
</div>
and the css:
.black-arrow{
color: black;
}
.up-vote-comment{
width: 100%;
}
.down-vote-comment{
position: relative;
top: -15px;
}
.comment-vote{
font-size: 20px;
}
it is important for me that the two arrows line up exactly on the same line horizontally and be quite close vertically, as they are in this fiddle.
Anyone know how to make them not overlap in occupied element space? I tried setting the height of the bottom arrow but that just made the occupied space of the element be above the arrow itself.
You can use the following code:
EDIT
.comment-vote {
font-size: 20px;
position: initial;
width: 100%;
display: inline-block;
}
.arrow-container {
width: 30px;
position: absolute;
top: 0px;
left: 0px;
}
This way you can use the .arrow-container class to position the arrows.
Combination of containers and absolute positioning. You can even have a 2px space between arrows.
.comment-icon-wrapper {
height: 10px;
width: 12px;
overflow: hidden;
position: relative;
margin-bottom: 2px;
}
.comment-vote {
position: absolute;
display: block;
}
.comment-vote {
font-size: 20px;
line-height: 20px;
display: block;
background-color: red;
}
.comment-vote:hover {
cursor:pointer;
}
.down-vote-comment {
position: relative;
top: -9px;
background-color: blue;
}
https://jsfiddle.net/w6ybL3nb/5/ (backgrounds to highlight spaces)
If you add a height to the top arrow and some z-indexes so the top arrow stacks over the bottom arrow, you can achieve what you want:
.black-arrow {
color: black;
}
.up-vote-comment {
width: 100%;
height: 12px;
z-index: 2;
overflow: hidden;
}
.down-vote-comment {
top: -13px;
z-index: 1;
}
.comment-vote {
font-size: 20px;
display: inline-block;
position: relative;
}
Updated fiddle - I have added console logging to the click of the arrows so you can see which one is being pressed
I have a dynamic element which will be capable of scaling in size, its position could be placed anywhere on the screen. I'm basically trying to create an "elbow" section.
What this "elbow" needs is an extension arm at the top right... Funny thing is, while I have the position and size correct, for some reason, the pseudo element is not showing up in the grey I'm calling... (see attached image showing Element Inspector highlighting the element in the correct size and position, but not in the same grey)...
I have a JSFiddle here of the code: https://jsfiddle.net/eliseo_d/6p9z8xr3/
HTML:
<div class="elbow-1-toprt-wide0-grey1">elbow 1</div>
CSS:
html {
background-color: rgb(0,0,0);
}
body {
margin: 5px;
}
div[class$='-grey1'] {
background-color: rgb(102,102,102);
}
div[class^='elbow-'] {
/* default settings */
color: rgb(0,0,0);
font-size: 14pt;
height: 14px;
margin-bottom: 4px;
margin-right: 4px;
overflow: hidden;
padding-bottom: 7px;
padding-left: 10px;
padding-right: 10px;
text-align: right;
text-transform: uppercase;
width: 84px;
position: relative;
}
div[class^='elbow-1-'] {
padding-top: 46px;
}
/* Initial curve */
div[class^='elbow-'][class*='-toprt-'] {
border-top-left-radius: 42px;
}
/* elbow bar */
div[class^='elbow-'][class*='-toprt-']:after {
content: '';
height: 30px;
left: 104px;
top: 0;
position: absolute;
}
div[class^='elbow-'][class*='-wide0-']:after {
width: 21px;
}
div[class^='elbow-'][class*='-wide0-'][class$='-grey0']:after {
background-color: rgb(51,51,51);
}
div[class^='elbow-'][class*='-wide0-'][class$='-grey1']:after {
background-color: rgb(102,102,102);
}
I can't seem to figure out what I'm missing?
Anyone know what I'm missing? Thanks in advance.
The ::after element is being shown with the background, your problem is that div[class^='elbow-'] is set to overflow:hidden;, which is hiding the pseudo element.
Simply remove overflow:hidden;
JSFiddle Demo