Size and position of div

Asked

Viewed 1,967 times

0

Hello everyone I’m trying for a div next to another div as you can see below, I’m not sure what I’m doing wrong here’s the code:

.div {
    background-color: #cecece; 
    margin-right: 700px; 
    padding-bottom: 424px;
    border: inset
}
<!DOCTYPE html>
<html>
<head>
	<title>C#</title>
</head>
<body>
  <div class="div">
   
  </div>
  <div style="background-color: #000; margin-left: 400px; padding-bottom: 424px">
   w
  </div>
</body>
</html>


The code is not performing very well in this post so if you need to see the result in this page you must copy the code.

1 answer

3


As divs by default have display block, this means that the div will be placed under the previous element:

EX:

div {
  height: 100px;
  width: 50px;
}
#div1 {
  background-color: red;
}
#div2 {
  background-color: green; 
}
<div id="div1"></div>
<div id="div2"></div>

To remedy this you can put one float:left:

div {
  height: 100px;
  width: 50px;
  float: left;
}
#div1 {
  background-color: red;
}
#div2 {
  background-color: green; 
}
<div id="div1"></div>
<div id="div2"></div>

Can also put display:inline-block, but note that by default this will put a margin between the elements (I don’t understand why, but it happens) that can be removed if put font-size:0 in the father. In this last example, you can see that withdraw font-size:0 of #caixa_pai

#caixa_pai {
  font-size:0;
}
.caixa_filho {
  height: 100px;
  width: 50px;
  display: inline-block;
}
#div1 {
  background-color: red;
}
#div2 {
  background-color: green; 
}
<div id="caixa_pai">
  <div class="caixa_filho" id="div1"></div>
  <div class="caixa_filho" id="div2"></div>
</div>

  • Thanks for the help is that during the waiting time the only solution I found was this .Block {background-color: #cecece; margin-left: 300px; margin-top: -430;padding-bottom: 424px;border: inset; margin-right: 600px;} worked but was bad

  • Hehe this must not be good :P . Obgado, glad that solved @Pekira

  • I was here continuing to program and I would like to know if there is any way to put a textbox in a div without the div starting to change the size <!-- language: lang-js --> <! DOCTYPE html> <html> <head> <title>C#</title> </head> <body> <!-Divcode-> <div class="code"> <textarea Rows="10" readonly="readonly" placeholder="""> </textarea> </div> div<!-Block->#Xa; <div="block" style="> &#div; /<div> <!-Divscript-> <div class="script"> </div> </body> </html>

  • 'cause I have no idea how through this as you possessed

  • You can always put a fixed length on the div: ex: width:200px; and the textbox: display:block;width:100%;. I haven’t tried it but I’m pretty sure it works @Pekira

  • OK I’ll try right away

  • You have an example: https://jsfiddle.net/g5of2np2/1/

  • this part of the textbox put css or html?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.