Is there a css cross-browser value for “width: -mo

2019-01-22 01:14发布

I need some divs to be center-positioned and to fit their content width at the same time.

I am now doing it like this:

.mydiv-centerer{

  text-align: center;

  .mydiv {
    background: none no-repeat scroll 0 0 rgba(1, 56, 110, 0.7);
    border-radius: 10px 10px 10px 10px;
    box-shadow: 0 0 5px #0099FF;
    color: white;
    margin: 10px auto;
    padding: 10px;
    text-align: justify;
    width: -moz-fit-content;
  }
}

Now, the last command "width: -moz-fit-content;" is exactly what I need!

Only problem is.. it works only on Firefox.

I also tryed with "display:inline-block;", but I need these divs to behave like divs. Namely, every next div should be under, and not inline, the previous.

Do you know any possible cross-browser solution?

7条回答
Animai°情兽
2楼-- · 2019-01-22 01:30

At last I fixed it simply using:

display: table;
查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-22 01:30

I use these:

.right {display:table; margin:-18px 0 0 auto;}
.center {display:table; margin:-18px auto 0 auto;}
查看更多
可以哭但决不认输i
4楼-- · 2019-01-22 01:35

In similar case I used: white-space: nowrap;

查看更多
萌系小妹纸
5楼-- · 2019-01-22 01:39
width: intrinsic;           /* Safari/WebKit uses a non-standard name */
width: -moz-max-content;    /* Firefox/Gecko */
width: -webkit-max-content; /* Chrome */
查看更多
forever°为你锁心
6楼-- · 2019-01-22 01:40

Mozilla's MDN suggests something like the following [source]:

 p {
  width: intrinsic;           /* Safari/WebKit uses a non-standard name */
  width: -moz-max-content;    /* Firefox/Gecko */
  width: -webkit-max-content; /* Chrome */
}
查看更多
我命由我不由天
7楼-- · 2019-01-22 01:40

Why not use some brs?

<div class="mydiv-centerer">
    <div class="mydiv">Some content</div><br />
    <div class="mydiv">More content than before</div><br />
    <div class="mydiv">Here is a lot of content that
                       I was not anticipating</div>    
</div>

CSS

.mydiv-centerer{
    text-align: center;
}

.mydiv{
    background: none no-repeat scroll 0 0 rgba(1, 56, 110, 0.7);
    border-radius: 10px 10px 10px 10px;
    box-shadow: 0 0 5px #0099FF;
    color: white;
    margin: 10px auto;
    padding: 10px;
    text-align: justify;
    display:inline-block;
}

Example: http://jsfiddle.net/YZV25/

查看更多
登录 后发表回答