Border in aside - html

I have this css code:
aside{
border: 3px solid black;
width: 15%;
padding-left: 25px;
padding-right: 25px;
float:right;
background-color: red;
overflow-y: auto;
min-height: 95.3vh;
flex-warp: warp;
}
square{
border: 3px solid black;
width: 10%;
height: 10%;
background-color: green;
}
And I have this HTML
<aside>
<div class="square">
Hello
</div>
</aside>
The problem is: I don't have any border for hello as you can see in the next image:
I wold like to be like this:

Your CSS properties are being properly applied to the tag as your CSS selects the tag which is on the html page. However, when selecting a class, in your case, "square", you must select it with the class selector. Instead, in your CSS code, change square to .square
Eg.
.square{
border: 3px solid black;
width: 10%;
height: 10%;
background-color: green;
}

in your CSS, you're selecting the element square, while there's only a class square. When selecting a class, include a . at the start:
aside{
border: 3px solid black;
width: 15%;
padding-left: 25px;
padding-right: 25px;
float:right;
background-color: red;
overflow-y: auto;
min-height: 95.3vh;
flex-warp: warp;
}
.square{
border: 3px solid black;
/* width: 10%;
height: 10%; */
background-color: green;
}
<aside>
<div class="square">
Hello
</div>
</aside>
Note, this resulted in only the H in Hello to be colored green with a border. To color the entirety of Hello, I removed width: 10%; and height 10%;

Related

HTML CSS color within border

I am trying to make a small yellow square of 300x300 pixels let's say with a black border. I use:
<style>
body {
background-color: yellow;
border: 1px solid #000000;
width: 300px;
height: 300px;
}
</style>
But this gives the whole page yellow and not just the square... How can I fix this? Ty
The body tag selects the entire body of the html document. You need to give your box a id or class and then apply the CSS to that.
For example:
#box {
background-color: yellow;
border: 1px solid #000000;
width: 300px;
height: 300px;
}
<div id="box"></div>
You've applied to the body, that basically means the whole page.
Insert a DIV on the body.
HTML
<div class="div-class"></div>
CSS
.div-class{
background-color: yellow;
border: 1px solid #000000;
width: 300px;
height: 300px;
}
If you want only a square of 300x300 you need to make a div for that
**HTML:**
<div class='square'></div>
**CSS**
.square {
background-color: yellow;
border: 1px solid #000000;
width: 300px;
height: 300px;
}
Now you are applying your style to the body (whole page). That's why your whole window is yellow instead of 300x300
You need to apply the styles to a div and not to the entire body...
.square {
background-color: yellow;
border: 1px solid #000000;
width: 300px;
height: 300px;
}
<div class="square"></div>
Don't use "body", use "div"
div {
background-color: yellow;
border: 1px solid #000000;
width: 300px;
height: 300px;
}
Fiddle: https://jsfiddle.net/Lrgqp2ud/

Coloring multiple elements with a single CSS declaration

I'm new to web development in general and I am stil just a novice in HTML and CSS.
I am currently trying to minimize the number of declarations in my stylesheet to clean it up, but I have come across something I need help with.
Anyway, here is the code I'm asking about:
#div1,
#div2,
#div3 {
width: 100px; height: 100px;
border: 1px solid #f00;
background-color: #0f0;
float: left; margin: auto 5px auto;
position: relative; left: 10px; top: 10px;
}
Here, each div has a green background color. What I'm trying to do is set a different color for each div in a single declaration.
Is this possible?
Thanks. Appreciate any and all help.
The cleanest way to style these elements would be to put a common class on them, and only style the individual divs for their differences (the color).
.box {
width: 100px;
height: 100px;
border: 1px solid #f00;
float: left;
margin: auto 5px auto;
position: relative;
left: 10px;
top: 10px;
}
#div1 {
background-color: #0f0;
}
#div2 {
background-color: #0ff;
}
#div3 {
background-color: #ff0;
}
<div class="box" id="div1"></div>
<div class="box" id="div2"></div>
<div class="box" id="div3"></div>
in css code
#box{
width: 100px;
height: 100px;
border: 1px solid #f00;
float: left;
margin: auto 5px auto;
position: relative;
left: 10px;
top: 10px;
}
in html code
<div id="box" style="background:green"> </div>
<div id="box" style="background:red"> </div>
<div id="box" style="background:blue"> </div>

missing pixels css fixed div wrapper

So I'm trying to get divs to fit perfectly in a wrapper using fixed pixels for width and height. Although I'm confused as to how the pixels don't add up properly.
HTML
<div class="div1">
<img src="image.png" alt="image" class="image">
</div>
<div class="div2">
</div>
<div class="div3">
</div>
<div class="div4">
</div>
</div>
CSS
#wrapper {
height: 455px;
width: 690px;
background-color: grey;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
overflow: hidden;
white-space:nowrap;
}
.div1 {
display: inline-block;
margin-bottom: 10px;
vertical-align:top;
}
.image {
max-width: 172px;
max-height: 172px;
border-radius: 2%;
border: 4px solid blue;
}
.div2 {
height: 172px;
width: 277px;
border: 4px solid blue;
display: inline-block;
margin-left: 30px;
background-color: purple;
}
.div3 {
width: 159px;
height: 188px;
display: inline-block;
margin-left: 30px;
border-left: 4px solid blue;
border-right: 2px solid blue;
border-top: 2px solid blue;
vertical-align: top;
background-color: purple;
}
.div4 {
background: url(image.png) no-repeat center;
background-size: cover;
width: 690px;
height: 265px;
}
If the parent div is 690px wide why can't the child divs add up to 690 with calculated widths, margin and boarders.
(div1)180 + 30 + (div2)285 + 30 + (div3)165 = 690px
If you look at div 3 it's right border can't be seen. You have to reduce the width by 7px to see it.
This is also happening vertically with a 190px div3 height meant to touch div4 exactly but is off by 4px.
Is this a browser issue? Default Alignment issues I'm not aware of? I'm really curious to know why this happens!
Any feedback would be appreciated. : )
If you put comments like this in your HTML you can fix the top but for the image in the 2nd line I dont know yet I continue trying
OK SO I did put the 1st line in a div "test" and gaved him display:block and overflow hidden to take away the the space under and then I did give the div1 fixed heigth and width 180px (image+border)
#wrapper {
height: 455px;
width: 690px;
background-color: grey;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
overflow: hidden;
}
.test{
display:block;
overflow: hidden;
}
.div1 {
height:180px;
width:180px;
display: inline-block;
margin-bottom: 10px;
vertical-align:top;
}
.image {
max-width: 172px;
max-height: 172px;
border-radius: 2%;
border: 4px solid blue;
}
.div2 {
height: 172px;
width: 277px;
border: 4px solid blue;
display: inline-block;
margin-left: 30px;
background-color: purple;
}
.div3 {
width: 159px;
height: 188px;
display: inline-block;
margin-left: 30px;
border-left: 4px solid blue;
border-right: 2px solid blue;
border-top: 2px solid blue;
vertical-align: top;
background-color: purple;
}
.div4 {
background: url('http://lorempixel.com/690/265/cats') no-repeat center;
background-size: contain;
width: 690px;
height: 265px;
display:block;
overflow: hidden;
}
<div id="wrapper">
<div class="test">
<div class="div1">
<img src="http://lorempixel.com/172/172/cats" alt="image" class="image">
</div><!--
--><div class="div2">
</div><!--
--><div class="div3">
</div><!--
--> </div><div class="div4">
</div>
</div>
have you checked out box-sizing feature?
Here is some links that might be helpful.
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing

why cant i see any output in the two divs?

I cant see any output in my left and right divs.I can only see the header and footer but not the rest.I am a beginner so please try to answer in simple terms.
Kindly try to point out the error/bug instead of altering the code.
#header {
height: 50px;
width: 1600px;
border: 2px solid red;
border-radius: 5px;
background-color: Aquamarine;
position: fixed;
z-index: 1;
}
.left {
height: 500px;
width: 700px;
border: 2px solid green;
border-radius: 5px;
background-color: Lavenderblush;
float: left;
}
.right {
height: 500px;
width: 700px;
border: 2px solid blue;
border-radius: 5px;
background-color: lightblue;
float: right;
}
#footer {
height: 50px;
width: 1600px;
border: 2px solid black;
border-radius: 5px;
background-color: Yellow;
clear: both;
}
h1 {
text-align: center;
margin: auto;
color: Blue;
font-family: Verdana;
}
h4 {
text-align: center;
margin: auto;
color: Blue;
font-family: Verdana;
}
<div id="header">
<h1>My Resume</h1>
</div>
<div class="left">
<p>Hello how are u</p>
</div>
<div class="right">
<p>some random data here</p>
</div>
<div id="footer">
<h4>This is the footer</h4>
</div>
The header is position: fixed so it is taken out of normal flow (i.e. it doesn't influence the start position of content outside it) and covers the top of the content that immediately follows it.
I haven't loaded this code but likely, your fixed header with a height of 50 is hiding the text you're expecting to see. You could add a margin-top: 50px to .left and .right so they clear the fixed header.

Having elements upon other elements

So I have a header and I'm not really sure how I should code the three element boxes that should be slightly below it, but still on the end of it, like the picture below:
One way, is perhaps position absolute and margin-top, or should I perhaps slice the images, so the top of the boxes is a picture with the header background...
.box {
position: absolute;
margin-top: -30px;
}
Or how should I do it?
Next time you should post some code of what you've tried. Against my better judgement, I made exactly what you drew.
http://jsfiddle.net/xD69h/
HTML:
<div id="a">
<span id="a-text">A</span>
<div id="b">
<span id="b-text">B</span>
</div>
<div id="c">
<span id="c-text">C</span>
</div>
</div>
CSS:
#a {
width: 100%;
height: 150px;
background-color: #EFE4B0;
border: 3px solid #FFABCA;
color: #B97A57;
}
#a-text {
float: left;
}
#b {
width: 200px;
height: 150px;
background-color: #7092BE;
border: 4px solid black;
border-radius: 5px;
color: #B97A57;
float: left;
margin-top: 50px;
margin-left: 50px;
}
#c {
width: 200px;
height: 150px;
background-color: #B97A57;
border: 4px solid #B97A57;
color: white;
float: left;
margin-top: 50px;
}