divs设置屏幕居中_使用CSS设置Divs不大于其内容

divs设置屏幕居中

Trivia:

琐事:

No amount of discussion is enough when we are talking about divs. It is a very concept aspect of website or web page development and so are its properties and functions. What can you not do with divs? Every fundamental thing can be achieved if we make use of divs. The best part of divs is that it is not even that brain-wrecking to implement, you just have to create a “div” tag and there you go, do whatever you feel like with it. From creating a class to appending CSS and much more. Therefore, divs are very crucial elements of any website or web page and one must know how to use divs thoroughly if they wish to be a good developer. Now, since we have discussed so much about divs, why don't we move ahead with the article and discuss the topic at hand.

当我们谈论div时,没有足够的讨论是不够的。 它是网站或网页开发的一个非常概念性的方面,属性和功能也是如此。 div不能做什么? 如果我们使用div,那么所有基本的事情都可以实现。 divs的最好之处在于,它甚至不需要费脑筋就能实现,您只需创建一个“ div”标签,然后就可以随心所欲地进行操作了。 从创建类到附加CSS等。 因此,div是任何网站或网页中非常重要的元素,如果他们希望成为一名优秀的开发人员,则必须完全了解如何使用div。 现在,既然我们已经对div进行了太多讨论,那么为什么不继续撰写本文并讨论当前主题。

Discussion:

讨论:

Now that you know the capabilities of using divs and what sorts of possibilities this tool has to offer, why don't we take this discussion a step ahead and dive more into the possibilities of divs? Therefore, in this section, we will be discussing how we can create divs larger than its contents using CSS? Well, CSS and divs are something inseparable, they go hand in hand. Using CSS we would be able to style our div elements and that would again help in creating a responsive website or web page. Now, the question is how do we create divs larger than its contents? To find the answer to that keep on reading!

既然您知道使用div的功能以及该工具必须提供的各种可能性,为什么我们不将讨论进行得更进一步而深入研究div的可能性呢? 因此,在本节中,我们将讨论如何使用CSS创建大于其内容的div? 嗯,CSS和div是密不可分的,它们是紧密相连的。 使用CSS,我们将能够设置div元素的样式,这将再次有助于创建响应式网站或网页。 现在,问题是我们如何创建大于其内容的div? 要找到答案,请继续阅读!

Steps:

脚步:

To achieve this task is not very tough rather it would seem to be very familiar to you, so all you gotta do is pay close attention and try to follow each step that is going to be mentioned below,

要完成此任务并不困难,相反,您似乎对此非常熟悉,因此您要做的就是密切关注并尝试遵循下面将要提到的每个步骤,

  1. First and foremost, go ahead and create a <div> tag with a class named box, then add <h2> tag in the div and write any content between the tags.

    首先,首先要创建一个名为box的类的<div>标签,然后在div中添加<h2>标签并在标签之间写入所有内容。

  2. The role of CSS steps in, choose colors for your text and maybe try to add some background color by using color properties.

    CSS的作用在于,为文本选择颜色,并可能尝试使用颜色属性添加一些背景颜色。

  3. Next, you will need to make use of display property to define the type of box which you would be used for HTML. Suppose you take the inline-block value for the display property.

    接下来,您将需要使用display属性来定义用于HTML的框的类型。 假设您使用display属性的内联块值。

  4. Try to add some padding around the content.

    尝试在内容周围添加一些填充。

Example:

例:

<!DOCTYPE html>

<html>

<head>
    <style>
        .box {
            background-color: #f40;
            color: #fff;
            width: fit-content;
            height: fit-content;
        }
    </style>
</head>

<body>
    <center>
        <div class="box">
            <h1>This is IncludeHelp!</h1>
            <h2>IncludeHelp is a learning platform.</h2>
        </div>
    </center>
</body>

</html>

Set Divs not larger than its contents using CSS

In the above example, fit-content value is applied to both the height and width of the div.

在上面的示例中,fit-content值同时应用于div的高度和宽度。

Conclusion:

结论:

That's it! That is all to it. Pretty easy right? I told you you would be familiar and this is the way how you create divs not larger than its contents. You can also add width and height property and you can set it to fit-content.

而已! 仅此而已。 很容易吧? 我告诉过您,您会很熟悉,这就是您创建不大于其内容的div的方式。 您还可以添加width和height属性,并将其设置为fit-content 。

翻译自: https://www.includehelp.com/code-snippets/set-divs-not-larger-than-its-contents-using-css.aspx

divs设置屏幕居中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值