iT邦幫忙

0

visual studio code圖片跟文字,如何不要黏再一起

  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20230908/20162024vLmUGBI6QF.jpg

    body {
        width: 100%;
        max-width: 1200px;
        margin: 0 auto;
        /*position: relative;*/
    }

    header {
        background-color: rgb(162, 220, 243); 
        height: 150px;
        position: relative;
    }

    .Logo {
        background-color: #ebc7d9;
        height: 80px;
        width: 250px;
        margin-top: 30px;
        margin-left: -40px;
        float: left;
    }

    header nav {
        /*background-color: rgb(242, 255 ,0);*/
        position: absolute;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: end;
    }

    /*header nav a{
            background-color: darkblue;
            color: #fff;
            font-size: 18px;
            letter-spacing: 1px;
            padding: 10px 20px;
            display: block;
            float: left;
            text-decoration: none;
            border-radius: 8px 8px 0 0;
            border: 1px solid red;
            margin: 0 3px;
            margin-top: 20px; 
        }*/
    header nav a {
        background-color: darkblue;
        color: white;
        font-size: 18px;
        letter-spacing: 1px;
        padding: 10px 20px;
        border-radius: 8px 8px 0 0;
        margin-left: 5px;
        transition: .2s;
    }

    header nav a:hover {
        padding-bottom: 30px;
    }

    body>nav {
        background-color: #369;
        color: #fff;
        height: 60px;
        position: sticky;
        top: 0;

    }

    main {
        background-color: #e1b8f3;
        min-height: 200px;
        overflow: hidden;
        display: flex;
        justify-content: center;
    }

    main aside {
        background-color: #e7a8a8;
        float: right;
        width: 20%;
        padding: 20px;
        margin-left: 555px;
    }

    .content {
        background-color: #f8fc9e;
        width: 70%;
        padding: 20px;
        margin: 4%;
    }
    
    .content img {
        display: inline-block;
        vertical-align: middle;
    }
    
    .content h1{
        font-size: 2em;
        margin: 0 0 20px;
    }

    .content figure{
        letter-spacing: 1px;
        line-height: 1.2;
        text-align: justify;
    }


    .gomore {
        background-color: darkblue;
        color: white;
        text-decoration: none;
        padding: 20px;
        display: block;
        clear: both;
        float: left;
    }

    .gomore p {
        background-color: black;
        color: white;
        padding: 10px;
        position: absolute;
        right: 0;
        top: 0;
        width: 250px;
        transform: translateY(calc(-100% -15px));
        display: none;
    }

    .gomore p::after {
        content: '';
        display: block;
        width: 0;
        height: 0;
        border: 15px solid transparent;
        border-top-color: black;
        position: absolute;
        right: 0;
        bottom: 0;
        transform: translate(-30px, 28px);
    }

    .gomore:hover p {
        display: block;
    }

    footer {
        background-color: #d5f3b8;
        text-align: center;
        padding: 1em;
    }

    img {
        background-color: #fff;
        width: 30%;
        height: 300px;
        margin-top: auto;
        margin-bottom: auto;
        float:left;
        margin-left: 10px;
    }
</style>
<footer>
    <p>Copyright © 2023 ITsESG</p>
</footer>
看更多先前的討論...收起先前的討論...
淺水員 iT邦大師 6 級 ‧ 2023-09-08 13:55:50 檢舉
少了 html 的部分不好判斷
但大概就是加個 margin 或 padding 吧
PIZZ iT邦新手 3 級 ‧ 2023-09-08 14:01:41 檢舉
GPT大神開釋

要确保在HTML和CSS中将图像和文本分离并避免它们黏在一起,您可以使用CSS中的样式来控制它们的布局和间距。以下是一些方法:

使用<div>元素包装图像和文本:
html
Copy code
<div class="image-container">
<img src="your-image.jpg" alt="Your Image">
</div>
<div class="text-container">
<p>Your text goes here.</p>
</div>
然后,在CSS中设置样式:

css
Copy code
.image-container {
margin-bottom: 20px; /* 或其他所需的间距 */
}

.text-container {
margin-top: 20px; /* 或其他所需的间距 */
}
这将为图像和文本之间添加一个间距,使它们不会黏在一起。

使用<figure>和<figcaption>元素:
html
Copy code
<figure>
<img src="your-image.jpg" alt="Your Image">
<figcaption>Your text goes here.</figcaption>
</figure>
然后,在CSS中设置样式:

css
Copy code
figure {
margin: 20px 0; /* 或其他所需的间距 */
}
这将为图像和文本之间以及周围添加间距,确保它们不会黏在一起。

使用CSS的display属性来控制元素的布局:
html
Copy code
<img src="your-image.jpg" alt="Your Image">
<p>Your text goes here.</p>
然后,在CSS中设置样式:

css
Copy code
img {
display: block;
margin-bottom: 20px; /* 或其他所需的间距 */
}
这将使图像和文本以块级元素显示,并在它们之间添加一个底部间距,以确保它们不会黏在一起。

这些方法中的任何一种都可以根据您的具体需求进行调整,以获得所需的布局和间距。
還是再新增一個框架
謝謝大神
發現不用哪麼煩,在img加margin 20px,圖片跟文字就分開了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

3
janlin002
iT邦好手 1 級 ‧ 2023-09-08 15:04:05
最佳解答

圖片推右邊 或是文字推左邊

我要發表回答

立即登入回答