css - 试图让 div 漂浮在另一个 div 旁边

标签 css html

我有两个 div featureText 和 skillsText 一个接一个,我试图让第二个 float 在下一个的右边而不是堆叠,我已经尝试在第二个上相对位置 float 左无济于事,容器本身是相对定位的。当我检查第一个 div 时,它显示超宽,但我设置了宽度并且边距和填充已设置为 0 以查看是否是问题所在。这是一个菜鸟问题,但我需要帮助。

直播site

html

<!DOCTYPE html>
<html>
<head>
    <title>Portfolio of Anders Kitson</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/styles.css">
    <script type="text/javascript" src="//use.typekit.net/lfr7txf.js"></script>
    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
</head>
<body>
<div id="container">
    <header>
        <h1>ASK</h1>
        <h2>Anders Samuel Kitson, front end web developer.</h2>
    </header>
    <div id="featureText">
        <h1>Recent Works</h1>
    </div>
    <div id="skillsText">
        <h1>Super hero skills</h1>
    </div>
    <div id="siteThumbs"><!--not sure if this is appropriate use of the section tag-->
        <div id="springmethod">
            <a href="#"><h1 class="springmethod">Springmethod.com</h1></a>
        </div>
        <div id="goodmorning">
            <a href="#"><h1 class="goodmorning">goodmorningmoon.ca</h1></a>
        </div>
    </div>

</div>
</body>
</html>

CSS

/*variables*/
/*shared styles*/
#container {
  width: 960px;
  max-width: 90%;
  border: solid 0px #000;
  margin: auto;
  position: relative; }

header h1 {
  background: url("../images/ask.gif");
  width: 97px;
  height: 96px;
  text-indent: -9000px; }
header h2 {
  font-family: "brandon-grotesque",sans-serif;
  font-weight: 300;
  font-size: 2.5em; }

#featureText {
  margin-top: 70px;
  margin-bottom: 20px;
  width: 24%;
  background: red; }
  #featureText h1 {
    font-family: "brandon-grotesque",sans-serif;
    font-size: 2.5em;
    font-weight: 700; }

#skillsText {
  width: 28%;
  background: aqua;
  position: relative;
  float: left; }
  #skillsText h1 {
    font-family: "brandon-grotesque",sans-serif;
    font-size: 2.5em;
    font-weight: 700;
    margin-top: -10px; }

#siteThumbs {
  position: relative;
  float: left;
  width: 960px; }
  #siteThumbs .springmethod {
    background: url("../images/springmethod.jpg") no-repeat;
    width: 318px;
    height: 241px;
    text-indent: -9000px;
    padding: 0;
    margin: 0; }
  #siteThumbs .goodmorning {
    background: url("../images/goodmorning.jpg") no-repeat;
    width: 318px;
    height: 241px;
    text-indent: -9000px;
    padding: 0;
    margin: 0; }

#siteThumbs a:hover .springmethod {
  background: url("../images/springmethod.jpg") 0 -241px no-repeat; }
#siteThumbs a:hover .goodmorning {
  background: url("../images/goodmorning.jpg") 0 -241px no-repeat; }

#springmethod {
  width: 318px;
  position: relative;
  float: left; }

#goodmorning {
  width: 318px;
  position: relative;
  float: left; }

/*media queries*/
/* Smartphones (portrait and landscape) */
@media only screen and (min-width: 0px) and (max-width: 767px) {
  header h2 {
    font-size: 1.5em; } }

最佳答案

#featureText 中移除 margin-top: 70px; 并向左浮动 #skillsText

#featureText {
   margin-bottom: 20px;
   width: 24%;
   background: red;
   float: left;
}

#skillsText { float:left; }

关于css - 试图让 div 漂浮在另一个 div 旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13545386/

相关文章:

jquery - 选择自定义属性设置样式

javascript - CSS 只绘制左边框和上边框,忽略右边框和下边框

javascript - Angular 错误 : [$rootScope:inprog] $apply already in progress on document. click()

javascript - 如何使用angularjs构建交互式滚动登陆页面?

javascript - 文本区域值和文本属性在 react 中未定义

jquery - 如何使用 jQuery 访问多个类

html - 在 Mac 上使用 @font-face 会导致文本高度为 0

php - 如何构造生成html的php

javascript - CSS z-index/javascript 在三大浏览器中的工作方式不同

html - HTML 中的平衡文本换行