H1标签溢出图像?

时间:2018-02-25 03:51:15

标签: javascript html css

当窗口全屏显示时,它显示如下:

When window is in full screen it shows like this

当我尝试使其移动友好或窗口缩小时,h1标签溢出图像:

When I tried to make it mobile friendly or window shrink the h1 tag is overflow the image

我也试过了溢出属性,但它没有用。此外,我希望我的h1和img必须在我所做的那个特定位置,但也希望它必须是移动友好的。如果我需要使用任何CSS或JavaScript,请提出建议。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>test video</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Butcherman&amp;subset=latin-ext" rel="stylesheet">


    <style type="text/css">
html,body{
    margin: 0;
    padding: 0;
    font-size: 100%;
}
#stripe img{
    position: absolute;
    top: 0;
    left: 40%;
    margin-left: 5px;
    margin-top: 0;
    margin-bottom: 0;
    margin-right: 5px;
    overflow: inherit;
}
h1{
    position: fixed;
    left: 45%;
    top: 20px;
    color: white;
    font-size: 2em;
    font-family: 'Butcherman', cursive;
    font-weight: normal;
    text-align: center; 
    margin-left: 5px;
    margin-top: 0;
    margin-bottom: 0;
    margin-right: 0;
    text-transform: uppercase;
    overflow: inherit;
}
#stripe{
    position : relative;
    background: #404040;
    height: 70px;
    text-align: center;
    overflow: hidden;
    right: 0;
}
    </style>

</head>
<body>

     <div id="stripe">
        <img src="logo/mask.png">
        <h1>My Website</h1>               
      </div>

</body>
</html>

3 个答案:

答案 0 :(得分:2)

试试这个:

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>test video</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Butcherman&amp;subset=latin-ext" rel="stylesheet">


    <style type="text/css">
html,body{
    margin: 0;
    padding: 0;
    font-size: 100%;
}
#stripe img{
    display: inline-block;
}
h1{
    color: white;
    font-size: 2em;
    font-family: 'Butcherman', cursive;
    font-weight: normal;
    text-align: center; 
    margin-left: 5px;
    margin-top: 0;
    margin-bottom: 0;
    text-transform: uppercase;
    display: inline-block;
}
#stripe{
    background: #404040;
    height: 70px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}
    </style>

</head>
<body>

     <div id="stripe">
          <img src="http://via.placeholder.com/50x50">
          <h1>My Website</h1> 
      </div>

</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我认为您应该将以下CSS添加到divimg样式中。

#stripe{    
    position: relative;
}

#stripe img{
    position: absolute;
}  

并且您无需提供h1代码position: fixed样式。删除它。

答案 2 :(得分:0)

最后,我用这个CSS解决了我的问题:

html,body{
    margin: 0;
    padding: 0;
    font-size: 100%;
}
#stripe img{
    margin-left: 0;
    margin-top: 0;
    margin-bottom: 15px;
    margin-right: 0;
}
h1{
    color: white;
    font-size: 2em;
    font-family: 'Butcherman', cursive;
    font-weight: normal;
    text-align: center; 
    text-transform: uppercase;
}

img + h1{
    display: inline-block;
}
#stripe{
    position: relative;
    background: #404040;
    height: 70px;
    text-align: center;
    right: 0;
}