css margin targeting the container instead of the images - html

I'm currently making a personal webpage using simple HTML and CSS codes. I'm currently stuck in a problem in the CSS part where I have to make 3 pictures appear in their 3 respective columns. It worked earlier before I added the div class intro. I did try removing it, undid changes, but it didn't go back to how it used to go. I'm actually self-taught and haven't been taking proper classes, so I may not understand too complicated explanation and I'm really sorry for that. Here's how my code looks.
HTML:
<div class="me">
<div class="smallcontainer">
<div class="row">
<div class="col-3">
<img src ="me/me.jpg"></img>
</div>
<div class="col-3">
<img src ="me/me3.jpg"></img>
</div>
<div class="col-3">
<img src ="me/me4.jpg"></img>
</div>
</div>
</div>
<div class="intro">
<h1>My name's Shinji</h1>
</div>
</div>
CSS:
.me {
background-color: black;
padding: 50px 50px;
}
.row {
display: flex;
}
.col-3 {
flex-basis:30%;
max-width: 250px;
margin-bottom: 30px;
}
.smallcontainer {
margin: auto;
max-width: 1080px;
margin-left:100px;
margin-right: 100px;
}
.smallcontainer img{
width: 250px;
margin-left: 20px;
}
.intro {
color:white;
font-size: 100px;
}
Here's an image on how it looked liked before it stopped working (without the black background)
Here's how it looked life AFTER. It seems like .smallcontainer img is targeting the img properly, but when I tell it to margin-left, it literally gives a margin only to the left-most picture, and not the other images. I've been frustrated about this for hours and I don't know what's going on.

.me {
background-color: black;
padding: 50px 50px;
}
.row {
display: flex;
}
.col-3 {
flex-basis:30%;
max-width: 250px;
margin-bottom: 30px;
margin: 20px; /* add this line */
}
.smallcontainer {
margin: auto;
max-width: 1080px;
margin-left:100px;
margin-right: 100px;
}
.smallcontainer img{
width: 250px;
margin-left: 20px;
}
.intro {
color:white;
font-size: 100px;
}
try this css

Related

Text position in table-style DIV when there's a picture?

I have this table-style DIV code for a used vehicle sales platform:
.mainwrapper {
border: 2px solid;
display: table;
}
.itemwrapper {
display: table-row;
width: 706px;
}
.mainwrapper {
margin-bottom: 20px;
}
.item {
width: 700px;
border: 1px solid;
padding: 1em;
background-color: blue;
color: white;
}
.item:nth-child(2) {
float: left;
margin: -2px;
}
.item1 {
display: table-cell;
text-align: left;
margin-left: -30px;
}
.item1 p {
margin-top: -30px;
}
.item-price {
width: 300px;
background-color: blue;
padding: 1em;
color: white;
text-align: center;
}
.picture, .item {
display: table-cell;
border: 1px solid;
}
.picture {
width: 90px;
margin: 1px;
border: 2px solid;
}
.picture img {
height: 185px;
}
<div class="mainwrapper">
<div class="itemwrapper">
<div class="item">1992 ELDDIS PAMPEROS XLi</div>
<div class="item-price">£1,000</div>
</div>
<div class="itemwrapper">
<div class="picture"><img src="https://complianz.io/wp-content/uploads/2019/03/placeholder-300x202.jpg.webp"></div>
<div class="item1"><p>2 berth, good condition</p></div>
</div>
</div>
<div class="mainwrapper">
<div class="itemwrapper">
<div class="item">2008 SWIFT CHALLENGER 540</div>
<div class="item-price">£13,000</div>
</div>
<div class="itemwrapper">
<div class="picture"><img src="https://complianz.io/wp-content/uploads/2019/03/placeholder-300x202.jpg.webp"></div>
<div class="item1"><p>4 berth end bedroom</p></div>
</div>
</div>
What I am trying to do is ensure the class item1 is opposite the image, with the text like this if you didn't have the £ per month div and list as table:
Basically, what I am trying to fix is the text that's in class item1 opposite the image (not with all the description or colored DIV there); see the image below.
I tried margin-left and margin-top, but it won't quite put the image opposite.
This is the result of my code:
I can't quite get it to work as I'd expected, text opposite image and size of DIV in the CSS; if anyone can help, I'd much welcome this.
It works OK - no major coding errors, but isn't quite esthetically working out, and that's the basic problem.
I'm trying this as basic HTML first before attempting anything with Javascript, just to ensure it works as a standalone design.
Edit: I tried vertical-align for text, that worked, but it's fixing the gap between image div and text that's the issue. There's a large amount of space I don't know how to fix.
As the answer for the text is solved. You can change the column width by changing the css property of item. you can do it as follows. The width was 700px in your code you can reduce to get a smaller width. I changed it to 400px.
.item {
width: 400px;
border: 1px solid;
padding: 1em;
background-color: blue;
color: white;
}

Confused on Horizontal Card

I've been really struggling making a horizontal card. I don't want to use flexbox, because I'm not very experienced with it. I want something to look like this:
I've already tried making the card and I'm able to get it to look similar although it doesn't adjust correctly to the text inputted in it.
I would recommend you learn some basic CSS in order to do simple layouts. Anyway here's a simple draft:
.container {
margin: auto;
width: 650px;
height: 150px;
padding: 0px;
text-align: center;
}
.leftbox,
.rightbox {
display: inline-block;
width: 200px;
height: 150px;
vertical-align: middle;
text-align: left
}
.leftbox {}
.rightbox {
border: 2px dashed pink;
background-color: pink;
width: 300px;
height: 146px;
}
.header {
margin: 10px 5px;
}
.data>p {
margin: 5px;
margin-left: 8px;
}
.leftbox {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/4/45/A_small_cup_of_coffee.JPG');
background-size: contain;
background-repeat: no-repeat;
}
<div class="container">
<div class="leftbox">
</div><div class="rightbox">
<div class="header">CARAMEL MACCHIATO</div>
<div class="data">
<p>SIZE</p>
<p>TOPPINGS</p>
<p>DELIVEERY</p>
<p>AMOUNT</p>
</div>
</div>
</div>

Trying to position 2 blocks next to each other [duplicate]

This question already has answers here:
How to place two divs next to each other? [duplicate]
(13 answers)
Closed 7 years ago.
I'm creating a webpage and trying to create the basic outline of my site by using div tags, however, I made a side-navigation div and body div. The size of my site is 1500px width and 1000px height, the side-navigation is 300px and body is 1200px.
I thought this would place them side by side, but, the body div, for some reason, went underneath the side-navigation div.
<body>
<div id="encase">
<div id="topNav">
<p> topNav </p>
</div>
<div id="header">
<p> header</p>
</div>
<div id="wholeBody">
<div id="sideNav">
<p> sideNav </p>
</div>
<div id="body1">
<p> body1 </p>
</div>
</div>
<div id="footer">
<p> footer </p>
</div>
</div>
and this is the css
<style>
#encase {
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
#header {
background-color:black;
width: 1490px;
height:110px;
margin-left: auto;
margin-right: auto;
padding: 5px;
}
#topNav {
background-color:green;
width: 1490px;
height: 50px;
margin-left: auto;
margin-right: auto;
padding: 5px;
}
#wholeBody {
background-color: red;
width: 1490px;
height: 690px;
margin-left: auto;
margin-right: auto;
padding: 5px;
}
#sideNav {
background-color: yellow;
width: 290px;
height: 690px;
/*margin-left: 10.25%;*/
padding: 5px;
}
#body1 {
background-color: purple;
width: 1190px;
height: 690px;
margin-left: 16%;
padding: 5px;
}
#footer {
background-color: blue;
width: 1490px;
height: 110px;
margin-left: auto;
margin-right: auto;
padding: 5px;
}
</style>
I tried to do this using percentages as well, but, percentages don't seem to work properly for me. Does anyone have any idea of how to solve my problem? Thank You.
Float your side nav to left. This should fix your problem.
#sideNav {
background-color: yellow;
width: 290px;
height: 690px;
float: left;
padding: 5px;
}
Divs are block elements - this means that, by default, each new div will start on a new line. So we need to cancel that behavior via CSS. We can use the "float" property to make the divs move next to each other:
#sideNav {
background-color: yellow;
width: 290px;
height: 690px;
/*margin-left: 10.25%;*/
padding: 5px;
float: left;
}
Once you add in the float, you can switch this all back to % and it will work fine, too.
In the future, I would encourage you to look at HTML5, if possible, as it has better tag names that can reduce the number of divs you are using. This makes for cleaner, more readable code.
Just include a float:left inside your sideNav class in order to push the other div to the right,
fiddle url: https://jsfiddle.net/eugensunic/j030jyjm/
#sideNav {
float:left;
background-color: yellow;
width: 290px;
height: 690px;
/*margin-left: 10.25%;*/
padding: 5px;
}
Your calculation about the width is wrong, you are using margin-left: 16% in #body1 which is one of the factors causing this problem otherwise float:left would have fixed the problem.
Check out this fiddle: https://jsfiddle.net/4jnbb5w3/

Div not expanding to fill the window

I've been trying to find a solution to this for days, but haven't found anything that works.
I thought I'd finally make an account on this great website, so here goes:
I am trying to have a div expand from left to right, with 170px of clearance on both sides.
However, when there is no content on the page, or only a few words, the div doesn't expand.
I've tried to add width: 100% in several different divs to try and have them take up the full space, but that either does nothing, or completely busts the page layout. for example, instead of filling out the page, the div that's supposed to hold the content moves off the right side of the screen, and also doesn't leave the 170px margin.
I hope you can be of help, my code is posted below:
Thanks in advance,
Chris
the html:
<html>
<body>
<div id="wrapper">
<div id="pagetopwrap">
</div>
<div id="pagemainliquid">
<div id="pagemainwrap">
<div id="content">
<div id="headerwrap">
<div id="header_left">
</div>
<div id="header_main">
<div id="logo_row">
<p id="logotext">Site Title</p>
</div>
<div id="menu_row">
<!-- irrelevant menu button code -->
</div>
</div>
<div id="header_right">
</div>
</div>
<div id="contentbody">
<div id="contenttext">
<p id="contenttextmakeup">Lorum Ipsum Dolor Sit Amet</p>
</div>
</div>
</div>
</div>
</div>
<div id="leftcolumnwrap">
<div id="leftcolumn">
</div>
</div>
<div id="rightcolumnwrap">
<div id="rightcolumn">
</div>
</div>
<div id="footerwrap">
<div id="footer">
</div>
</div>
</div>
</body>
</html>
the css:
It is not ordered too well, the uninteresting sides, top and footer are first, and the main part of the website at the bottom
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
background-color: #0f0f0f; /* is normally an image */
}
#wrapper {
width: 100%;
min-width: 960px;
max-width: 1920px;
margin: 0 auto;
height: 100%
}
#pagetopwrap {
height: 50px;
width: 100%;
float: left;
margin: 0 auto;
}
#pagemainliquid {
float: left;
}
#pagemainwrap {
margin-left: 170px;
margin-right: 170px;
float: left;
}
#leftcolumnwrap {
width: 170px;
margin-left:-100%;
float: left;
}
#leftcolumn {
margin: 5px;
}
#rightcolumnwrap {
width: 170px;
margin-left: -150px;
float: left;
}
#rightcolumn {
margin: 5px;
}
#footerwrap {
width: 100%;
float: left;
margin: 0 auto;
clear: both;
bottom:50px;
}
#footer {
height: 0px;
margin: 5px;
}
#headerwrap {
width: 100%;
margin: 0 auto;
}
#header_left {
background-color: #ff0000; /* is normally an image */
width:25px;
height:200px;
float:left;
}
#header_right {
background-color: #ff0000; /* is normally an image */
width:25px;
height:200px;
margin-left: 0px;
float:right;
position:relative; top:-200px;
}
#header_main {
background-color: #00ff00; /* is normally an image */
margin-left: 25px;
margin-right: 25px;
height:200px;
background-size: 100% 200px;
}
#contentbody {
background-color: #E2E2E2;
border-radius: 10px;
margin-top:10px;
border: 1px solid #A7A7B2;
}
#contenttext {
margin-left:10px;
margin-right:10px;
}
#logo_row {
height:150px;
width:100%;
float:left;
}
#logotext {
margin-top:20px;
margin-left:10px;
vertical-align: middle;
font-size: 55px;
font-family: "Arial Black", Arial;
}
#contenttextmakeup {
margin-top:12px;
margin-left:10px;
vertical-align: middle;
}
#menu_row {
width:100%;
}
button.menubutton {
/* irrelevant button markup */
}
http://jsfiddle.net/w9qLh6tp/ if that helps, I've seen it a lot around here :)
Instead of using !important, save yourself a headache in figuring out why important works.
CSS = cascading style sheets. You have a selector with more specificity which is why your width property isnt changing. Figuring out the route of the problem will save you time in the future when this happens again (and it will)
For example, if I styled something like so
#container .red { width: 50% }
updating the style using .red without the #container in front of it has less specificity. So if they are both modifying the same property, the one with more prevalence will take effect. This is true for media queries as well.
Fixed here http://jsfiddle.net/w9qLh6tp/1/
#pagemainwrap {
margin-left: 170px;
margin-right: 170px;
float: left;
width: 100% !important; // set it highest priority
border: 3px red solid; // border is set just for demonstration
}
set the width to be 100% with priority (!important) that will override any other css styling.

div overlaps on another div when screen size reduced

Below is a simple html web page that is responsive except for one div (goplay) that over lays other parts of the page when screen size is reduced, instead of dropping below the image.
Styling Sheet external
#wrapperlp {
width: 100%;
margin: auto;
}
#media screen and (max-width: 800px) {
#wrapperlp {
width: 90%;
min-width: 100px;
}
}
#headerlp {
font-size: 30px;
color: white;
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
}
#para {
font-size: 20px;
color: white;
text-align: center;
}
#game_img {
height: 250px;
width: auto;
margin-bottom: -30px;
position: relative;
display: inline-block;
float: left;
margin-top:-30px;
padding-top: 5px;
max-width: 100%;
}
#goplay {
position: relative;
display: inline-block;
float: right;
margin-top:-250px;
margin-left:80px
}
#spacer {
height: 40px;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 900px;
padding-top:20px;
}
Html which is set to call the above css
<div id="wrapperlp">
<div style="background-image: url(https://.jpg); height: 430px; width: 1000px; margin-left: auto; margin-right: auto; max-width: 100%;">
<div id="headerlp">Some Text</div>
<div id="para">More Text</div>
<div id="game_img"><a href="//www.youtube.com/" target="_blank"><br />
<img src="https://.png" height="auto"/></a></div>
</div>
</div>
<div id="goplay">----form----/div>
<div id="spacer">
<div style="position: relative; float: left">Text</div>
</div>
margin-top and left should in %. thats y its overlay becoz of px
First off, it looks like you're missing a couple of divs.
The goplay div doesn't have a closing tag, (well it's got one but not that works)
Also your bottom spacer looks like it's missing a closing tag as well. Not sure if it's supposed to wrap anything or what.
Perhaps you had some copy/paste errors?
Normally if you set a negative margin it will overwrite other divs. You should, for the most part, not have to use negative margins.