I write this code: jsfiddle.net/4ror198u/1/
That zombi class is ok and when my mouse goes over it it show me that pink box, but why when my mouse is over blue i canno't see the green class ?
Can you help me where im wrong and what i need to do to fix this problem, also to suggest some examples why this thing hapening and how to prevent it in feature.
Thanx in advance! :)
You have misplaced the class green with class shell so I rearranged that and I placed some attributes to the .green class in order the difference to be obvious.The blue box works exactly as the effect that you have for the zombieone.
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
color: yellow;
margin: 0;
padding: 0;
}
.zombitwo {
height: 200px;
width: 200px;
background: pink;
border-radius: 10px;
text-align: center;
line-height: 200px;
display: none;
}
.zombione:hover + .zombitwo {
display: block;
}
.black{
//border: 5px solid red;
background-color: black;
width: 300px;
height: 300px;
}
.blue{
width: 300px;
height: 300px;
background-color: blue;
//border: 5px solid blue;
}
.green{
height: 300px;
width: 300px;
background-color: green;
color:red;
//border: 5px solid green;
display: none;
text-align:center;
}
.blue:hover + .green{
display: block;
}
</style>
<div class="zombione">test</div>
<div class="zombitwo">work</div>
<div class="wrapper">
<div class="shell">
<div class="black">
<div class="blue">
<div class="shell">
</div>
</div>
<div class="green">
<div class="shell">
<div class="sblack"></div>
<div class="sred"></div>
<div class="sgreen">It works fine!!</div>
</div>
</div>
</div>
</div>
</div>
Related
I'm looking for a html/css solution to obtain following behavior for some html element:
It must force a new-line after it, that is, no other element can be in the same line after it. Similar to a div or display: block.
Its size must be the one of his content, not expand to all line. Similar to a span or display: inline or display: inline-block.
We can choice the kind of element (div, span, ...) but it must be a single one, no possible to use, by example, a span followed of a br.
In the following example there are several tries to obtain this behavior, all them unsuccessful.:
body {
width: 200px;
}
#yellow {
height: 50px;
background-color: yellow;
border: 2px solid black;
}
#red {
height: 50px;
background-color: red;
border: 2px solid black;
display: inline-block;
}
#blue {
height: 50px;
background-color: blue;
border: 2px solid black;
display: inline-block;
}
.child {
width: 50px;
}
<!DOCTYPE html>
<html>
<body>
<div id="yellow">
<div class="child"></div>
</div>
<div id="red">
<div class="child"></div>
</div>
<div id="blue">
<div class="child"></div>
</div>
</body>
</html>
The yellow div expands over all line width, exceeding the 50px of its content. The red one ( a div with display inline-block) has the correct size, but doesn't forces next div (the blue one) to appear in next line.
Can you use max-width: fit-content? Not supported on IE or Edge.
body {
width: 200px;
}
#yellow {
height: 50px;
background-color: yellow;
border: 2px solid black;
max-width: -webkit-fit-content;
max-width: -moz-fit-content;
max-width: fit-content;
}
#red {
height: 50px;
background-color: red;
border: 2px solid black;
display: inline-block;
}
#blue {
height: 50px;
background-color: blue;
border: 2px solid black;
display: inline-block;
}
.child {
width: 50px;
}
<!DOCTYPE html>
<html>
<body>
<div id="yellow">
<div class="child"></div>
</div>
<div id="red">
<div class="child"></div>
</div>
<div id="blue">
<div class="child"></div>
</div>
</body>
</html>
You can apply display: table to #yellow as display: table acts as an inline-block element by being as wide as its content, but also acts as a block element by adding a line break before and after the element.
body {
width: 200px;
}
#yellow {
display: table;
height: 50px;
border-collapse: separate; /** added to allow padding to apply if used **/
background-color: yellow;
border: 2px solid black;
}
#red {
height: 50px;
background-color: red;
border: 2px solid black;
display: inline-block;
}
#blue {
height: 50px;
background-color: blue;
border: 2px solid black;
display: inline-block;
}
.child {
width: 50px;
}
<div id="yellow">
<div class="child"></div>
</div>
<div id="red">
<div class="child"></div>
</div>
<div id="blue">
<div class="child"></div>
</div>
Personally, I don't recommend using table based designs as they're not responsive, but due to your requirements I use so you don't have to use any other element and also it's supported by all the major browsers.
Hope this helps. Small change to the original body width and making the display for Yellow to be inline-block will make it work.
body {
width: 50px;
}
#yellow {
height: 50px;
background-color: yellow;
border: 2px solid black;
display: inline-block;
}
#red {
height: 50px;
background-color: red;
border: 2px solid black;
display: inline-block;
}
#blue {
height: 50px;
background-color: blue;
border: 2px solid black;
display: inline-block;
}
.child {
width: 50px;
}
<!DOCTYPE html>
<html>
<body>
<div id="yellow">
<div class="child"></div>
</div>
<div id="red">
<div class="child"></div>
</div>
<div id="blue">
<div class="child"></div>
</div>
</body>
</html>
I typed this code and i want boxes like in a row (horizontal) , but it appears like in a column(vertical).
I just want these colour boxes horizontal with spaces between them. (like top layer)
Ex- main box(grey) , and 7 boxes in the top ( with margins & paddings)
Like this : 4 color Boxes in a bigger grey color box.
I used "div" tag , but it only work for first one only
How could i align those boxes and have spaces between them ?
Thanks in advance.
.header_box {
width: 100%;
background: #ccc;
display: -webkit-box;
}
.box {
width: 150px;
height: 40px;
margin: 20px;
}
.box1 {
background: white;
}
.box2 {
background: #ccc;
}
.box3 {
background: #ccc;
}
.box4 {
background: #ccc;
}
.box5 {
background: #ccc;
}
.box6 {
background: #ccc;
}
.box7 {
background: #ccc;
}
.middle_box {
width: 100%;
background: white;
display -webkit-box;
padding: 20px;
}
.box0 {
width: 150px;
height: 150px;
margin: 20px;
padding: 10px;
}
.box11 {
background: blue;
}
.box12 {
background: yellow;
}
.box13 {
background: red;
}
.box14 {
background: green;
}
.circle1 {
height: 100px;
width: 100px;
background-color: yellow;
border-radius: 50%;
}
.circle2 {
height: 100px;
width: 100px;
background-color: yellow;
border-radius: 50%;
border: 2px solid red;
}
.circle3 {
width: 100px;
height: 50px;
/* as the half of the width */
background-color: gold;
border-top-left-radius: 110px;
/* 100px of height + 10px of border */
border-top-right-radius: 110px;
/* 100px of height + 10px of border */
border: 4px solid gray;
border-bottom: 0;
}
.img-circle {
width: 100px;
height: 100px;
border-radius: 50%;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<section>
<div class="header_box">
<div class="box box1" align="center">
logo
</div>
<div class="box box6" align="center">
</div>
<div class="box box7" align="center">
</div>
<div class="box box2" align="center">
TEXT 01
</div>
<div class="box box3" align="center">
TEXT 02
</div>
<div class="box box4" align="center">
TEXT 03
</div>
<div class="box box5" align="center">
TEXT 04
</div>
</div>
<div>
<img src="C:\Users\Dimuth De Zoysa\Pictures\sample3.png" width="100%">
</div>
<div class="middle_box">
<div class="box0 box11">
</div>
<div class="box02 box12">
</div>
<div class="box0 box13">
</div>
<div class="box0 box14">
</div>
</div>
<div class="circle1">
</div>
<div class="circle2">
</div>
<div class="circle3">
</div>
<div>
<img class="img-circle" src="C:\Users\Dimuth De Zoysa\Downloads\sunsetmypht.jpg">
</div>
</section>
</body>
</html>
Your example doesn't work because you forgot a colon in the display directive.
You have:
display -webkit-box;
Use:
display: -webkit-box;
That being said, look into flex and flex-direction (I usually use this article).
To get the circles on a horizontal row you need to wrap them in a div which has the same display rule as the boxes (for example by assigning the middle_box class to the div).
.products
{
width: 100%;
height: 500px;
background: gray;
}
.box
{
width: 250px;
height: 300px;
background: darksalmon;
border: 1px solid #000;
}
<div class="products">
<div class="box">
<p>Ola</p>
</div>
</div>
I want the paragraph to appear inside a square. The code as it is shows that the 2 divs are together. And only the content inside the paragraph appears.
This image ilustrates the format I intend:
.products
{position:relative;
width: 100%;
height: 500px;
background: gray;
}
.box
{p
width: 250px;
height: 300px;
background: darksalmon;
border: 1px solid #000;
}
<div class="products">
<p>Ola</p>
</div>
<div class="box">
</div>
try this...
background-color: ;
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
Have you tried
<p class="box">...</p>
removing the div wrapping your paragraph?
So I have a red bar inside a container which lies between two black boxes. The boxes are fixed in size while the red bar and the container are based on percentages.
My goal is to reduce the size of the container, as well as the red bar without the right black box breaking onto the next line. I was able to resolve the issue via custom mathematical calculations in JavaScript, but I want to keep functionality and design separate. I feel that there must be some way to solve this with CSS without hacks or extra div tags.
How can this be achieved?
.container {
width: 80%;
height: 40px;
background: grey;
}
.box {
height: 50%;
border: 15px solid black;
border-top: none;
border-bottom: none;
float: left;
}
.bar {
width: 80%;
height: 100%;
background: red;
float: left
}
<div class="container">
<div class="box"></div>
<div class="bar"></div>
<div class="box"></div>
</div>
JSFiddle
CSS3 has a new flex display style supported by the major browsers.
.container {
display: webkit-flex;
display: flex;
height: 40px;
background: grey;
}
.box {
height: 50%;
border: 15px solid black;
border-top: none;
border-bottom: none;
}
.bar {
width: 100%;
height: 100%;
background: red;
}
<div class="container">
<div class="box"></div>
<div class="bar"></div>
<div class="box"></div>
</div>
To set the box elements to a specific width use min-width rather than width
Use calc() in your CSS. It's from CSS3, but supported in all major browsers, even IE9.
.bar {
width: calc(100% - 60px);
}
.container {
width: 80%;
height: 40px;
background: grey;
}
.box {
height: 50%;
border: 15px solid black;
border-top: none;
border-bottom: none;
float: left;
}
.bar {
width: calc(100% - 60px);
height: 100%;
background: red;
float: left
}
<div class="container">
<div class="box"></div>
<div class="bar"></div>
<div class="box"></div>
</div>
Try "table" layout
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.container {
width: 80%;
height: 40px;
background: grey;
display: table;
}
.container > div {
display: table-row;
}
.container > div > div {
display: table-cell;
vertical-align: top;
}
.box {
height: 50%;
margin: 0 7px;
border: 15px solid black;
border-top: none;
border-bottom: solid 1px black;
/*float: left;*/
}
.bar {
width: 80%;
height: 100%;
background: red;
/*float: left*/
}
</style>
</head>
<body>
<div class="container">
<div>
<div>
<div class="box"></div>
</div>
<div class="bar"></div>
<div>
<div class="box"></div>
</div>
</div>
</div>
</body>
</html>
So I'm quite new to writing code (about a few weeks) and I've hit a wall while writing code for my website. I want to have a layout like this:
But I can't figure out how to put the two boxes side by side. One box will be a video explaining my website, while the other box will be a sign up registration form.
I want the boxes to be next to each other, with about an inch of separation between them.
I also need help with the width of my website's header. Right now it looks like the header doesn't fit on the page, causing a horizontal scroll. Kind of like this:
I want it so that the entire website is like one big box, and all the content is inside that box. Can someone please help me? Much appreciated. Thank you in advance.
http://jsfiddle.net/kkobold/qMQL5/
#header {
width: 100%;
background-color: red;
height: 30px;
}
#container {
width: 300px;
background-color: #ffcc33;
margin: auto;
}
#first {
width: 100px;
float: left;
height: 300px;
background-color: blue;
}
#second {
width: 200px;
float: left;
height: 300px;
background-color: green;
}
#clear {
clear: both;
}
<div id="header"></div>
<div id="container">
<div id="first"></div>
<div id="second"></div>
<div id="clear"></div>
</div>
This will work
<div style="width:800px;">
<div style="width:300px; float:left;"></div>
<div style="width:300px; float:right;"></div>
</div>
<div style="clear: both;"></div>
<div style="display: inline">
<div style="width:80%; display: inline-block; float:left; margin-right: 10px;"></div>
<div style="width: 19%; display: inline-block; border: 1px solid red"></div>
</div>
I am just giving the code for two responsive divs side by side
*{
margin: 0;
padding: 0;
}
#parent {
display: flex;
justify-content: space-around;
}
#left {
border: 1px solid lightgray;
background-color: red;
width: 40%;
}
#right {
border: 1px solid lightgray;
background-color: green;
width: 40%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="parent">
<div id="left">
lorem ipsum dolor sit emet
</div>
<div id="right">
lorem ipsum dolor sit emet
</div>
</div>
</body>
</html>
This is just a simple(not-responsive) HTML/CSS translation of the wireframe you provided.
HTML
<div class="container">
<header>
<div class="logo">Logo</div>
<div class="menu">Email/Password</div>
</header>
<div class="first-box">
<p>Video Explaning Site</p>
</div>
<div class="second-box">
<p>Sign up Info</p>
</div>
<footer>
<div>Website Info</div>
</footer>
</div>
CSS
.container {
width:900px;
height: 150px;
}
header {
width:900px;
float:left;
background: pink;
height: 50px;
}
.logo {
float: left;
padding: 15px
}
.menu {
float: right;
padding: 15px
}
.first-box {
width:300px;
float:left;
background: green;
height: 150px;
margin: 50px
}
.first-box p {
color: #ffffff;
padding-left: 80px;
padding-top: 50px;
}
.second-box {
width:300px;
height: 150px;
float:right;
background: blue;
margin: 50px
}
.second-box p {
color: #ffffff;
padding-left: 110px;
padding-top: 50px;
}
footer {
width:900px;
float:left;
background: black;
height: 50px;
color: #ffffff;
}
footer div {
padding: 15px;
}
You can do it in three ways:
Float Method
<div class="float-container">
<div class="float-child">
<div class="green">Float Column 1</div>
</div>
<div class="float-child">
<div class="blue">Float Column 2</div>
</div>
</div>
.float-container {
border: 3px solid #fff;
padding: 20px;
}
.float-child {
width: 50%;
float: left;
padding: 20px;
border: 2px solid red;
}
Flexbox Method
<div class="flex-container">
<div class="flex-child magenta">
Flex Column 1
</div>
<div class="flex-child green">
Flex Column 2
</div>
</div>
.flex-container {
display: flex;
}
.flex-child {
flex: 1;
border: 2px solid yellow;
}
.flex-child:first-child {
margin-right: 20px;
}
CSS Grid Method
<div class="grid-container">
<div class="grid-child purple">
Grid Column 1
</div>
<div class="grid-child green">
Grid Column 2
</div>
</div>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
}
Source
Have a look at CSS and HTML in depth you will figure this out. It just floating the boxes left and right and those boxes need to be inside a same div. http://www.w3schools.com/html/html_layout.asp might be a good resource.
Regarding the width of your website, you'll want to consider using a wrapper class to surround your content (this should help to constrain your element widths and prevent them from expanding too far beyond the content):
<style>
.wrapper {
width: 980px;
}
</style>
<body>
<div class="wrapper">
//everything else
</div>
</body>
As far as the content boxes go, I would suggest trying to use
<style>
.boxes {
display: inline-block;
width: 360px;
height: 360px;
}
#leftBox {
float: left;
}
#rightBox {
float: right;
}
</style>
I would spend some time researching the box-object model and all of the "display" properties. They will be forever helpful. Pay particularly close attention to "inline-block", I use it practically every day.