gpt4 book ai didi

html - 显示内联 block 不起作用,第二个 div 出现在下方,并且在检查元素上显示为显示 : block

转载 作者:行者123 更新时间:2023-11-28 10:01:50 25 4
gpt4 key购买 nike

我真的在这段代码中苦苦挣扎,这是我之前苦苦挣扎的 CSS 我是左右浮动 div,但工作中的网页设计师告诉我改用内联 block 和 % 的高度和宽度和以前一样我使用像素......我的“主”div有问题当我在chrome中使用检查元素功能时它不会水平对齐它说它是一个 block 元素而不是一个内联 block 元素我什么都没有do 似乎改变了这一点!

  <!DOCTYPE html>
<html>
<head>
<title> Chillblast </title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div id="container">
<div id="header">
<!-- <img src="img.jpg" width="800" height="200" alt="logo" /> setting
image as header -->
<h1> <u>Lorem Ipsum</u></h1>
<script type="text/javascript">
var myvar = "Welcome";
alert(myvar);
</script>
</div>

<div id="content">
<div id="navi">
<h3> <u>Navigation</u></h3>
<ul>
<li><a class="selected" href="index.html">Home</a></li> <!-- creating a css class
called selected as this is
the page we are on -->
<li><a href="form.html"> Quote me</a></li>
<li><a href="index.html"> Gallery</a></li>
<li><a href="index.html">Contact us</a></li>
</div>

<div id="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum urna nec nibh varius aliquam.<br>
Pellentesque sit amet justo lectus. Sed vehicula purus in porta fermentum. Integer malesuada non augue id sollicitudin.<br>
Curabitur non purus elementum, porttitor nisl nec, vestibulum mauris. Ut euismod urna tortor.<br>
Curabitur consequat mi eu sapien laoreet, vitae pharetra magna porttitor. Cum sociis natoque penatibus et<br>
magnis dis parturient montes, nascetur ridiculus mus. Aliquam et placerat massa. Fusce felis tellus, <br>
gravida at convallis vitae, vestibulum eu sapien. Suspendisse sed sapien egestas, scelerisque risus ut,<br>
molestie dui. Etiam lacinia tellus a aliquet faucibus. </p>
</div>
</div>
<div id="footer">
Footer Copyright &copy; Andrew doyle
</div>
</div>
</body>
</html>


My CSS is as follows:


body{
/* dont need to call id*/
background-color:black;
background-repeat: no-repeat;
font-family: lobster, baskerville, sans-serif, arial; /* set the font for the whole body,
use back up fonts too*/
}

a{ /*In the same way we targeted the body tag we can target the a tag*/
text-decoration: none; /* links not underlined*/
color: white; /* links are coloured red*/


}

p{

color:#FFFFFF;
}

#container{

height: 100%;
width: 100%;
margin: 0 auto;
background-image:url("spc.png");


}

h1{ /* using commas i could set it for h1,h2,h3*/
margin:0; /* gets rid of margin*/
}

#header {
width:100%;
height:10%;
background:transparent; /* background of div id set to blue */ /* text set to red*/
text-align: center; /* aligns text in the header to middle of page*/
padding: 20px;
color: white;
}

/* #content{ padding-left:10px and all seperate directions or can use
padding: 10px 10px 10px 10px
1st is top 2nd is right 3rd is bottom and 4th is the left and since want
all the same we can shorten even more and just put 10px*/

#content {

width: 100%;
height: 90%;
margin: 0 auto;
}





#navi{
display: inline-block;
width:20%;
height:70%;
text-align: center; /*as divs always start a new line to stop this we use float*/
background: transparent;
color: white;
margin: 0 auto;

}
#navi ul{

list-style-type: none; /* gets rid of the bullet points after targeting ul*/
/*gets rid of padding */

}




}
#main{

display: inline-block;
width: 80%;
height:70%;
background:transparent;
margin: 0 auto;

}



#main p{


color: white;
}




#footer{
display: block;
height: 20%;
width: 100%; /* this is to clear of all floating elements or will not appear
below, clearing both lets the div element get past all
the floating div elements*/
padding: 0px;
background: transparent;
color: white;
text-align: right;
}

最佳答案

尝试 DEMO

 #navi li {
display:inline-block;
}

关于html - 显示内联 block 不起作用,第二个 div 出现在下方,并且在检查元素上显示为显示 : block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24698026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com