I am currently developing my first chrome extension that uses html/css/javascript. I have a problem, and so far none of the questions in stackoverflow seem to answer my problem.
I have a layout that looks like a phone, just like an IPhone. Basically, my button inside the homepage-bottom ID div is not working properly. I want the homepage-bottom-inside ID div(it's color is black) round.
It currently looks like this.
Please explain my error, and fix the code.
#homepage-bottom-content {
margin-right: auto;
margin-left: auto;
margin-top: 15px;
margin-bottom: 15px;
height: 50px;
padding-top: 10px;
width: 50px;
background-color: black;
border-radius: 100px;
}
#homepage-bottom-content-inside {
height: 25px;
width: 25px;
background-color: black;
border: #E6E6E6 2px solid;
border-radius: 7.5px;
margin-right: auto;
margin-left: auto;
}
<div id="homepage-bottom">
<div id="homepage-bottom-content">
<div id="homepage-bottom-content-inside"></div>
</div>
</div>
EXTRA
This is how the overall "phone" looks.
#homepage {
margin: auto;
height: 620px;
width: 330px;
background-color: lightblue;
border-radius: 40px;
border: black 7px solid;
}
#homepage-content {
margin: auto;
height: 470px;
cursor: cell;
width: 270px;
background-color: white;
border-radius: 7.5px;
border: 3px black solid;
}
#homepage-bottom-content {
margin-right: auto;
margin-left: auto;
margin-top: 15px;
margin-bottom: 15px;
height: 50px;
padding-top: 10px;
width: 50px;
background-color: black;
border-radius: 100px;
}
#homepage-bottom-content-inside {
height: 25px;
width: 25px;
background-color: black;
border: #E6E6E6 2px solid;
border-radius: 7.5px;
margin-right: auto;
margin-left: auto;
}
<div id="homepage">
<div id="homepage-top">
<div id="homepage-top-content">
<div style="background-color: black; height: 15px; width: 15px; margin-right: auto; margin-left: auto; margin-top: 10px; margin-bottom: 10px; border-radius: 100px;"></div>
<div style="background-color: black; height: 10px; width: 50px; margin-right: auto; margin-left: auto; margin-top: 20px; margin-bottom: 15px; border-radius: 20px;"></div>
</div>
</div>
<div id="homepage-content">
</div>
<div id="homepage-bottom">
<div id="homepage-bottom-content">
<div id="homepage-bottom-content-inside"></div>
</div>
</div>
</div>
The padding-top is part of total height, so height:40px + padding-top:10px does it for homepage-bottom-content.
Be aware that the border thickness is also part of the total height.
#homepage-bottom-content {
margin-right: auto;
margin-left: auto;
margin-top: 15px;
margin-bottom: 15px;
height: 40px;
padding-top: 10px;
width: 50px;
background-color: black;
border-radius: 100px;
}
#homepage-bottom-content-inside {
height: 25px;
width: 25px;
background-color: black;
border: #E6E6E6 2px solid;
border-radius: 7.5px;
margin-right: auto;
margin-left: auto;
}
<div id="homepage-bottom">
<div id="homepage-bottom-content">
<div id="homepage-bottom-content-inside"></div>
</div>
</div>
Extra
Your phone fixed:
#homepage {
margin: auto;
height: 620px;
width: 330px;
background-color: lightblue;
border-radius: 40px;
border: black 7px solid;
}
#homepage-content {
margin: auto;
height: 470px;
cursor: cell;
width: 270px;
background-color: white;
border-radius: 7.5px;
border: 3px black solid;
}
#homepage-bottom-content {
margin-right: auto;
margin-left: auto;
margin-top: 15px;
margin-bottom: 15px;
height: 40px;
padding-top: 10px;
width: 50px;
background-color: black;
border-radius: 100px;
}
#homepage-bottom-content-inside {
height: 25px;
width: 25px;
background-color: black;
border: #E6E6E6 2px solid;
border-radius: 7.5px;
margin-right: auto;
margin-left: auto;
}
<div id="homepage">
<div id="homepage-top">
<div id="homepage-top-content">
<div style="background-color: black; height: 15px; width: 15px; margin-right: auto; margin-left: auto; margin-top: 10px; margin-bottom: 10px; border-radius: 100px;"></div>
<div style="background-color: black; height: 10px; width: 50px; margin-right: auto; margin-left: auto; margin-top: 20px; margin-bottom: 15px; border-radius: 20px;"></div>
</div>
</div>
<div id="homepage-content">
</div>
<div id="homepage-bottom">
<div id="homepage-bottom-content">
<div id="homepage-bottom-content-inside"></div>
</div>
</div>
</div>
Related
I'm making a food pyramid where when you hover over certain segments of the pyramid, buttons will appear but I am unsure how to code it. I want the .button1 and .button2 to appear when the mouse is hovered over .triangle and then I plan to do more buttons that appear when you hover over each trapezoid.
The following is the code.
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="assignment01.css">
</head>
<body>
<h1 style="font-family: helvetica">
<center>Figure 1</center>
</h1>
<div class="triangle">
<div class="circle1 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<div class="trapezoid ">
<div class="circle2 "></div>
</div>
<div class="trapezoid1 ">
<div class="circle3 "></div>
</div>
<div class="trapezoid2 ">
<div class="circle4 "></div>
</div>
<div class="trapezoid3 ">
<div class="circle5 "></div>
</div>
<div class="trapezoid4 ">
<div class="circle6 "></div>
</div>
<h2 style="font-family: helvetica">
<center>My Food Pyramid</center>
</h2>
<h2 style="font-family: helvetica">
<center id="datetime"></center>
</h2>
<script>
var dt = new Date();
document.getElementById("datetime").innerHTML = dt.toLocaleDateString();
</script>
</body>
</html>
CSS
.triangle {
border-bottom: 150px solid #FF6347;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
height: 0;
width: 0;
margin-left: auto;
margin-right: auto;
white-space: nowrap;
display: block;
}
.trapezoid {
border-bottom: 100px solid #f58c57;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 220px;
margin-left: auto;
margin-right: auto;
padding-bottom: 20px;
}
.trapezoid1 {
border-bottom: 100px solid #fff894;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 360px;
margin-left: auto;
margin-right: auto;
padding-bottom: 20px;
}
.trapezoid2 {
border-bottom: 100px solid #83ccde;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 480px;
margin-left: auto;
margin-right: auto;
}
.trapezoid3 {
border-bottom: 100px solid #a87d5c;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 600px;
margin-left: auto;
margin-right: auto;
}
.trapezoid4 {
border-bottom: 100px solid #9effa6;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 720px;
margin-left: auto;
margin-right: auto;
}
.circle1 {
height: 45px;
width: 45px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 100px;
margin-left: -22px;
margin-right: auto;
opacity: 0.7;
}
.circle2 {
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 45px;
margin-left: 87px;
margin-right: auto;
opacity: 0.7;
}
.circle3 {
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 45px;
margin-left: 158px;
margin-right: auto;
opacity: 0.7;
}
.circle4 {
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 219px;
margin-right: auto;
opacity: 0.7;
}
.circle5 {
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 279px;
margin-right: auto;
opacity: 0.7;
}
.circle6 {
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 339px;
margin-right: auto;
opacity: 0.7;
}
.button1 {
background-color: white;
border: none;
padding: 20px;
height: 5px;
width: 5px;
display: inline-block;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 0px;
top: -18px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button2 {
background-color: white;
border: none;
padding: 20px;
height: 5px;
width: 5px;
display: inline-block;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -147px;
top: -18px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.triangle:hover+.button1 {
display: inline-block;
}
You can define a class like 'piece' for each element and when you hover any element of this class, you change display:none to display: inline-block from buttons. Like the example above:
.triangle {
border-bottom: 150px solid #FF6347;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
height: 0;
width: 0;
margin-left: auto;
margin-right: auto;
white-space: nowrap;
display: block;
}
.trapezoid {
border-bottom: 100px solid #f58c57;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 220px;
margin-left: auto;
margin-right: auto;
padding-bottom: 20px;
}
.trapezoid1 {
border-bottom: 100px solid #fff894;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 360px;
margin-left: auto;
margin-right: auto;
padding-bottom: 20px;
}
.trapezoid2 {
border-bottom: 100px solid #83ccde;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 480px;
margin-left: auto;
margin-right: auto;
}
.trapezoid3 {
border-bottom: 100px solid #a87d5c;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 600px;
margin-left: auto;
margin-right: auto;
}
.trapezoid4 {
border-bottom: 100px solid #9effa6;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
height: 0;
width: 720px;
margin-left: auto;
margin-right: auto;
}
.circle1{
height: 45px;
width: 45px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 100px;
margin-left: -22px;
margin-right: auto;
opacity: 0.7;
}
.circle2{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 45px;
margin-left: 87px;
margin-right: auto;
opacity: 0.7;
}
.circle3{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 45px;
margin-left: 158px;
margin-right: auto;
opacity: 0.7;
}
.circle4{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 219px;
margin-right: auto;
opacity: 0.7;
}
.circle5{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 279px;
margin-right: auto;
opacity: 0.7;
}
.circle6{
height: 50px;
width: 50px;
background-color: #ffffff;
border-radius: 50%;
display: inline-block;
margin-top: 25px;
margin-left: 339px;
margin-right: auto;
opacity: 0.7;
}
.button1 {
background-color: white;
border: none;
padding: 20px;
height: 5px;
width: 5px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: 0px;
top: -18px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.button2{
background-color: white;
border: none;
padding: 20px;
height: 5px;
width: 5px;
display: none;
margin-left: 0px;
cursor: pointer;
border-radius: 50%;
position: relative;
left: -147px;
top: -18px;
opacity: 0.7;
text-align: center;
text-decoration: none;
line-height: 5px;
}
.piece:hover .button1, .piece:hover .button2 {
display: inline-block;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="assignment01.css">
</head>
<body>
<h1 style = "font-family: helvetica"><center>Figure 1</center></h1>
<div class="triangle piece">
<div class="circle1 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<div class="trapezoid piece">
<div class="circle2 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<div class="trapezoid1 piece">
<div class="circle3 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<div class="trapezoid2 piece">
<div class="circle4 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<div class="trapezoid3 piece">
<div class="circle5 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<div class="trapezoid4 piece">
<div class="circle6 "></div>
<div class="button1"><span>+</span></div>
<div class="button2"><span>-</span></div>
</div>
<h2 style = "font-family: helvetica"><center>My Food Pyramid</center></h2>
<h2 style = "font-family: helvetica"><center id="datetime"></center></h2>
<script>
var dt = new Date();document.getElementById("datetime").innerHTML = dt.toLocaleDateString();
</script>
</body>
</html>
OBS.: Just correct the style bacause second piece button2 is going too much to the left.
I made a simple example using a normal rectangular div, but it should work the same adding your complex CSS:
.button1, .button2 { /* make the two buttons better visible */
background-color: red;
}
.triangle { /* make .triangle more visible */
height: 80px;
width: 80px;
background-color: yellow;
}
/* This is the important part of the CSS which makes the buttons appear when .triangle is hovered and disappear when the mouse leaves .triangle again */
.triangle > * { /* selects all direct children of .triangle */
display: none; /* hide the selected elements */
}
.triangle:hover > * {
display: initial; /* change the display property to its initial value */
}
<div class="triangle">
<div class="button1">
<span>+</span>
</div>
<div class="button2">
<span>-</span>
</div>
</div>
I want to keep the #typebox fixed in its position even when chatboxes move on scrolling up and down.
I have tried keeping the position:relative for #innerbox (which is container of #typebox) and position:absolute for #typebox but this did not meet the requirement.
I also tried keeping position:fixed for #typebox but this vanishes the #typebox and the scrollbar as well.
I tried referring to other similar question but could not find what am I doing wrong.
Any help would be appreciated :)
#outerbox {
width: 300px;
height: 500px;
border-radius: 25px;
padding: 10px;
border: 2px solid DodgerBlue;
margin: 20px;
box-shadow: 10px 10px 5px grey;
}
#innerbox {
width: 240px;
height: 440px;
padding: 10px;
border: 2px solid DodgerBlue;
margin: 20px;
background-image: url("allo.gif");
overflow-y: auto;
overflow-x: hidden;
position: relative;
}
#chatbox1 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #0097A7;
margin-top: 100%;
margin-right: 50%;
color: #FFFFFF;
text-align: center;
}
#chatbox2 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #00BCD4;
margin-top: 10%;
margin-left: 30%;
color: #FFFFFF;
text-align: center;
}
#chatbox3 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #00BCD4;
margin-top: 10%;
margin-right: 30%;
color: #FFFFFF;
text-align: center;
}
#chatbox4 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #00BCD4;
margin-top: 10%;
margin-left: 30%;
color: #FFFFFF;
text-align: center;
}
#typebox {
width: 200px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: 2px solid white;
box-shadow: 5px 5px 2px grey;
margin-top: 50%;
position: absolute;
background-color: #FFFFFF;
color: #808080;
}
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-4" "col-xs-4"></div>
<div class="col-md-4" "col-xs-4">
<h1>Vaas</h1>
</div>
<div class="col-md-4" "col-xs-4"></div>
</div>
<div class="row">
<div class="col-md-4" "col-xs-4"></div>
<div class="col-md-4" "col-xs-4" id="outerbox">
<div id="innerbox">
<div id="chatbox1"></div>
<div id="chatbox2"></div>
<div id="chatbox3"></div>
<div id="chatbox4"></div>
<div id="typebox">
<i class="fa fa-plus" style="color:#00BFFF; padding-right:3px;" aria-hidden="true"> Say something...</i>
<i class="fa fa-smile-o" style="color:#808080;padding-left:30px; padding-right:5px;" aria-hidden="true"></i> <i class="fa fa-microphone" style="color:#808080;" aria-hidden="true"></i>
</div>
</div>
</div>
<div class="col-md-4" "col-xs-4"></div>
</div>
</div>
</body>
Try this:
Apply position: relative to outerbox instead of innerbox and keep absolute positioning of the typebox (I have given bottom: 50px for illustration)
#outerbox {
width: 300px;
height: 500px;
border-radius: 25px;
padding: 10px;
border: 2px solid DodgerBlue;
margin: 20px;
box-shadow: 10px 10px 5px grey;
position: relative;
}
#innerbox {
width: 240px;
height: 440px;
padding: 10px;
border: 2px solid DodgerBlue;
margin: 20px;
background-image: url("allo.gif");
overflow-y: auto;
overflow-x: hidden;
}
#chatbox1 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #0097A7;
margin-top: 100%;
margin-right: 50%;
color: #FFFFFF;
text-align: center;
}
#chatbox2 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #00BCD4;
margin-top: 10%;
margin-left: 30%;
color: #FFFFFF;
text-align: center;
}
#chatbox3 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #00BCD4;
margin-top: 10%;
margin-right: 30%;
color: #FFFFFF;
text-align: center;
}
#chatbox4 {
width: 140px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: #009688;
background-color: #00BCD4;
margin-top: 10%;
margin-left: 30%;
color: #FFFFFF;
text-align: center;
}
#typebox {
width: 200px;
height: 8%;
border-radius: 25px;
padding: 10px;
border: 2px solid white;
box-shadow: 5px 5px 2px grey;
margin-top: 50%;
bottom: 50px;
position: absolute;
background-color: #FFFFFF;
color: #808080;
}
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-4" "col-xs-4"></div>
<div class="col-md-4" "col-xs-4">
<h1>Vaas</h1>
</div>
<div class="col-md-4" "col-xs-4"></div>
</div>
<div class="row">
<div class="col-md-4" "col-xs-4"></div>
<div class="col-md-4" "col-xs-4" id="outerbox">
<div id="innerbox">
<div id="chatbox1"></div>
<div id="chatbox2"></div>
<div id="chatbox3"></div>
<div id="chatbox4"></div>
<div id="typebox">
<i class="fa fa-plus" style="color:#00BFFF; padding-right:3px;" aria-hidden="true"> Say something...</i>
<i class="fa fa-smile-o" style="color:#808080;padding-left:30px; padding-right:5px;" aria-hidden="true"></i> <i class="fa fa-microphone" style="color:#808080;" aria-hidden="true"></i>
</div>
</div>
</div>
<div class="col-md-4" "col-xs-4"></div>
</div>
</div>
</body>
For a current project of mine, I'm working on a website for a clan of sorts. They've asked me to create a grid of games that they play, and I seem to be struggling with that.
Each individual div considsts of a background-image and a p element for the title of the game. Currently, for every different game, I have to create a new div and a new class in my style sheet, and I only end up changing the left-margin a bit and changing that background image's filepath. It feels like a bit of a waste of time to me.
The code is as follows:
(HTML)
<div id="content" align="center">
<div class="content-box">
<div class="content-box-game-one">
<p>Just Cause 2</p>
</div>
<div class="content-box-game-two">
<p>War Thunder</p>
</div>
<div class="content-box-game-three">
<p>Borderlands 2</p>
</div>
<br />
<div class="content-box-game-four">
<p>Heroes and Generals</p>
</div>
<div class="content-box-game-five">
<p>Grand Theft Auto V</p>
</div>
<div class="content-box-game-six">
<p>Dirty Bomb</p>
</div>
<br />
<div class="content-box-game-seven">
<p>PayDay 2</p>
</div>
<div class="content-box-game-eight">
<p>Team Fortress 2</p>
</div>
<div class="content-box-game-nine">
<p>Coming soon...</p>
</div>
</div>
(CSS)
#content {
margin-top: 3px;
}
.content-box {
width: 1150px;
height: 100%;
}
.content-box-game-one {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 80px;
background-image: url('http://i.imgur.com/ZZtELB6.png');
background-size: 400px;
}
.content-box-game-two {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 20px;
background-image: url('http://war-thunder-hack.marioapps.net/assets/cheatmp/images/background.jpg');
background-size: 400px;
}
.content-box-game-three {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 20px;
background-image: url('http://www.hardcoregamer.com/wp-content/uploads/2012/10/borderlands2.jpg');
background-size: 400px;
}
.content-box-game-four {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 80px;
background-image: url('http://www.gamewallpapers.com/previews_480x300/wallpaper_heroes_and_generals_01.jpg');
background-size: 400px;
}
.content-box-game-five {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 20px;
background-image: url('http://static.guim.co.uk/sys-images/Guardian/Pix/audio/video/2012/11/15/1352984366518/Grand-Theft-Auto-V-005.jpg');
background-size: 400px;
}
.content-box-game-six {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 20px;
background-image: url('https://metrouk2.files.wordpress.com/2012/11/article-1354195970386-16454a86000005dc-11033_636x353.jpg');
background-size: 400px;
}
.content-box-game-seven {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 80px;
background-image: url('http://www.gamechup.com/wp-content/uploads/2013/08/payday-2-featured-1.jpg');
background-size: 400px;
}
.content-box-game-eight {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 20px;
background-image: url('https://upload.wikimedia.org/wikipedia/en/5/59/TF2_Group.jpg');
background-size: 400px;
}
.content-box-game-nine {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 20px;
background-image: url('http://www.exoticindia.com/religious/sfa47.jpg');
background-size: 400px;
}
.content-box p {
margin-top: 80px;
font-family: Lobster;
font-weight: bold;
font-size: 30px;
color: white;
}
Is there anyway I can just create one class on my stylesheet and have it so that the background image will change? Any other ways around this problem?
Thanks!
Since all other properties are same other than background-image you can create one general class like:
.content-box-game {
border: 3px solid black;
border-radius: 5px;
margin-top: 20px;
width: 300px;
height: 200px;
float: left;
margin-left: 80px;
background-size: 400px;
}
Then you only need to specify a background-image property in your other classes.
.content-box-game-one{
background-image: url('http://www.hardcoregamer.com/wp-content/uploads/2012/10/borderlands2.jpg');
}
Add both classes to your div
<div class="content-box-game content-box-game-one">
<p>Borderlands 2</p>
</div>
I would like to a 4 blocks layout like this:
I've been trying things with float but I really don't master it.
How can I do that ?
Thanks
My HTML code:
<div id="colonne_gauche">1</div>
<div id="colonne_gauche2">2</div>
<div id="colonne_droite">4</div>
<div id="colonne_centre">3</div>
My CSS code:
#colonne_gauche
{
margin-top: 5px;
-float: left;
width: 420px;
height: 145px;
border: 1px solid #818181;
background: red;
}
#colonne_gauche2
{
float: left;
margin-top: 5px;
width: 420px;
height: 145px;
border: 1px solid #818181;
background: orange;
}
#colonne_centre
{
float: right;
margin-top: 5px;
margin-left: 5px;
margin-right: 5px;
width: 310px;
height: 295px;
border: 1px solid #818181;
background: green;
}
#colonne_droite
{
float: right;
margin-top: 5px;
width: 220px;
height: 295px;
border: 1px solid #818181;
background: blue;
}
I just played a little with the floating and see what that does.
This should help you: DEMO.
HTML:
<div id="header">Header</div>
<div id="stackleft">
<div id="one">1</div>
<div id="two">2</div>
</div>
<div id="stackright">
<div id="three">3</div>
<div id="four">4</div>
</div>
CSS:
#header {
width: 960px;
padding: 50px 0px;
color: black;
border: 1px solid black;
margin: 5px;
text-align: center;
}
#one {
width: 420px;
text-align: center;
padding: 0px;
height: 145px;
color: black;
border: 1px solid black;
margin: 5px;
}
#two {
width: 420px;
text-align: center;
padding: 0px;
height: 145px;
color: black;
border: 1px solid black;
margin: 5px;
}
#three {
width: 310px;
text-align: center;
padding: 0px;
height: 295px;
color: black;
border: 1px solid black;
margin: 5px;
display: inline-block;
}
#four {
width: 220px;
text-align: center;
padding: 0px;
height: 295px;
color: black;
border: 1px solid black;
margin: 5px;
display: inline-block;
}
#stackleft, #stackright {
display: inline-block;
vertical-align: top;
}
http://jsfiddle.net/xam558e3/
Using DIV's inside of other DIV's you can easily control how they appear, and where they appear. You should look up the box model, it may shed some light for you on this.
<div style="width:310px">
<div style="width:303px; height: 100px; background-color: #6495ed;"></div>
<div style="width:100px; height: 100px; background-color: red; float:left; margin: 1px;"></div>
<div style="width:100px; height: 100px; background-color: red; float:left; margin: 1px;"></div>
<div style="width:100px; height: 100px; background-color: red; float:left; margin: 1px;"></div>
<div style="width:303px; height: 100px; background-color: red; float:left; margin: 1px;"></div>
</div>
I'm trying to make it so the boxes are next to each other, but when I add another box it goes to the bottom. I'm fairly new to html and css, how would you do that? If you could code that part for me and explain it, I'd be really grateful.
Image:
http://i61.tinypic.com/9lj0ox.png
<div id="leftside">
<div id="portrait"></div>
<div id="leftbox"><b>About Me</b><p>test</p></div>
<style>
#leftside {
position: fixed;
margin-left: 0px;
top: 125px;
width: 220px;
height: 485px;
padding: 20px;
background: rgba(255,255,255,0.5);
background-repeat: repeat;
background-attachment: fixed;
border: 1px solid #000;
border-radius: 5px;
}
#portrait {
margin-left: 0px;
width: 200px;
height: 200px;
padding: 10px;
background: url(http://i861.photobucket.com/albums/ab179/treeskywind/profile/kidosmall2_zps57444730.png );
border: 1px solid #000;
border-radius: 5px;
color: #fff;
font-family: Century Gothic;
}
#leftbox {
height: 230px;
width: 200px;
margin-left: 0px;
margin-top: 20px;
background-color: #6855A7;
color: #fff;
border: 1px solid #000;
border-radius: 5px;
padding: 10px;
font-family: Century Gothic;
text-align: justified;
overflow: auto;
}
</style>
</div>
<div id="rightside">
<div id="box1"><b>Links</b></div>
<div id="rightbox"><b>My Interests</b></div>
<div id="box2">test</div>
<style>
#rightside {
position: fixed;
margin-left: 0px;
top: 125px;
width: 600px;
height: 485px;
padding: 20px;
background: rgba(255,255,255,0.5);
background-repeat: repeat;
background-attachment: fixed;
border: 1px solid #000;
border-radius: 5px;
margin-left: 280px;
}
#box1 {
margin-left: 0px;
width: 200px;
height: 160px;
padding: 10px;
background: #6855A7;
border: 1px solid #000;
border-radius: 5px;
color: #fff;
font-family: Century Gothic;
}
#rightbox {
height: 260px;
width: 200px;
margin-left: 0px;
margin-top: 20px;
background-color: #6855A7;
color: #fff;
border: 1px solid #000;
border-radius: 5px;
padding: 10px;
font-family: Century Gothic;
text-align: justified;
overflow: auto;
}
#box2 {
width: 200px;
height: 160px;
padding: 10px;
background: #6855A7;
border: 1px solid #000;
border-radius: 5px;
color: #fff;
font-family: Century Gothic;
margin-left: 250px;
}
</style>
</div>
you can use:
display: inline-block;
btw put your above your page html!!