How to lower an image vertically on a webpage - javascript

I have been defeated attempting to figure out how to lower an image on a website.
I have seen lots of people simply doing .img {...} and editing it that way, the problem is that I have more than one img that is using that tag so if I edit it that way, it will affect all tags that utilize it, which is not what I want. Simply put, I have an image that is displaying near the top of my website and I would simply want it lower. For the class, here is the code:
.bichon{
display: block;
margin-left: auto;
margin-right: auto;
height: 300px;
width: 850px;
}
for my class and then for the image insert:
<img src = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/Bichon_Fris%C3%A9_-_studdogbichon.jpg/1200px-Bichon_Fris%C3%A9_-_studdogbichon.jpg" class = "bichon">
The image is centered horizontally but I simply want to lower it a bit vertically so it's not overshadowing my navigation bar.
Thanks.

.bichon {
display: block;
margin: 50px auto 0;
height: 300px;
width: 850px;
}

You can give it a margin at the top. This will lower your image. I suggest make margin-top equal to the height of your navigation bar.
.bichon{
display: block;
margin-top: 80px; //the height of your navigation bar
margin-left: auto;
margin-right: auto;
height: 300px;
width: 850px;
}

Related

How to combine dynamic Javascript div height resizing with in-page anchor hyperlinks?

Ok, this is an unusual question, but I've been playing around with it for hours and haven't had any progress - hoping the SO community can help! 🤓
Here's the webpage in question: https://pifornerds.io/
We're using this code to dynamically set the background (the digits of pi that you see in grey) height based on the foreground content length:
<script>
// Dynamically set base height based on container contents
var containerHeight = document.getElementById("container").offsetHeight;
var baseHeight = document.getElementById("base").offsetHeight;
if (baseHeight > containerHeight) {
document.getElementById("base").style.height = containerHeight + "px";
}
</script>
CSS snippet:
.layered {
display: grid;
justify-items: left;
background-color: #222222;
max-width: 1000px;
margin: auto;
height: auto;
min-height: 100px;
overflow: hidden;
}
.layered > * {
grid-column-start: 1;
grid-row-start: 1;
}
.base {
font-family: "DejaVuSansMonoBold", courier;
color: white;
opacity: 0.1;
max-width: 100%;
height: 100%;
word-break: break-all;
margin-top: -3px;
margin-left: 10px;
margin-right: 10px;
margin-bottom: 10px;
position: static;
z-index: 1;
overflow: hidden;
}
.container {
display: block;
height: max-content;
overflow: hidden;
}
We wanted to do this so there wouldn't be a bunch of pi digits in the footer area. We think it looks "cleaner" this way.
However, the menu at the top uses anchor links to jump to content lower on the page, for example:
Roadmap
jumps to:
<a id="roadmap"></a>
Now here's the problem ...
After you click a menu anchor link, and then try to scroll back up the page to the top, you can't 🧐 ... because somehow the previous Javascript height update won't allow that.
This is as far up as I can scroll up now, after clicking "Roadmap":
Any ideas? Thanks in advance! 😀
EDIT: Here's a Fiddle: https://jsfiddle.net/imkane/kof83msy/4/
Of course it works properly there 😖
You need to remove the overflow: hidden; from .layered div.
It will probably be better to add overflow: hidden; to .base div, which is the one you set the height on.

css square limit size and position to parent div

I am trying to get a square to have a limited size and stay within the bounds of the parent div and scale cleanly. I can get one or two of these, but not all.
Setup is I have a main div, two column divs on the left, and a div that takes up the remaining space on the right. I would like the div on the right to contain the square and the bounds of the square stay within the parent div. I can get it to stay put if I don't use the padding-bottom to keep it square, but then the pic of the item looks horrible.
Take a look at my js bin. The pathway to hit the square is:
Weapons -> item b1 -> click on it to make it stay
The padding-bottom pushes it way down and outside of the parent div and blows the bottom out of the whole thing.
css
.itempanel{
display: block;
align-items: center;
position: relative;
}
.itemcontainer{
position: relative;
top: 30%;
height: 60%;
width: auto;
margin-left: auto;
margin-right: auto;
}
.itemdisplay{
display:none;
flex-direction: column;
width: 60%;
padding-bottom: 60%;
margin-left: auto;
margin-right: auto;
position: relative;
align-items: center;
overflow: hidden;
}
/* .itemdisplay::after{
content: " ";
display: block;
padding-bottom: 100%;
} */
html
<div class="itempanel">
<div class = "itemcontainer">
<div id="itemdisplay" class="itemdisplay">
<img id="itemimg" class="itemimg" src=""></img>
<div id="itemdesc" class="itemdesc">
<div id="itemtitle" class="itemtitle"></div>
<div id="itembody" class="itembody"></div>
<a id="itemclick" class="itemclick" href="">Click To Place Order</a>
</div>
</div>
</div>
</div>
Thanks for any help!
*little bit of background - girlfriend wants a skyrim wedding so building out a website for rsvp and stuff. Belethor's shop is going to be setup to help those not so nerdy shop for cheap cosplay outfits. Everything else works just like I want it, but the itempanel/itemcontainer/itemdisplay is not in the display area how I want it.
figured it out. The psuedo element has to be opposite what padding you are using. For instance, using this worked like I expected it to. it's always the simple things...
.itemdisplay::after{
content: " ";
display: block;
padding-top: 100%;
I see that you have created a class .bottommenu but I don't see it being applied anywhere on your HTML or JavaScript. If you want to display two rows using Flex-box and you are not quite sure of the height of your images or content, you could set that parent container to have a height: auto and on your child container you could use the align-self: flex-end to handle the positioning of items, and on your parent use the justify-content or align-content to your liking. Something like this:
div .parent {
display:flex;
height: auto;
min-width: 300px;
}
div .child {
align-self: center;
width: 100%;
min-height: 50%;
height: auto;
margin: 0 auto;
}
Hope that helps.

Keep image stationary, that's location is relative to nearby text

In the very middle of the screen I have a piece of text, along with an image. When the text gets longer, the image is forced to move the right, which is what its supposed to do. But what I want it to do, is keep the image in the same spot, and make the text shift over to the left instead.
(I will also be adding more names so I need this fix to be universal, not like manually changing it for each piece of text.)
(It might be hard to see, but its noticeable, and yes I'm using a template...)
My site - Updated link
I tried messing with the HTML to get the margin-right once the page is fully loaded, then when it updates the text change the margin-right to that, but it did absolutely nothing.
Any help is appreciated, I have no idea how to fix this issue.
What about this?
#banner .content {
display: inline-block;
margin-right: 1%;
max-width: 95%;
padding: 6em;
position: relative;
text-align: right;
vertical-align: middle;
z-index: 1;
float: left;
width: 66%;
}
You can solve this issue by defining the width property for the containing content layer, and then floating the image and the text to the right.
For example, if you want the right-hand side of the text to be aligned to the center of the page your image + it's left-hand margin needs to be half the width of the containing #banner .content layer.
With your image being 18rem square with a left-margin of 3rem your containing #banner .content div needs to be 42rem wide ((18 + 3) * 2).
#banner .content {
position: relative;
width: 42rem;
height: 18rem;
text-align: right;
vertical-align: middle;
/* center div.content */
margin: 0 auto;
clear: both;
display: block;
z-index: 1;
}
#banner .content .image {
width: 18em;
height: 18em;
border-radius: 100%;
vertical-align: middle;
margin-left: 3rem;
display: inline-block;
}
Content inside .content slides to the right with the span.image locked to its right-hand edge. As long as the text-container's width (header) does not exceed half the width of `.content' it will remain right-aligned 3rem from images left-hand side. Avoid using css-padding for positioning control and use css-margin properties instead.

Layout with tiles of 2 types

Is there a way to make this kind of layout with pure CSS or CSS + little JS? (click my avatar to enlarge reference image =)
My attempts to use floats and display options haven't succeed. See
http://jsfiddle.net/vdk2wns1/1/
Tiles will be used for images and iframes.
p.s. using external code (like Masonry or Isotope) is not appropriate here.
One approach would be:
#container {
max-width: 860px;
margin: 0 auto;
height: 100%;
height: 100%;
}
.block {
width: 23%;
height: 200px;
background: #ccc;
margin: 10px 1%;
float: left;
outline: 1px solid red;
}
.block:nth-of-type(3) {
clear: left;
}
.block:nth-of-type(5) {
float: right;
width: 48%;
height: 420px;
margin-top: -210px;
}
#media screen and (max-width: 640px) {
.block:nth-of-type(3) {
clear: none;
}
.block:nth-of-type(5) {
float: left;
width: 23%;
height: 200px;
margin-top: 10px;
}
}
Since it appears you wanted to adapt to different screen sizes, I changed the widths to percentages to make it responsive. This Fiddle shows the result.
If you didn't want to float Block 5 right, you could position it absolutely.
I expect that you can adapt the basic ideas to your needs.
Here is how I solve my problem after #bobdye shared his idea.
The final code (jsfiddle) is: Here
The solution appeared in 4 steps:(1). style large block with float: right;(2). clear float of the second small block;(3). set up negative margins for large block while in 3-cloumn layout;(4). make some adjusments to #media queries.
Hope this will help someone else =)

Hidden Navigation Bar Revealed on Hover But Not Full Width

So I have a script I found that allows me to hide a div within an outer div. When the outer div is hovered over the inner div appears. However both the outer and inner div are set to 100% width in CSS and without the script they work properly, spannning the entire width of the screen. With the script they span to only the min-width I set.
This is meant to be a menu bar that spans the entire width of the site at the very top.
I'm wondering if anyone knows a solution to get the div back to the full width of the screen? Hoping it's something simple I missed.
<div id="menu_outer_wrapper"
onmouseover="document.getElementById('menu_strip_wrapper')
.style.visibility = 'visible';"
onmouseout="document.getElementById('menu_strip_wrapper')
.style.visibility = 'hidden';">
And here is my CSS:
#menu_outer_wrapper {
height: 40px:
width: 100%;
float: left;
position: relative;
min-width: 800px;
}
#menu_strip_wrapper {
height: 40px;
width: 100%;
min-width: 800px;
background: #f1f1f2;
border-bottom: 1px solid #ccc;
position: relative;
float: left;
font-size: 1.3em;
}
Change : to ; and see if it will work.
#menu_outer_wrapper { height: 40px: }
jsfiddle.net/7maCW/

Categories

Resources