简体   繁体   English

HTML5和CSS如何创建单独的ul和移动 <aside> 向左转

[英]Html5 and Css how to create separate ul li and move <aside> to the left

How do I push the image to the side and to the top? 如何将图像推向侧面和顶部? Also how do I control each UL LI on their own and not as a general? 另外,我该如何独自而不是一般地控制每个UL LI

Current Result 当前结果

HTML HTML

<div class="header">
  <h1>Merry Christmas</h1>
  <ul id="lil">
    <li><a href="">About Us</a></li>
    <li><a href="">Christmas</a></li>
    <li><a href="">Snow</a></li>
    <li><a href="">Other Holidays</a></li>
  </ul>
  <img src="http://ntt.cc/wp-content/uploads/2009/11/Bell.png" />
</div>
<aside id="sideBar">
  <ul>
    <li>What is Christmas</li>
    <li>Do I celebrate Christmas</li>
    <li>Is Christmas fun?</li>
    <li>Conclusion</li>
  </ul>
</aside>

CSS CSS

div.header {
  background-color: #E32636;
  color: white;
  text-align: center;
  padding: 2px;
  margin: 0px;
  font-family: 'Nemo Nightmares', Arial;
  font-size: 300%;
}

ul#lil li {
  list-style-type: none;
  display: inline;
  color: white;
  font-family: 'Courier New';
  text-align: center;
  margin: 6px;
}

img {
  float: left;
  width: 270px;
  height: 270px;
  position: relative;
  bottom: 190px;
}

a:link {
  text-decoration: none;
  color: white;
}

a:hover {
  color: white;
  text-decoration: underline;
}

a:visited {
  text-decoration: none;
  color: white;
}

ul li {
  color: black;
  list-style-type: none;
  margin: 12px;
  font-size: 100%;
  position: relative;
  right: 350px;
}

#sideBar {
  background-color: #87A96B;
  float: left;
  left: 350px;
}

First off, you have some syntax errors in your HTML. 首先,您的HTML中有一些语法错误。

1) Several of you anchor tags are not closed. 1)您中的几个定位标记未关闭。 You forgot the / in the closing tags. 您在结束标记中忘记了/

2) Your image tag is inside a <ul> , but not inside a <li> . 2)您的图片标签在<ul> ,但不在<li> Anything you put in a list tag needs to be a <li> . 您放入列表标记中的所有内容都必须是<li>

Corrected HTML: 更正的HTML:

<div class="header">
  <h1>Merry Christmas</h1>
  <img src="http://ntt.cc/wp-content/uploads/2009/11/Bell.png" class="bells" />
  <ul id="lil">
    <li><a href="">Aboutus</a></li>
    <li><a href="">Christmas</a></li>
    <li><a href="">Snow</a></li>
    <li><a href="">OtherHolidays</a></li>
  </ul>
</div>
<aside id="sideBar">
  <ul>
    <li>What is christmas</li>
    <li>Do I celebrate Christmas</li>
    <li>Is Christmas fun?</li>
    <li>Conclustion</li>
  </ul>
</aside>

There are a lot of options here.. you could use absolute positioning for a quick fix.. 这里有很多选项。您可以使用绝对定位来快速修复。

img{
    position: absolute;
    top: 10px;
    left: 10px;
}

You could use media queries to make it different sizes deending on the size of the screen.. 您可以使用媒体查询使它的大小取决于屏幕的大小。

/* Large desktop */
@media (min-width: 1200px) {
    img{
        width:30px;
        height: 30px;
    }
}

/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) {
    img{
        width:25px;
        height: 25px;
    }
}

/* Landscape phone to portrait tablet */
@media (max-width: 767px) { ... }

/* Landscape phones and down */
@media (max-width: 480px) { ... }

Or any number of other tricks, but ideally, you should use some kind of scaffolding. 或其他许多技巧,但理想情况下,您应该使用某种脚手架。 Something like Bootstrap makes this kind of thing much easier to manage. 诸如Bootstrap之类的东西使这种事情更易于管理。


If you're interested in Bootstrap, these 3 links should help get you going very quickly. 如果您对Bootstrap感兴趣,那么这3个链接应该可以帮助您快速入门。 Google is now checking for mobile compatibility, so using BS will also improve your search ranking. Google现在正在检查移动兼容性,因此使用BS还将提高您的搜索排名。

  • This one is a single page blank bootstrap template that pulls the BS files from a CDN so you can get started without downloading anything. 是一个单页空白引导模板,可从CDN中提取BS文件,因此无需下载任何内容即可开始使用。 Just copy this into a blank html document and you're ready to use any of the examples in the next two links. 只需将其复制到空白的html文档中,就可以使用下面两个链接中的任何示例了。

  • This one explains the scaffolding and how to position items on the page. 这一篇解释了脚手架以及如何在页面上放置项目。 Bootstrap is a responsive framework, meaning it automatically resizes the page for smaller devices. Bootstrap是一个响应式框架,这意味着它会自动为较小的设备调整页面大小。

  • And this one explains all the built-in styling tools it comes with. 这一个解释了所有内置的造型工具它配备。 Jumbotron might be useful for this. Jumbotron可能对此有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM